bstraehle commited on
Commit
3b50f76
·
1 Parent(s): 737e02d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -29
app.py CHANGED
@@ -2,15 +2,8 @@ import gradio as gr
2
  import os
3
 
4
  from datetime import date
5
- from langchain import hub
6
- from langchain.agents import AgentExecutor, AgentType, create_openai_functions_agent, initialize_agent, tool
7
  from langchain.chat_models import ChatOpenAI
8
- from langchain_community.tools.tavily_search import TavilySearchResults
9
-
10
- from dotenv import load_dotenv, find_dotenv
11
- _ = load_dotenv(find_dotenv())
12
-
13
- TAVILY_API_KEY = os.environ["TAVILY_API_KEY"]
14
 
15
  config = {
16
  "max_tokens": 1000,
@@ -49,27 +42,15 @@ def invoke(openai_api_key, prompt, agent_option):
49
  openai_api_key = openai_api_key,
50
  temperature = config["temperature"])
51
 
52
- search = TavilySearchResults()
53
-
54
- tools = [search]
55
-
56
- #agent = initialize_agent(tools + [time],
57
- # llm,
58
- # agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
59
- # handle_parsing_errors = True,
60
- # verbose = True)
61
-
62
- p = hub.pull("hwchase17/openai-functions-agent")
63
-
64
- agent = create_openai_functions_agent(llm, tools, p)
65
-
66
- agent_executor = AgentExecutor(agent = agent, tools = tools, verbose = True)
67
 
68
- output = agent_executor.invoke({"input": prompt})
69
-
70
- #completion = agent(prompt)
71
 
72
- #output = completion["output"]
73
  except Exception as e:
74
  err_msg = e
75
 
@@ -89,8 +70,7 @@ demo = gr.Interface(fn = invoke,
89
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
90
  title = "Generative AI - LLM & Agent",
91
  description = description,
92
- examples = [["sk-", "What is today's date?", AGENT_ON],
93
- ["sk-", "What is the weather in SF?", AGENT_ON]],
94
  cache_examples = False)
95
 
96
  demo.launch()
 
2
  import os
3
 
4
  from datetime import date
5
+ from langchain.agents import AgentType, initialize_agent, tool
 
6
  from langchain.chat_models import ChatOpenAI
 
 
 
 
 
 
7
 
8
  config = {
9
  "max_tokens": 1000,
 
42
  openai_api_key = openai_api_key,
43
  temperature = config["temperature"])
44
 
45
+ agent = initialize_agent([time],
46
+ llm,
47
+ agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
48
+ handle_parsing_errors = True,
49
+ verbose = True)
 
 
 
 
 
 
 
 
 
 
50
 
51
+ completion = agent(prompt)
 
 
52
 
53
+ output = completion["output"]
54
  except Exception as e:
55
  err_msg = e
56
 
 
70
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
71
  title = "Generative AI - LLM & Agent",
72
  description = description,
73
+ examples = [["sk-", "What is today's date?", AGENT_ON]],
 
74
  cache_examples = False)
75
 
76
  demo.launch()