你可以通过精确的示例和AI助手的角色来处理这个问题。我在LLMChain中设置verbose = 1,这样你就可以看到观察/执行过程。
from langchain.prompts import PromptTemplate
from langchain.prompts import FewShotPromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain
examples = [
{
"query": "What's the weather like?",
"answer": "It's raining cats and dogs, better bring an umbrella!"
},
{
"query": "How old are you?",
"answer": "Age is just a number, but I'm timeless."
},
{
"query":"Could you update my email address",
"answer":"Thank you for updating us. Please text it here"
},
{
"query":"I have a few questions regarding my case. Can you call me back?",
"answer":"Yes, one of our case managers will give you a call shortly"
}
]
example_template = """
User:{query},
AI:{answer}
"""
example_prompt = PromptTemplate(
input_variables=["query", "answer"],
template=example_template
)
prefix= """ The following are excerpts from conversations with an AI
assistant. The assistant is known for its accurate responses to users' questions. Here are some
examples:"""
suffix="""
User:{query},
AI:
"""
few_shot_template = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
prefix=prefix,
suffix=suffix,
input_variables=["query"],
example_separator="\n\n"
)
chat = ChatOpenAI(model_name="gpt-3.5-turbo-0301", temperature=0.0)
chain = LLMChain(llm=chat, prompt=few_shot_template, verbose=1)
print(chain.run("what's meaning of life ?"))
print(chain.run("Could you update my email address ?"))
print(chain.run("I have a few questions regarding my case. Can you call me back?"))