L4 Persistence and Streaming

參考自https://www.deeplearning.ai/short-courses/ai-agents-in-langgraph,以下為代碼的實現。

  • 這里主要是加入了memory,這樣通過self.graph = graph.compile(checkpointer=checkpointer)就可以加入持久性的檢查點
  • 通過thread = {"configurable": {"thread_id": "1"}}指示線程id和其對應的持久性的檢查點
  • SqliteSaver使用Sqlite數據庫進行流式處理
  • 把檢查點的SqliteSaver改成異步的AsyncSqliteSaver,可以在token級進行流式處理
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage, ToolMessage
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
tool = TavilySearchResults(max_results=2)
class AgentState(TypedDict):messages: Annotated[list[AnyMessage], operator.add]
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
from langgraph.checkpoint.sqlite import SqliteSavermemory = SqliteSaver.from_conn_string(":memory:")
class Agent:def __init__(self, model, tools, checkpointer, system=""):self.system = systemgraph = StateGraph(AgentState)graph.add_node("llm", self.call_openai)graph.add_node("action", self.take_action)graph.add_conditional_edges("llm",self.exists_action,{True: "action", False: END})graph.add_edge("action", "llm")graph.set_entry_point("llm")self.graph = graph.compile(checkpointer=checkpointer)self.tools = {t.name: t for t in tools}self.model = model.bind_tools(tools)logger.info(f"model: {self.model}")def exists_action(self, state: AgentState):result = state['messages'][-1]logger.info(f"exists_action result: {result}")return len(result.tool_calls) > 0def call_openai(self, state: AgentState):logger.info(f"state: {state}")messages = state['messages']if self.system:messages = [SystemMessage(content=self.system)] + messagesmessage = self.model.invoke(messages)logger.info(f"LLM message: {message}")return {'messages': [message]}def take_action(self, state: AgentState):import threadingprint(f"take_action called in thread: {threading.current_thread().name}")tool_calls = state['messages'][-1].tool_callsresults = []print(f"take_action called with tool_calls: {tool_calls}")for t in tool_calls:logger.info(f"Calling: {t}")print(f"Calling: {t}") if not t['name'] in self.tools:      # check for bad tool name from LLMprint("\n ....bad tool name....")result = "bad tool name, retry"  # instruct LLM to retry if badelse:result = self.tools[t['name']].invoke(t['args'])logger.info(f"action {t['name']}, result: {result}")print(f"action {t['name']}, result: {result}")results.append(ToolMessage(tool_call_id=t['id'], name=t['name'], content=str(result)))print("Back to the model!")return {'messages': results}
prompt = """You are a smart research assistant. Use the search engine to look up information. \
You are allowed to make multiple calls (either together or in sequence). \
Only look up information when you are sure of what you want. \
If you need to look up some information before asking a follow up question, you are allowed to do that!
"""
model = ChatOpenAI(model="gpt-4o")
abot = Agent(model, [tool], system=prompt, checkpointer=memory)
INFO:__main__:model: bound=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000002A44F2D6CC0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000002A44AEE7920>, model_name='gpt-4o', openai_api_key=SecretStr('**********'), openai_proxy='') kwargs={'tools': [{'type': 'function', 'function': {'name': 'tavily_search_results_json', 'description': 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}}]}
messages = [HumanMessage(content="What is the weather in sf?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):for v in event.values():print(v['messages'])
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}] usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}] usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}[AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173})]
take_action called in thread: ThreadPoolExecutor-0_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}INFO:__main__:action tavily_search_results_json, result: HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B')]}action tavily_search_results_json, result: HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')
Back to the model!
[ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B')]INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like." response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0' usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}
INFO:__main__:exists_action result: content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like." response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0' usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}[AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259})]
messages = [HumanMessage(content="What about in la?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):for v in event.values():print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}] usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}] usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293})]}
take_action called in thread: ThreadPoolExecutor-1_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'Los Angeles', 'region': 'California', 'country': 'United States of America', 'lat': 34.05, 'lon': -118.24, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593698, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 18.3, 'temp_f': 64.9, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 3.8, 'wind_kph': 6.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1010.0, 'pressure_in': 29.83, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 84, 'cloud': 50, 'feelslike_c': 18.3, 'feelslike_f': 64.9, 'windchill_c': 24.4, 'windchill_f': 76.0, 'heatindex_c': 25.6, 'heatindex_f': 78.0, 'dewpoint_c': 14.4, 'dewpoint_f': 58.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 8.3, 'gust_kph': 13.3}}"}, {'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'Los Angeles\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 34.05, \'lon\': -118.24, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 18.3, \'temp_f\': 64.9, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 3.8, \'wind_kph\': 6.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1010.0, \'pressure_in\': 29.83, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 84, \'cloud\': 50, \'feelslike_c\': 18.3, \'feelslike_f\': 64.9, \'windchill_c\': 24.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'url\': \'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10\', \'content\': \'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225')]}action tavily_search_results_json, result: [{'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'Los Angeles', 'region': 'California', 'country': 'United States of America', 'lat': 34.05, 'lon': -118.24, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593698, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 18.3, 'temp_f': 64.9, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 3.8, 'wind_kph': 6.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1010.0, 'pressure_in': 29.83, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 84, 'cloud': 50, 'feelslike_c': 18.3, 'feelslike_f': 64.9, 'windchill_c': 24.4, 'windchill_f': 76.0, 'heatindex_c': 25.6, 'heatindex_f': 78.0, 'dewpoint_c': 14.4, 'dewpoint_f': 58.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 8.3, 'gust_kph': 13.3}}"}, {'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}]
Back to the model!
{'messages': [ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'Los Angeles\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 34.05, \'lon\': -118.24, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 18.3, \'temp_f\': 64.9, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 3.8, \'wind_kph\': 6.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1010.0, \'pressure_in\': 29.83, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 84, \'cloud\': 50, \'feelslike_c\': 18.3, \'feelslike_f\': 64.9, \'windchill_c\': 24.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'url\': \'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10\', \'content\': \'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225')]}INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).' response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0' usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}
INFO:__main__:exists_action result: content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).' response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0' usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}{'messages': [AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939})]}
messages = [HumanMessage(content="Which one is warmer?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):for v in event.values():print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'Los Angeles\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 34.05, \'lon\': -118.24, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 18.3, \'temp_f\': 64.9, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 3.8, \'wind_kph\': 6.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1010.0, \'pressure_in\': 29.83, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 84, \'cloud\': 50, \'feelslike_c\': 18.3, \'feelslike_f\': 64.9, \'windchill_c\': 24.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'url\': \'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10\', \'content\': \'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225'), AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}), HumanMessage(content='Which one is warmer?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-792c6640-bcb9-48f7-8939-d87445d97469-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}] usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-792c6640-bcb9-48f7-8939-d87445d97469-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}] usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-792c6640-bcb9-48f7-8939-d87445d97469-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}], usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011})]}
take_action called in thread: ThreadPoolExecutor-2_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'San Francisco', 'region': 'California', 'country': 'United States of America', 'lat': 37.78, 'lon': -122.42, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}, {'url': 'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44', 'content': 'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...'}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}action tavily_search_results_json, result: [{'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'San Francisco', 'region': 'California', 'country': 'United States of America', 'lat': 37.78, 'lon': -122.42, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}, {'url': 'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44', 'content': 'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'Los Angeles\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 34.05, \'lon\': -118.24, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 18.3, \'temp_f\': 64.9, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 3.8, \'wind_kph\': 6.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1010.0, \'pressure_in\': 29.83, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 84, \'cloud\': 50, \'feelslike_c\': 18.3, \'feelslike_f\': 64.9, \'windchill_c\': 24.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'url\': \'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10\', \'content\': \'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225'), AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}), HumanMessage(content='Which one is warmer?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-792c6640-bcb9-48f7-8939-d87445d97469-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}], usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}), ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'San Francisco\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 37.78, \'lon\': -122.42, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}, {\'url\': \'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44\', \'content\': \'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...\'}]', name='tavily_search_results_json', tool_call_id='call_QWrXRdAk2G9gJjU8wjQ85lVD'), ToolMessage(content="[{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]", name='tavily_search_results_json', tool_call_id='call_ihCOlJ1Lv1SvjkYdp6FnFhF8')]}action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]
Back to the model!
{'messages': [ToolMessage(content='[{\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'San Francisco\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 37.78, \'lon\': -122.42, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}, {\'url\': \'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44\', \'content\': \'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...\'}]', name='tavily_search_results_json', tool_call_id='call_QWrXRdAk2G9gJjU8wjQ85lVD'), ToolMessage(content="[{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]", name='tavily_search_results_json', tool_call_id='call_ihCOlJ1Lv1SvjkYdp6FnFhF8')]}INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.' response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f27878a2-44cc-4679-a650-239c2f257023-0' usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860}
INFO:__main__:exists_action result: content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.' response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f27878a2-44cc-4679-a650-239c2f257023-0' usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860}{'messages': [AIMessage(content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.', response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f27878a2-44cc-4679-a650-239c2f257023-0', usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860})]}
# 改變線程id,沒有持久性的檢查點了
messages = [HumanMessage(content="Which one is warmer?")]
thread = {"configurable": {"thread_id": "2"}}
for event in abot.graph.stream({"messages": messages}, thread):for v in event.values():print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='Which one is warmer?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.' response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None} id='run-95f88168-c060-46db-8430-83ea9a39c477-0' usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177}
INFO:__main__:exists_action result: content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.' response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None} id='run-95f88168-c060-46db-8430-83ea9a39c477-0' usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177}{'messages': [AIMessage(content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.', response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None}, id='run-95f88168-c060-46db-8430-83ea9a39c477-0', usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177})]}

