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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import json
from langchain_core . output_parsers import SimpleJsonOutputParser
from langchain_core . prompts import PromptTemplate , ChatPromptTemplate
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 ,
) ;
# 提示词模板
prompt = ChatPromptTemplate . from_template (
" 进你所能回答问题。 "
' 你必须输出一个包含 " answer " 和 " follow_answer " 健的JSON对象, 其中 " answer " 是你回答问题的答案, " follow_answer " 是用户后续可能问的问题。 '
" {question} "
)
chain = prompt | llm | SimpleJsonOutputParser ( )
resp = chain . invoke ( { " question " : " 人类是怎么出现的 " } )
print ( resp )