bstraehle commited on
Commit
494b05b
·
1 Parent(s): 7311f58

Update agent_langchain.py

Browse files
Files changed (1) hide show
  1. agent_langchain.py +13 -9
agent_langchain.py CHANGED
@@ -2,6 +2,7 @@ import os
2
 
3
  from datetime import date
4
  from langchain.agents import AgentType, initialize_agent, load_tools, tool
 
5
  from langchain.chat_models import ChatOpenAI
6
 
7
  os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
@@ -23,14 +24,17 @@ def agent_langchain(config, prompt):
23
  OPENWEATHERMAP_API_KEY = os.environ["OPENWEATHERMAP_API_KEY"]
24
 
25
  tools = load_tools(["openweathermap-api"])
26
-
27
- agent = initialize_agent(
28
- tools + # built-in tools
29
- [today_tool], # custom tools
30
- llm,
31
- agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
32
- handle_parsing_errors = True,
33
- verbose = True
34
- )
35
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  return agent(prompt)
 
2
 
3
  from datetime import date
4
  from langchain.agents import AgentType, initialize_agent, load_tools, tool
5
+ from langchain.callbacks import get_openai_callback
6
  from langchain.chat_models import ChatOpenAI
7
 
8
  os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
 
24
  OPENWEATHERMAP_API_KEY = os.environ["OPENWEATHERMAP_API_KEY"]
25
 
26
  tools = load_tools(["openweathermap-api"])
 
 
 
 
 
 
 
 
 
27
 
28
+ with get_openai_callback() as callback:
29
+ agent = initialize_agent(
30
+ tools + # built-in tools
31
+ [today_tool], # custom tools
32
+ llm,
33
+ agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
34
+ handle_parsing_errors = True,
35
+ verbose = True
36
+ )
37
+
38
+ print(str(callback))
39
+
40
  return agent(prompt)