流式處理token本身

from langgraph.checkpoint.aiosqlite import AsyncSqliteSavermemory = AsyncSqliteSaver.from_conn_string(":memory:")
abot = Agent(model, [tool], system=prompt, checkpointer=memory)
INFO:__main__:model: bound=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000002A44F2D6CC0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000002A44AEE7920>, model_name='gpt-4o', openai_api_key=SecretStr('**********'), openai_proxy='') kwargs={'tools': [{'type': 'function', 'function': {'name': 'tavily_search_results_json', 'description': 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}}]}
messages = [HumanMessage(content="What is the weather in SF?")]
thread = {"configurable": {"thread_id": "4"}}
async for event in abot.graph.astream_events({"messages": messages}, thread, version="v1"):kind = event["event"]if kind == "on_chat_model_stream":content = event["data"]["chunk"].contentif content:# Empty content in the context of OpenAI means# that the model is asking for a tool to be invoked.# So we only print non-empty contentprint(content, end="|")
D:\wuzhongyanqiu\envs\pytorch\Lib\site-packages\langchain_core\_api\beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.warn_beta(
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in SF?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]} response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]} response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}take_action called in thread: asyncio_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10', 'content': 'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...'}, {'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'San Francisco', 'region': 'California', 'country': 'United States of America', 'lat': 37.78, 'lon': -122.42, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in SF?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'}, id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]), ToolMessage(content='[{\'url\': \'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10\', \'content\': \'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...\'}, {\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'San Francisco\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 37.78, \'lon\': -122.42, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}]', name='tavily_search_results_json', tool_call_id='call_zeYLxGgOxQSZtujg7rNsJ6Gx')]}action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10', 'content': 'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...'}, {'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'San Francisco', 'region': 'California', 'country': 'United States of America', 'lat': 37.78, 'lon': -122.42, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}]
Back to the model!INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"The| current| weather| in| San| Francisco|,| CA| is| |61|°F| (|16|.|1|°C|)| and| partly| cloudy|.| The| wind| is| blowing| from| the| west|-n|orth|west| at| |9|.|4| mph| (|15|.|1| k|ph|),| and| the| humidity| is| at| |90|%.| The| visibility| is| |16| km| (|9| miles|),| and| the|INFO:__main__:LLM message: content='The current weather in San Francisco, CA is 61°F (16.1°C) and partly cloudy. The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%. The visibility is 16 km (9 miles), and the UV index is 1.' response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-96dbd0cb-1f75-46c8-97df-2f64d201c26f'
INFO:__main__:exists_action result: content='The current weather in San Francisco, CA is 61°F (16.1°C) and partly cloudy. The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%. The visibility is 16 km (9 miles), and the UV index is 1.' response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-96dbd0cb-1f75-46c8-97df-2f64d201c26f'UV| index| is| |1|.|

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/44270.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/44270.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/44270.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

