如何使用langchain使用多个提示

问题描述 投票:0回答:1

我想使用多个提示来完成我的任务。我编写了一个文档问答提示,它利用聊天历史记录和上下文来回答问题。现在我希望我的模型根据聊天历史记录生成发票。我为此写了另一个提示。有没有任何方法可以使用多个提示,以便我的模型使用他的智能来确定要运行哪个提示?首先,我尝试使用 langchain 形式的提示管道,但没有得到异常结果,因为输入变量产生了问题。

对于文档问题提示,我的模型有 4 个输入变量

DEFAULT_TEMPLATE = """
### Instruction: Your name is 'Jarvis' and the name of the customer is {username}. Please introduce yourself as 'Jarvis, Information Assistant'. Use the user's name occasionally in your responses, but ensure to introduce yourself only in the first response.
Utilize the chat history and available information in "{context}" to answer the question.
Remember, the user is looking for assistance, so keep your responses natural, concise, accurate, and informative. If you are uncertain about a query or if the user asked something which is unidentified by you, prompt the user to rephrase it. 
When greeted, respond briefly and amiably.
{chat_history}
### Input: {question}
### Response:
"""

prompt = PromptTemplate (
        input_variables = ["context", "question", "chat_history", "username"],
        template = DEFAULT_TEMPLATE,```

对于发票生成,我将聊天历史记录传递到另一个提示,并告诉我的模型将其格式化为 json 格式并创建一个表。

有什么方法可以让我的模型根据用户的问题确定运行哪个提示?

chatbot prompt openai-api agent langchain
1个回答
0
投票

有什么方法可以让我的模型根据用户的问题确定运行哪个提示?

您可以查看OpenAI函数调用,但恐怕您必须自己定义函数和模式(pydantic可能有帮助?)。另外,不能保证它会调用该函数/正确的函数/任何函数。

我看到你正在使用langchain,但我发现它的文档写得不好,所以找不到确切的东西。大概是这个。您可能还需要看看连锁店。

© www.soinside.com 2019 - 2024. All rights reserved.