Skip to content

Commit

Permalink
能正常调用google,其他的待测试
Browse files Browse the repository at this point in the history
  • Loading branch information
caizhuoyue77 committed May 18, 2024
1 parent 89c9886 commit 5878730
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async def chat_endpoint(request: Request):
data = await request.json()
query = data.get("message")
if query:
# response = "在搞什么?"
response = rewoo_as_func(query)
return {"response": response}
return {"response": "No query provided"}
3 changes: 1 addition & 2 deletions call_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def use_actual_tool(tool: str, tool_input: dict):

# 通用API
if tool == "Google":
# result = search.invoke(tool_input)
result = "Gen v is a good movie, published in 2025."
result = search.invoke(tool_input)
# 天气API
elif tool == "WeatherSearch":
result = weather_forcast_24h(tool_input)
Expand Down
6 changes: 3 additions & 3 deletions chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def check_yes():

if response.status_code == 200:
msg = response.json()["response"]
st.session_state["button_clicked"] = False
st.experimental_rerun()
# st.session_state["button_clicked"] = False
# st.experimental_rerun()
else:
msg = "API调用失败"

st.session_state.messages.append({"role": "assistant", "content": msg})
st.chat_message("assistant").write(msg)
6 changes: 5 additions & 1 deletion rewoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def tool_execution(state: ReWOO):

def solve(state: ReWOO):
"""根据收集的证据生成最终解决方案。"""

logger.error("在调用solve函数啦!!!!")

plan = ""
for _plan, step_name, tool, tool_input in state["steps"]:
_results = state["results"] or {}
Expand All @@ -103,6 +106,7 @@ def solve(state: ReWOO):
plan += f"Plan: {_plan}\n{step_name} = {tool}[{tool_input}]\n"
prompt = SOLVE_PROMPT.format(plan=plan, task=state["task"])
result = model.invoke(prompt)

return {"result": result.content}

def _route(state):
Expand Down Expand Up @@ -149,7 +153,7 @@ def rewoo_as_func(task: str):
logger.info(s['solve']['result'])

response = response + "\n\n**最终结果**:\n\n" + s['solve']['result'] + "\n"

return response

if __name__ == "__main__":
Expand Down

0 comments on commit 5878730

Please sign in to comment.