項目實戰--Spring Boot + GraphQL實現實時數據推送

背景 用戶體驗不斷提升而3對實時數據的需求日益增長&#xff0c;傳統的數據獲取方式無法滿足實時數據的即時性和個性化需求。 GraphQL作為新興的API查詢語言&#xff0c;提供更加靈活、高效的數據獲取方案。結合Spring Boot作為后端框架&#xff0c;利用GraphQL實現實時數據推…

Java筆試|面試 —— 對多態性的理解

談談對多態性的理解&#xff1a; 一個事物的多種形態&#xff08;編譯和運行時狀態不一致性&#xff09; 實現機制&#xff1a;通過繼承、重寫和向上轉型&#xff08;Object obj new 子類()&#xff09;來實現。 1.廣義上的理解 子類對象的多態性&#xff0c;方法的重寫&am…

visual studio 2022 在使用open3d出現的問題及解決方式

當出現以下問題&#xff1a; 使用open3d::utility::LogInfo系列出現LNK2001問題&#xff0c;如下所示&#xff1a;LNK2001 無法解析的外部符號 “char __cdecl fmt::v6::internal::decimal_point_impl(class fmt::v6::internal::locale_ref)” LNK2001 無法解析的外部符號 “p…

【C/C++】SDKDDKVer.h和WinSDKVer.h詳解及二者區別

