You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
788 B
29 lines
788 B
from langchain_openai import ChatOpenAI
|
|
from pydantic import BaseModel, Field
|
|
|
|
from env_util import DASHSCOPE_API_KEY, DASHSCOPE_BASE_URL
|
|
|
|
# llm对象就是调用大模型的对象
|
|
llm = ChatOpenAI(
|
|
model = "qwen-plus",
|
|
base_url=DASHSCOPE_BASE_URL,
|
|
api_key=DASHSCOPE_API_KEY,
|
|
temperature=0.8,
|
|
);
|
|
|
|
|
|
# 使用pydantic定义一个类 数据模型类
|
|
class ResponseFormatter(BaseModel):
|
|
|
|
answer: str = Field(description = "对用户问题的回答")
|
|
follow_question: str = Field(description = "用户可能提出的后续问题")
|
|
|
|
# 指定返回结果
|
|
# 这里根据他要的类型,貌似需要给[]里面追加类型
|
|
runnable = llm.bind_tools([ResponseFormatter])
|
|
|
|
resp = runnable.invoke("现存存在最久的生物是什么?")
|
|
|
|
print(resp)
|
|
resp.pretty_print()
|