Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
tools = load_tools(["openweathermap-api"])
|
| 51 |
|
| 52 |
-
agent = initialize_agent(
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 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 |
|