一.SDKDDKVer.h介紹 SDKDDKVer.h 是一個在 Windows 軟件開發中常見的頭文件&#xff0c;它用于定義軟件開發工具包&#xff08;SDK&#xff09;和驅動開發工具包&#xff08;DDK&#xff09;的版本信息。這個文件通常位于 Visual Studio 安裝目錄下的 Include 子目錄中。 …

GD32MCU如何實現掉電數據保存?

大家在GD32 MCU應用時&#xff0c;是否會碰到以下應用需求&#xff1a;希望在MCU掉電時保存一定的數據或標志&#xff0c;用以記錄一些關鍵的數據。 以GD32E103為例&#xff0c;數據的存儲介質可以選擇內部Flash或者備份數據寄存器。 如下圖所示&#xff0c;片內Flash具有10年…

學習數據庫的增刪改查

一、創建數據庫和表 在進行增刪改查操作之前&#xff0c;我們需要創建一個數據庫和表。 1. 創建數據庫 使用 CREATE DATABASE 語句創建數據庫&#xff1a; CREATE DATABASE test_db;2. 選擇數據庫 使用 USE 語句選擇數據庫&#xff1a; USE test_db;3. 創建表 使用 CREA…

詳解C語言結構體

文章目錄 1.結構體的聲明1.1 結構體的基礎知識1.2 結構的聲明1.3 結構成員的類型 1.4結構體變量的定義和初始化2.結構體成員的訪問3.結構體傳參 1.結構體的聲明 1.1 結構體的基礎知識 結構是一些值的集合&#xff0c;這些值稱為成員變量。結構的每個成員可以是不同類型的變量 …

【密碼學】分組密碼概述

一、分組密碼的定義 分組密碼和流密碼都是對稱密碼體制。 流密碼&#xff1a;是將明文視為連續的比特流&#xff0c;對每個比特或字節進行實時加密&#xff0c;而不將其分割成固定的塊。流密碼適用于加密實時數據流&#xff0c;如網絡通信。分組密碼&#xff1a;是將明文數據…

【React】Ant Design -- Table分頁功能實現

