现象:/root/.virtualenvs/LLM/lib/python3.9/site-packages/langchain/init.py:29: UserWarning: Importing PromptTemplate from langchain root module is no longer supported. Please use langchain_core.prompts.PromptTemplate instead.
warnings.warn(
Setting eos_token is not supported, use the default one.
Setting pad_token is not supported, use the default one.
Setting unk_token is not supported, use the default one.
Loading checkpoint shards: 100%|██████████| 7/7 [00:01<00:00, 4.85it/s]
{'input': 'how many meters in 30 km?', 'output': "Is there anything else you would like to ask or know? I'm here to help!"}
代码:(我的运行环境无法连外网,没法执行hub.pull)
prompt_template: str = """
Respond to the human as helpfully and accurately as possible. You have access to the following tools:
{tools}
Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).
Valid "action" values: "Final Answer" or {tool_names}
Question: input question to answer
Thought: consider previous and subsequent steps
Action:
$JSON_BLOB
Observation: action result
... (repeat Thought/Action/Observation N times)
Thought: I know what to respond
Action:
{{
"action": "Final Answer",
"action_input": "Final response to human"
}}
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation
PLACEHOLDER
chat_history
HUMAN
{input}
{agent_scratchpad}
(reminder to respond in a JSON blob no matter what)
"""
ODEL_PATH = "/root/lzl/ChatGLM3-main/down/"
if __name__ == "__main__":
llm = ChatGLM3()
llm.load_model(MODEL_PATH)
prompt = PromptTemplate.from_template(prompt_template)
tools = [DistanceConverter()]
agent = create_structured_chat_agent(llm=llm, tools=tools, prompt=prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
ans = agent_executor.invoke({"input": "how many meters in 30 km?"})
print(ans)
硬件:64核CPU,4个T4 GPU(每个16G显存)
软件:linux、ubuntu、transformers4.40.1、torch2.2.2、langchain0.1.16
@yinch
### Who can help? / 谁可以帮助到您?
_No response_
### Information / 问题信息
- [X] The official example scripts / 官方的示例脚本
- [ ] My own modified scripts / 我自己修改的脚本和任务
### Reproduction / 复现过程
复现步骤:
1. 代码如上所示
2. run
### Expected behavior / 期待表现
我希望是能调用到tool,给个正确结果,比如
{'input': 'how many meters in 30 km?', 'output': "30 000m!"}
System Info / 系統信息
现象:/root/.virtualenvs/LLM/lib/python3.9/site-packages/langchain/init.py:29: UserWarning: Importing PromptTemplate from langchain root module is no longer supported. Please use langchain_core.prompts.PromptTemplate instead. warnings.warn( Setting eos_token is not supported, use the default one. Setting pad_token is not supported, use the default one. Setting unk_token is not supported, use the default one. Loading checkpoint shards: 100%|██████████| 7/7 [00:01<00:00, 4.85it/s] {'input': 'how many meters in 30 km?', 'output': "Is there anything else you would like to ask or know? I'm here to help!"}
代码:(我的运行环境无法连外网,没法执行hub.pull) prompt_template: str = """ Respond to the human as helpfully and accurately as possible. You have access to the following tools:
{tools}
Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).
Valid "action" values: "Final Answer" or {tool_names}
Provide only ONE action per $JSON_BLOB, as shown:
Follow this format:
Question: input question to answer Thought: consider previous and subsequent steps Action:
Observation: action result ... (repeat Thought/Action/Observation N times) Thought: I know what to respond Action: