Skip to content

Commit

Permalink
添加了cache,目前能正常调用google搜索api,还修改了API名称
Browse files Browse the repository at this point in the history
  • Loading branch information
caizhuoyue77 committed May 19, 2024
1 parent cda0929 commit d4cffcf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@
[x] 2. 修改步骤为,先出编排结果,确认后再执行
[x] 3. 设计好plan和execute的API格式,然后记录到文档里
[ ] 4. 调整好执行API的流程API,如何识别参数和如何执行
[x] 5. 添加了一个非常直接的cache,如果某个task/query在之前是输入过的,那么就直接返回之前的/chat的结果
[x] 5. 添加了一个非常直接的cache,如果某个task/query在之前是输入过的,那么就直接返回之前的/get_plan的结果
[ ] 6. 添加高德地图的API
[ ] 7. 动态配参数
[ ] 8. 添加可视化的部分
[ ] 9. 添加可交互式编排的部分

## 进展记录

2024年5月19日

1. 前、后端的交互部分调整:先出编排结果,然后确认后再执行;把获得的编排结果进行cache,能命中的时候就不用再次执行。
效果演示:能够自主地调用Google搜索API并得到结果
![调用google search的API](assets/images/24-05-19-google搜索结果.png)

2.

## 模型改成Qwen的几个注意事项

Expand Down
4 changes: 2 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read_root():
return {"Hello": "World"}

# TODO: 要改为get_plan之类的
@app.post("/chat")
@app.post("/get_plan")
async def chat_endpoint(request: Request):
data = await request.json()
query = data.get("message")
Expand All @@ -24,7 +24,7 @@ async def chat_endpoint(request: Request):
return response
return {"response": "No query provided", "rewoo_state": None}

@app.post("/continue")
@app.post("/execute_plan")
async def execute_endpoint(request: Request):
data = await request.json()
# data是request里面传递过来的内容
Expand Down
Binary file added assets/images/24-05-19-google搜索结果.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion cache.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"帮我用google搜一下genv": {"response": "**API编排步骤:**\n* 第1步: 使用Google进行搜索,查询关于\"genv\"的信息。\n\n", "rewoo_state": {"task": "帮我用google搜一下genv", "plan_string": "Plan: 使用Google进行搜索,查询关于\"genv\"的信息。\n#E1 = Google[genv]", "steps": [["使用Google进行搜索,查询关于\"genv\"的信息。", "#E1", "Google", "genv"]]}}, "帮我用google搜一下genv\n\n": {"response": "**API编排步骤:**\n* 第1步: 使用Google进行搜索,查询关于\"genv\"的信息。\n\n", "rewoo_state": {"task": "帮我用google搜一下genv\n\n", "plan_string": "Plan: 使用Google进行搜索,查询关于\"genv\"的信息。\n#E1 = Google[genv]", "steps": [["使用Google进行搜索,查询关于\"genv\"的信息。", "#E1", "Google", "genv"]]}}}
{"帮我用google搜一下genv": {"response": "**API编排步骤:**\n* 第1步: 使用Google进行搜索,查询关于\"genv\"的信息。\n\n", "rewoo_state": {"task": "帮我用google搜一下genv", "plan_string": "Plan: 使用Google进行搜索,查询关于\"genv\"的信息。\n#E1 = Google[genv]", "steps": [["使用Google进行搜索,查询关于\"genv\"的信息。", "#E1", "Google", "genv"]]}}, "帮我用google搜一下genv\n\n": {"response": "**API编排步骤:**\n* 第1步: 使用Google进行搜索,查询关于\"genv\"的信息。\n\n", "rewoo_state": {"task": "帮我用google搜一下genv\n\n", "plan_string": "Plan: 使用Google进行搜索,查询关于\"genv\"的信息。\n#E1 = Google[genv]", "steps": [["使用Google进行搜索,查询关于\"genv\"的信息。", "#E1", "Google", "genv"]]}}, "genv好像是一个电影,帮我google一下?\n\n": {"response": "**API编排步骤:**\n* 第1步: 使用Google搜索工具来查询“genv”是否是一部电影的相关信息。\n\n", "rewoo_state": {"task": "genv好像是一个电影,帮我google一下?\n\n", "plan_string": "Plan: 使用Google搜索工具来查询“genv”是否是一部电影的相关信息。\n#E1 = Google[genv movie]", "steps": [["使用Google搜索工具来查询“genv”是否是一部电影的相关信息。", "#E1", "Google", "genv movie"]]}}, "genv好像是一个电影,帮我google一下?": {"response": "**API编排步骤:**\n* 第1步: 使用Google来搜索关于\"genv\"的电影信息。\n\n", "rewoo_state": {"task": "genv好像是一个电影,帮我google一下?", "plan_string": "Plan: 使用Google来搜索关于\"genv\"的电影信息。\n#E1 = Google[genv movie]", "steps": [["使用Google来搜索关于\"genv\"的电影信息。", "#E1", "Google", "genv movie"]]}}, "genv是什么?我同学跟我说“genV”很好看,能给我介绍一下吗?": {"response": "**API编排步骤:**\n* 第1步: 使用Google来搜索关于\"genV\"的相关信息,特别是与我同学提到的内容相关的。\n\n", "rewoo_state": {"task": "genv是什么?我同学跟我说“genV”很好看,能给我介绍一下吗?", "plan_string": "Plan: 使用Google来搜索关于\"genV\"的相关信息,特别是与我同学提到的内容相关的。\n#E1 = Google[\"genV\" + \"我的同学说很好看\"]", "steps": [["使用Google来搜索关于\"genV\"的相关信息,特别是与我同学提到的内容相关的。", "#E1", "Google", "\"genV\" + \"我的同学说很好看\""]]}}, "疯狂动物城2啥时候上?": {"response": "**API编排步骤:**\n* 第1步: 使用Google来搜索“疯狂动物城2 release date”以获取电影的上映信息。\n\n", "rewoo_state": {"task": "疯狂动物城2啥时候上?", "plan_string": "Plan: 使用Google来搜索“疯狂动物城2 release date”以获取电影的上映信息。\n#E1 = Google[\"疯狂动物城2 release date\"]", "steps": [["使用Google来搜索“疯狂动物城2 release date”以获取电影的上映信息。", "#E1", "Google", "\"疯狂动物城2 release date\""]]}}, "google搜索一下:GenV男星去世": {"response": "**API编排步骤:**\n* 第1步: 使用Google来搜索关于\"GenV男星去世\"的信息。\n\n", "rewoo_state": {"task": "google搜索一下:GenV男星去世", "plan_string": "Plan: 使用Google来搜索关于\"GenV男星去世\"的信息。\n#E1 = Google[GenV 男星去世]", "steps": [["使用Google来搜索关于\"GenV男星去世\"的信息。", "#E1", "Google", "GenV 男星去世"]]}}}
4 changes: 4 additions & 0 deletions call_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
from imdb_upcoming_movies import upcoming_movies
from imdb_week_top_10 import week_top_10
from imdb_whats_streaming import whats_streaming
from logger import *

