bstraehle commited on
Commit
5bbf5a8
1 Parent(s): 9257296

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -36,25 +36,30 @@ def invoke(openai_api_key, prompt, agent_option):
36
  output = ""
37
 
38
  try:
39
- llm = ChatOpenAI(model_name = config["model_name"],
40
- openai_api_key = openai_api_key,
41
- temperature = config["temperature"])
42
-
43
  if (agent_option == AGENT_OFF):
44
- agent = initialize_agent([], # no tools
45
- llm,
46
- agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
47
- handle_parsing_errors = True,
48
- verbose = True)
 
 
 
49
  else:
 
 
 
 
 
50
  tools = load_tools(["openweathermap-api"])
51
 
52
- agent = initialize_agent(tools + # built-in tools
53
- [time], # custom tools
54
- llm,
55
- agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
56
- handle_parsing_errors = True,
57
- verbose = True)
 
58
 
59
  completion = agent(prompt)
60
 
 
36
  output = ""
37
 
38
  try:
 
 
 
 
39
  if (agent_option == AGENT_OFF):
40
+ client = OpenAI(api_key = openai_api_key)
41
+
42
+ completion = client.chat.completions.create(
43
+ messages = [{"role": "user", "content": prompt}],
44
+ model = config["model"],
45
+ temperature = config["temperature"],)
46
+
47
+ output = completion.choices[0].message.content
48
  else:
49
+ llm = ChatOpenAI(
50
+ model_name = config["model_name"],
51
+ openai_api_key = openai_api_key,
52
+ temperature = config["temperature"])
53
+
54
  tools = load_tools(["openweathermap-api"])
55
 
56
+ agent = initialize_agent(
57
+ tools + # built-in tools
58
+ [time], # custom tools
59
+ llm,
60
+ agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
61
+ handle_parsing_errors = True,
62
+ verbose = True)
63
 
64
  completion = agent(prompt)
65