聊天模型中的少量镜头示例 本笔记本介绍了如何在聊天模型中使用少量镜头示例。 关于如何最好地进行少量镜头提示,目前似乎还没有达成一致意见。因此,我们还没有围绕这个问题建立任何抽象概念,而是使用现有的抽象概念。 人类/人工智能信息交替 第一种进行少量镜头提示的方法是交替使用人类/人工智能信息。请看下面的示例。 from langchain.chat_models import ChatOpenAI from langchain import PromptTemplate, LLMChain from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, AIMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.schema import AIMessage, HumanMessage, SystemMessage chat = ChatOpenAI(temperature=0) template = "You are a helpful assistant that translates english to pirate." system_message_prompt = SystemMessagePromptTemplate.from_template(template) example_human = HumanMessagePromptTemplate.from_template("Hi") example_ai = AIMessagePromptTemplate.from_template("Argh me mateys") human_template = "{text}" human_message_prompt = HumanMessagePromptTemplate.from_template(human_template) chat_prompt = ChatPromptTemplate.from_messages( ...
少量镜头提示模板 在本教程中,我们将学习如何创建使用少量示例的提示模板。少量镜头提示模板可以从一组示例或示例选择器对象中创建。 使用实例 在本教程中,我们将为带有搜索功能的自问自答配置少量镜头示例。 使用示例集 创建示例集 要开始使用,请创建一个包含少量示例的列表。每个示例都应是一个字典,键是输入变量,值是这些输入变量的值。 from langchain.prompts.few_shot import FewShotPromptTemplate from langchain.prompts.prompt import PromptTemplate examples = [ { "question": "Who lived longer, Muhammad Ali or Alan Turing?", "answer": """ Are follow up questions needed here: Yes. Follow up: How old was Muhammad Ali when he died? Intermediate answer: Muhammad Ali was 74 years old when he died. Follow up: How old was Alan Turing when he died? Intermediate answer: Alan Turing was 41 years old when he died. So the final answer is: Muhammad Ali """ }, { "question": "When was the founder of craigslist born?", "answer": """ Are follow up questions needed here: Yes. Follow up: Who was the founder of craigslist? Intermediate answer: Craigsl...