eagle0504 commited on
Commit
9206a9e
1 Parent(s): dd917b9

search added

Browse files
Files changed (3) hide show
  1. app.py +16 -2
  2. helpers/foundation_models.py +18 -1
  3. requirements.txt +2 -0
app.py CHANGED
@@ -2,11 +2,15 @@ import os
2
 
3
  import openai
4
  import streamlit as st
 
 
5
  from transformers import pipeline
6
 
7
  from helpers.foundation_models import *
8
 
9
- openai_client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])
 
 
10
 
11
 
12
  # Initialize chat history
@@ -34,7 +38,7 @@ with st.expander("Instructions"):
34
 
35
  option = st.sidebar.selectbox(
36
  "Which task do you want to do?",
37
- ("Sentiment Analysis", "Medical Summarization", "ChatGPT"),
38
  )
39
 
40
 
@@ -74,6 +78,16 @@ if prompt := st.chat_input("What is up?"):
74
  if prompt:
75
  out = call_chatgpt(query=prompt)
76
  doc = out
 
 
 
 
 
 
 
 
 
 
77
  else:
78
  doc = ""
79
 
 
2
 
3
  import openai
4
  import streamlit as st
5
+ from langchain.agents import AgentType, initialize_agent, load_tools
6
+ from langchain.llms import OpenAI as l_OpenAI
7
  from transformers import pipeline
8
 
9
  from helpers.foundation_models import *
10
 
11
+ OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
12
+ SERPAPI_API_KEY = os.environ["SERPAPI_API_KEY"]
13
+ openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
14
 
15
 
16
  # Initialize chat history
 
38
 
39
  option = st.sidebar.selectbox(
40
  "Which task do you want to do?",
41
+ ("Sentiment Analysis", "Medical Summarization", "ChatGPT", "ChatGPT (with Google)"),
42
  )
43
 
44
 
 
78
  if prompt:
79
  out = call_chatgpt(query=prompt)
80
  doc = out
81
+ elif option == "ChatGPT (with Google)":
82
+ if prompt:
83
+ ans_langchain = call_langchain(prompt)
84
+ prompt = f"""
85
+ Based on the internet search results: {ans_langchain};
86
+
87
+ Answer the user question: {prompt}
88
+ """
89
+ out = call_chatgpt(query=prompt)
90
+ doc = out
91
  else:
92
  doc = ""
93
 
helpers/foundation_models.py CHANGED
@@ -3,8 +3,12 @@ from typing import List, Tuple
3
 
4
  import openai
5
  import streamlit as st
 
 
6
 
7
- openai_client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])
 
 
8
 
9
 
10
  def call_chatgpt(query: str, model: str = "gpt-3.5-turbo") -> str:
@@ -36,3 +40,16 @@ def call_chatgpt(query: str, model: str = "gpt-3.5-turbo") -> str:
36
 
37
  # Return the generated content.
38
  return content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  import openai
5
  import streamlit as st
6
+ from langchain.agents import AgentType, initialize_agent, load_tools
7
+ from langchain.llms import OpenAI as l_OpenAI
8
 
9
+ OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
10
+ SERPAPI_API_KEY = os.environ["SERPAPI_API_KEY"]
11
+ openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
12
 
13
 
14
  def call_chatgpt(query: str, model: str = "gpt-3.5-turbo") -> str:
 
40
 
41
  # Return the generated content.
42
  return content
43
+
44
+
45
+ def call_langchain(prompt: str) -> str:
46
+ llm = l_OpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
47
+ tools = load_tools(
48
+ ["serpapi", "llm-math"], llm=llm, serpapi_api_key=SERPAPI_API_KEY
49
+ )
50
+ agent = initialize_agent(
51
+ tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
52
+ )
53
+ output = agent.run(prompt)
54
+
55
+ return output
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
  torch
 
 
2
  openai
3
  transformers
 
1
  torch
2
+ google-search-results
3
+ langchain
4
  openai
5
  transformers