bstraehle commited on
Commit
6a833cd
·
1 Parent(s): 9b1ff17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -10,6 +10,9 @@ config = {
10
  "temperature": 0,
11
  }
12
 
 
 
 
13
  @tool
14
  def time(text: str) -> str:
15
  """Returns todays date, use this for any \
@@ -20,28 +23,33 @@ def time(text: str) -> str:
20
  outside this function."""
21
  return str(date.today())
22
 
23
- def invoke(openai_api_key, prompt):
24
  if (openai_api_key == ""):
25
  raise gr.Error("OpenAI API Key is required.")
26
  if (prompt == ""):
27
  raise gr.Error("Prompt is required.")
 
 
28
 
29
  output = ""
30
 
31
  try:
32
- llm = ChatOpenAI(model_name = config["model_name"],
33
- openai_api_key = openai_api_key,
34
- temperature = config["temperature"])
 
 
 
35
 
36
- agent = initialize_agent([time],
37
- llm,
38
- agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
39
- handle_parsing_errors = True,
40
- verbose = True)
41
 
42
- completion = agent(prompt)
43
 
44
- output = completion["output"]
45
  except Exception as e:
46
  err_msg = e
47
 
@@ -55,8 +63,9 @@ description = """<a href='https://www.gradio.app/'>Gradio</a> UI using the <a hr
55
  gr.close_all()
56
 
57
  demo = gr.Interface(fn = invoke,
58
- inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
59
- gr.Textbox(label = "Prompt", lines = 1, value = "What is today's date?")],
 
60
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
61
  title = "Generative AI - LLM & Agent",
62
  description = description,
 
10
  "temperature": 0,
11
  }
12
 
13
+ AGENT_OFF = False
14
+ AGENT_ON = True
15
+
16
  @tool
17
  def time(text: str) -> str:
18
  """Returns todays date, use this for any \
 
23
  outside this function."""
24
  return str(date.today())
25
 
26
+ def invoke(openai_api_key, prompt, agent_option):
27
  if (openai_api_key == ""):
28
  raise gr.Error("OpenAI API Key is required.")
29
  if (prompt == ""):
30
  raise gr.Error("Prompt is required.")
31
+ if (agent_option is None):
32
+ raise gr.Error("Use Agent is required.")
33
 
34
  output = ""
35
 
36
  try:
37
+ if (agent_option == AGENT_OFF):
38
+ #
39
+ else:
40
+ llm = ChatOpenAI(model_name = config["model_name"],
41
+ openai_api_key = openai_api_key,
42
+ temperature = config["temperature"])
43
 
44
+ agent = initialize_agent([time],
45
+ llm,
46
+ agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
47
+ handle_parsing_errors = True,
48
+ verbose = True)
49
 
50
+ completion = agent(prompt)
51
 
52
+ output = completion["output"]
53
  except Exception as e:
54
  err_msg = e
55
 
 
63
  gr.close_all()
64
 
65
  demo = gr.Interface(fn = invoke,
66
+ inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1, value = "sk-"),
67
+ gr.Textbox(label = "Prompt", lines = 1, value = "What is today's date?"),
68
+ gr.Radio([AGENT_OFF, AGENT_ON], label = "Use Agent", value = AGENT_OFF)],
69
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
70
  title = "Generative AI - LLM & Agent",
71
  description = description,