os.environ["TAVILY_API_KEY"] = TAVILY_API_KEY
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY

def use_actual_tool(tool: str, tool_input: dict):
logger.info(f"调用工具:{tool}")
logger.info(f"工具输入:{tool_input}")
search = TavilySearchResults()

# 通用API
Expand All @@ -58,6 +61,7 @@ def use_actual_tool(tool: str, tool_input: dict):
# result = current_weather(tool_input)
# 24小时内的天气预报
elif tool == "WeatherSearch":
return "长沙现在的天气是晴天,温度是25摄氏度,湿度是50%。"
result = weather_forcast_24h(tool_input)
elif tool == "SunriseSunset":
result = sunrise_sunset(tool_input)
Expand Down
6 changes: 3 additions & 3 deletions chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def check_yes():
# 用户确认后继续执行计划
url_continue = "http://localhost:8000/continue"
url_continue = "http://localhost:8000/execute_plan"
state_str = st.session_state["rewoo_state"]

if state_str:
Expand Down Expand Up @@ -63,8 +63,8 @@ def check_yes():
st.session_state["messages"].append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)

# 调用 /chat 端点生成计划
url_chat = "http://localhost:8000/chat"
# 调用 /get_plan 端点生成计划
url_chat = "http://localhost:8000/get_plan"
payload = {"message": prompt}
response = requests.post(url_chat, json=payload)

Expand Down
5 changes: 2 additions & 3 deletions rewoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _get_current_task(state: ReWOO):
def tool_execution(state: ReWOO):
"""执行计划中的工具。"""


_step = _get_current_task(state)
_, step_name, tool, tool_input = state["steps"][_step - 1]
_results = state["results"] or {}
Expand All @@ -91,8 +90,8 @@ def tool_execution(state: ReWOO):
logger.info(f"Executing step {_step}: {step_name} using {tool} with input {tool_input}")

# 专门来选择并执行工具
# result = use_actual_tool(tool, tool_input)
result = "genv是2024年上映的一部美国超级英雄电视剧"
result = use_actual_tool(tool, tool_input)
# result = "genv是2024年上映的一部美国超级英雄电视剧"

_results[step_name] = str(result)
return {"results": _results}
Expand Down

0 comments on commit d4cffcf

Please sign in to comment.