8
8
from langchain .agents import AgentType
9
9
from langchain .chat_models import ChatOpenAI
10
10
from langchain .tools import Tool , DuckDuckGoSearchRun
11
- from langchain .callbacks import StreamlitCallbackHandler
11
+ from langchain .callbacks import (
12
+ StreamlitCallbackHandler ,
13
+ get_openai_callback ,
14
+ )
12
15
13
16
from tools .mercantile_tool import MercantileTool
14
17
from tools .geopy .geocode import GeopyGeocodeTool
@@ -23,7 +26,7 @@ def get_llm():
23
26
llm = ChatOpenAI (
24
27
temperature = 0 ,
25
28
openai_api_key = os .environ ["OPENAI_API_KEY" ],
26
- model_name = "gpt-3.5-turbo" ,
29
+ model_name = "gpt-3.5-turbo-0613 " ,
27
30
)
28
31
return llm
29
32
@@ -92,7 +95,7 @@ def plot_vector(df):
92
95
st .subheader ("Add the geometry to the Map" )
93
96
center = df .centroid .iloc [0 ]
94
97
m = folium .Map (location = [center .y , center .x ], zoom_start = 12 )
95
- folium .GeoJson (gdf ).add_to (m )
98
+ folium .GeoJson (df ).add_to (m )
96
99
folium_static (m )
97
100
98
101
@@ -106,7 +109,14 @@ def plot_vector(df):
106
109
if st .button ("Submit" , key = "submit" , type = "primary" ):
107
110
llm = get_llm ()
108
111
agent = get_agent (llm )
109
- response = run_query (agent , query )
112
+
113
+ with get_openai_callback () as cb :
114
+ response = run_query (agent , query )
115
+ print (f"Model name: { response .llm_output .get ('model_name' , '' )} " )
116
+ print (f"Total Tokens: { cb .total_tokens } " )
117
+ print (f"Prompt Tokens: { cb .prompt_tokens } " )
118
+ print (f"Completion Tokens: { cb .completion_tokens } " )
119
+ print (f"Total Cost (USD): ${ cb .total_cost } " )
110
120
111
121
if type (response ) == str :
112
122
st .write (response )
0 commit comments