Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,15 +8,15 @@ from openai import OpenAI
|
|
8 |
from dotenv import load_dotenv, find_dotenv
|
9 |
_ = load_dotenv(find_dotenv())
|
10 |
|
|
|
|
|
|
|
|
|
11 |
config = {
|
12 |
"model": "gpt-4-0613",
|
13 |
"temperature": 0
|
14 |
}
|
15 |
|
16 |
-
AGENT_OFF = "Off"
|
17 |
-
AGENT_LANGCHAIN = "LangChain"
|
18 |
-
AGENT_LLAMAINDEX = "LlamaIndex"
|
19 |
-
|
20 |
def invoke(openai_api_key, prompt, agent_option):
|
21 |
if (openai_api_key == ""):
|
22 |
raise gr.Error("OpenAI API Key is required.")
|
@@ -34,21 +34,24 @@ def invoke(openai_api_key, prompt, agent_option):
|
|
34 |
completion = agent_langchain(
|
35 |
config["model"],
|
36 |
config["temperature"],
|
37 |
-
prompt
|
|
|
38 |
|
39 |
output = completion["output"]
|
40 |
elif (agent_option == AGENT_LLAMAINDEX):
|
41 |
output = agent_llamaindex(
|
42 |
config["model"],
|
43 |
config["temperature"],
|
44 |
-
prompt
|
|
|
45 |
else:
|
46 |
client = OpenAI()
|
47 |
|
48 |
completion = client.chat.completions.create(
|
49 |
messages = [{"role": "user", "content": prompt}],
|
50 |
model = config["model"],
|
51 |
-
temperature = config["temperature"]
|
|
|
52 |
|
53 |
output = completion.choices[0].message.content
|
54 |
except Exception as e:
|
@@ -60,12 +63,13 @@ def invoke(openai_api_key, prompt, agent_option):
|
|
60 |
|
61 |
gr.close_all()
|
62 |
|
63 |
-
demo = gr.Interface(
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
70 |
|
71 |
demo.launch()
|
|
|
8 |
from dotenv import load_dotenv, find_dotenv
|
9 |
_ = load_dotenv(find_dotenv())
|
10 |
|
11 |
+
AGENT_OFF = "Off"
|
12 |
+
AGENT_LANGCHAIN = "LangChain"
|
13 |
+
AGENT_LLAMAINDEX = "LlamaIndex"
|
14 |
+
|
15 |
config = {
|
16 |
"model": "gpt-4-0613",
|
17 |
"temperature": 0
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
20 |
def invoke(openai_api_key, prompt, agent_option):
|
21 |
if (openai_api_key == ""):
|
22 |
raise gr.Error("OpenAI API Key is required.")
|
|
|
34 |
completion = agent_langchain(
|
35 |
config["model"],
|
36 |
config["temperature"],
|
37 |
+
prompt
|
38 |
+
)
|
39 |
|
40 |
output = completion["output"]
|
41 |
elif (agent_option == AGENT_LLAMAINDEX):
|
42 |
output = agent_llamaindex(
|
43 |
config["model"],
|
44 |
config["temperature"],
|
45 |
+
prompt
|
46 |
+
)
|
47 |
else:
|
48 |
client = OpenAI()
|
49 |
|
50 |
completion = client.chat.completions.create(
|
51 |
messages = [{"role": "user", "content": prompt}],
|
52 |
model = config["model"],
|
53 |
+
temperature = config["temperature"]
|
54 |
+
)
|
55 |
|
56 |
output = completion.choices[0].message.content
|
57 |
except Exception as e:
|
|
|
63 |
|
64 |
gr.close_all()
|
65 |
|
66 |
+
demo = gr.Interface(
|
67 |
+
fn = invoke,
|
68 |
+
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
|
69 |
+
gr.Textbox(label = "Prompt", lines = 1, value = "How does current weather in San Francisco and Paris compare in metric and imperial system? Answer in JSON format and include today's date."),
|
70 |
+
gr.Radio([AGENT_OFF, AGENT_LANGCHAIN, AGENT_LLAMAINDEX], label = "Use Agent", value = AGENT_LANGCHAIN)],
|
71 |
+
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
72 |
+
title = "Real-Time Reasoning Application",
|
73 |
+
description = os.environ["DESCRIPTION"])
|
74 |
|
75 |
demo.launch()
|