Langchain-Chatchat
Langchain-Chatchat copied to clipboard
使用模型chatglm3-6b,如何在langchain-chatchat交互中调用到chatglm3-6b自定义的工具(function calling),请提供实例
使用模型chatglm3-6b,如何在langchain-chatchat交互中调用到chatglm3-6b自定义的工具(function calling),请提供实例
嘿,@Andy1018!又见面了,希望你最近一切都好!看来我们有新的挑战要一起解决了呢。
在Langchain-Chatchat中使用chatglm3-6b模型的自定义工具,需要确保在初始化StructuredGLM3ChatAgent
时,自定义工具被包含在tools
序列中。同时,需要验证StructuredChatOutputParserWithRetries
类的parse
方法能正确识别工具的名称,以及tool_config_from_file
函数能找到并正确读取工具的配置文件。最后,需要在StructuredGLM3ChatAgent
类的allowed_tools
属性中包含工具的名称。具体的示例代码可以参考这个链接。
此外,自定义工具的YAML配置文件应遵循提供的结构和内容示例,可以参考这个链接。
如果在检查这些点后问题仍然存在,建议提供更多的错误信息或详细的使用场景以便进一步协助。
在Langchain-Chatchat的交互中调用chatglm3-6b模型的自定义工具,可以参考dialogue.py
文件中的dialogue_page
函数。这个函数演示了如何与不同的对话模式进行交互,包括LLM(Large Language Models)对话、知识库Q&A、文件对话、搜索引擎Q&A和自定义代理Q&A。这里有一个简化的示例,专注于LLM对话模式,这对于与chatglm3-6b等模型的交互是相关的:
def dialogue_page(api: ApiRequest):
# 初始化或获取当前的对话ID
st.session_state.setdefault("conversation_ids", {})
conversation_id = st.session_state["conversation_ids"].setdefault("default", uuid.uuid4().hex)
# 从下拉菜单中选择LLM模型(例如,chatglm3-6b)
llm_model = st.selectbox("Select LLM model:", ["chatglm3-6b"], index=0)
# 用户的输入
chat_input_placeholder = "在这里输入您的消息"
if prompt := st.chat_input(chat_input_placeholder, key="prompt"):
# 模拟发送消息并从模型接收响应
history = get_messages_history(history_len=5) # 假设一个函数来获取最后5条消息
chat_box.user_say(prompt)
chat_box.ai_say("Thinking...")
# 在这里你会调用API或函数来从chatglm3-6b获取响应
# 为了演示,我们模拟一个响应
response = "这是来自chatglm3-6b的模拟响应。"
chat_box.ai_say(response)
# 显示来自历史记录的聊天消息
chat_box.output_messages()
这个示例假设存在一个chat_box
对象用于管理聊天UI元素,以及一个api
对象用于向后端或外部服务发出请求。st.chat_input
函数捕获用户输入,然后处理以模拟向chatglm3-6b模型发送消息并接收响应。实际上与chatglm3-6b或任何其他LLM的集成,需要调用适当的API或函数,根据用户的输入和对话历史获取模型的响应。具体的示例代码可以参考这个链接。
希望这些信息对您有所帮助,如果有任何其他问题,欢迎继续提问。
Sources
- 使用agent_chat调自定义工具,无法调到自定义工具
- [FEATURE] 如何接入CustomLLM?
- 支持chatglm3模型
- webui_pages/dialogue/dialogue.py
- configs/model_config.py.example
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
这个问题已经被标记为 stale
,因为它已经超过 30 天没有任何活动。