bstraehle commited on
Commit
d2062a1
·
1 Parent(s): 9b71572

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -1,7 +1,8 @@
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
@@ -12,8 +13,9 @@ config = {
12
  "temperature": 0
13
  }
14
 
15
- AGENT_OFF = False
16
- AGENT_ON = True
 
17
 
18
  def invoke(openai_api_key, prompt, agent_option):
19
  if (openai_api_key == ""):
@@ -28,7 +30,19 @@ def invoke(openai_api_key, prompt, agent_option):
28
  output = ""
29
 
30
  try:
31
- if (agent_option == AGENT_OFF):
 
 
 
 
 
 
 
 
 
 
 
 
32
  client = OpenAI()
33
 
34
  completion = client.chat.completions.create(
@@ -37,13 +51,6 @@ def invoke(openai_api_key, prompt, agent_option):
37
  temperature = config["temperature"])
38
 
39
  output = completion.choices[0].message.content
40
- else:
41
- completion = invoke_agent(
42
- config["model"],
43
- config["temperature"],
44
- prompt)
45
-
46
- output = completion["output"]
47
  except Exception as e:
48
  err_msg = e
49
 
@@ -56,7 +63,7 @@ gr.close_all()
56
  demo = gr.Interface(fn = invoke,
57
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
58
  gr.Textbox(label = "Prompt", lines = 1, value = "How does current weather in Los Angeles, New York, and Paris compare in metric and imperial system? Answer in JSON format and include today's date."),
59
- gr.Radio([AGENT_OFF, AGENT_ON], label = "Use Agent", value = AGENT_ON)],
60
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
61
  title = "Real-Time Reasoning Application",
62
  description = os.environ["DESCRIPTION"])
 
1
  import gradio as gr
2
  import os
3
 
4
+ from agent_langchain import agent_langchain
5
+ from agent_llamaindex import agent_llamaindex
6
  from openai import OpenAI
7
 
8
  from dotenv import load_dotenv, find_dotenv
 
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 == ""):
 
30
  output = ""
31
 
32
  try:
33
+ if (agent_option == AGENT_LANGCHAIN):
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(
 
51
  temperature = config["temperature"])
52
 
53
  output = completion.choices[0].message.content
 
 
 
 
 
 
 
54
  except Exception as e:
55
  err_msg = e
56
 
 
63
  demo = gr.Interface(fn = invoke,
64
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
65
  gr.Textbox(label = "Prompt", lines = 1, value = "How does current weather in Los Angeles, New York, and Paris compare in metric and imperial system? Answer in JSON format and include today's date."),
66
+ gr.Radio([AGENT_OFF, AGENT_LANGCHAIN, AGENT_LLAMAINDEX], label = "Use Agent", value = AGENT_LANGCHAIN)],
67
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
68
  title = "Real-Time Reasoning Application",
69
  description = os.environ["DESCRIPTION"])