Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
-
from
|
5 |
-
from langchain.agents import AgentType, initialize_agent, load_tools, tool
|
6 |
-
from langchain.chat_models import ChatOpenAI
|
7 |
from openai import OpenAI
|
8 |
|
9 |
from dotenv import load_dotenv, find_dotenv
|
10 |
_ = load_dotenv(find_dotenv())
|
11 |
|
12 |
-
OPENWEATHERMAP_API_KEY = os.environ["OPENWEATHERMAP_API_KEY"]
|
13 |
-
|
14 |
config = {
|
15 |
"model": "gpt-4-0613",
|
16 |
"temperature": 0,
|
@@ -19,13 +15,6 @@ config = {
|
|
19 |
AGENT_OFF = False
|
20 |
AGENT_ON = True
|
21 |
|
22 |
-
@tool
|
23 |
-
def date_tool(text: str) -> str:
|
24 |
-
"""Returns today's date. Use this for any questions related to knowing today's date.
|
25 |
-
The input should always be an empty string, and this function will always return today's date.
|
26 |
-
Any date mathematics should occur outside this function."""
|
27 |
-
return str(date.today())
|
28 |
-
|
29 |
def invoke(openai_api_key, prompt, agent_option):
|
30 |
if (openai_api_key == ""):
|
31 |
raise gr.Error("OpenAI API Key is required.")
|
@@ -47,7 +36,10 @@ def invoke(openai_api_key, prompt, agent_option):
|
|
47 |
|
48 |
output = completion.choices[0].message.content
|
49 |
else:
|
50 |
-
completion = invoke_agent(
|
|
|
|
|
|
|
51 |
|
52 |
output = completion["output"]
|
53 |
except Exception as e:
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
+
from Agent import invoke_agent
|
|
|
|
|
5 |
from openai import OpenAI
|
6 |
|
7 |
from dotenv import load_dotenv, find_dotenv
|
8 |
_ = load_dotenv(find_dotenv())
|
9 |
|
|
|
|
|
10 |
config = {
|
11 |
"model": "gpt-4-0613",
|
12 |
"temperature": 0,
|
|
|
15 |
AGENT_OFF = False
|
16 |
AGENT_ON = True
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def invoke(openai_api_key, prompt, agent_option):
|
19 |
if (openai_api_key == ""):
|
20 |
raise gr.Error("OpenAI API Key is required.")
|
|
|
36 |
|
37 |
output = completion.choices[0].message.content
|
38 |
else:
|
39 |
+
completion = invoke_agent(model,
|
40 |
+
temperature,
|
41 |
+
openai_api_key,
|
42 |
+
prompt)
|
43 |
|
44 |
output = completion["output"]
|
45 |
except Exception as e:
|