實現步驟 為Table組件指定pagination屬性來展示分頁效果在分頁切換事件中獲取到篩選表單中選中的數據使用當前頁數據修改params參數依賴引起接口重新調用獲取最新數據 const pageChange (page) > {// 拿到當前頁參數 修改params 引起接口更新setParams({...params,page})…

翰德恩咨詢賦能材料行業上市公司,共筑IPD管理體系新篇章

賦能背景概覽 坐落于江蘇的某材料行業領軍企業&#xff0c;作為國內無機陶瓷膜元件及成套設備領域的佼佼者&#xff0c;以其龐大的生產規模、豐富的產品系列及卓越的研發實力&#xff0c;屹立行業之巔二十余年。公司不僅在新材料研發、技術創新、工藝設計、設備制造及整體解決…

【VUE進階】安裝使用Element Plus組件

Element Plus組件 安裝引入組件使用Layout 布局button按鈕行內表單菜單 安裝 包管理安裝 # 選擇一個你喜歡的包管理器# NPM $ npm install element-plus --save# Yarn $ yarn add element-plus# pnpm $ pnpm install element-plus瀏覽器直接引入 例如 <head><!-- I…

Transformer-LSTM預測 | Matlab實現Transformer-LSTM時間序列預測

Transformer-LSTM預測 | Matlab實現Transformer-LSTM時間序列預測 目錄 Transformer-LSTM預測 | Matlab實現Transformer-LSTM時間序列預測效果一覽基本介紹程序設計參考資料 效果一覽 基本介紹 1.Matlab實現Transformer-LSTM時間序列預測&#xff0c;Transformer-LSTM&#xf…

淺談“不要卷模型,要卷應用”

目錄 1.概述 2.AI技術應用場景探索 3.避免超級應用陷阱的策略 3.1.追求DAU的弊端 3.2.平衡用戶活躍度與應用實用性的策略 4.個性化智能體開發 4.1. 用戶需求分析與數據收集 4.2. 技術選擇與開發 4.3. 個性化算法設計 4.4. 安全性與隱私保護 4.5. 多渠道集成與響應機…

用vite創建Vue3項目的步驟和文件解釋

創建項目的原則是不能出現中文和特殊字符&#xff0c;最好為小寫字母&#xff0c;數字&#xff0c;下劃線組成 之后在visual studio code 中打開創建的這個項目 src是源代碼文件 vite和webpack是有去別的&#xff0c;對于這個vite創建的工程來說index.js是入口文件 在終端里面輸…

數字探秘:用神經網絡解密MNIST數據集中的數字!

用神經網絡解密MNIST數據集中的數字&#xff01; 一. 介紹1.1 MNIST數據集簡介1.2 MLP&#xff08;多層感知器&#xff09;模型介紹1.3 目標&#xff1a;使用MLP模型對MNIST數據集中的0-9數字進行分類 二.數據預處理2.1 數據集的獲取與加載2.2 數據集的探索性分析&#xff08;E…

騙子用出國月薪3萬騙了1000多萬上千名求職者被騙

日前,江蘇省南通市崇川區人民法院開庭審理了一起涉及詐騙的案件,該案件 審理后引發全國求職者的關注以及熱議。根據了解得知,這起案件的主犯是利用出 國勞務的虛假高薪職位位誘餌,最終有上千名求職者被騙上當了。文章來源于&#xff1a;股城網www.gucheng.com 根據法院審…

微信文件太大傳不了?學會這些,微信秒變大文件傳輸神器

在數字化時代&#xff0c;微信已成為我們日常溝通的重要橋梁。然而&#xff0c;當需要在微信上傳輸大文件時&#xff0c;文件大小的限制往往讓人束手無策。 今天&#xff0c;我們將分享一些實用的技巧&#xff0c;幫助你在微信上輕松傳輸大文件&#xff0c;無論是工作文檔還是…

HTTP 概況

Web的應用層協議是超文本傳輸協議(HyperTextTransferProtocol&#xff0c;HTTP)&#xff0c;它是 Web的核心。HTTP由兩個程序實現:一個客戶程序和一個服務器程序。客戶程序和服務器程序運行在不同的端系統中&#xff0c;通過交換HTTP報文進行會話。HTTP定義了這些報文的結構以及…

彩虹小插畫:成都亞恒豐創教育科技有限公司

彩虹小插畫&#xff1a;色彩斑斕的夢幻世界 在繁忙的生活節奏中&#xff0c;總有一抹溫柔的色彩能悄然觸動心弦&#xff0c;那就是彩虹小插畫帶來的夢幻與寧靜。彩虹&#xff0c;這一自然界的奇跡&#xff0c;被藝術家們巧妙地融入小巧精致的插畫之中&#xff0c;不僅捕捉了瞬…

事務未釋放問題排查

事務未釋放問題現象&#xff1a;一般會導致大量鎖表現象。 排查&#xff1a;查看所有鎖表報錯的日志是否都是同一個線程號上的&#xff0c;找到最開始的報錯并進行分析。