-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfallintern.py
More file actions
62 lines (51 loc) · 1.96 KB
/
fallintern.py
File metadata and controls
62 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from bs4 import BeautifulSoup
from dotenv import load_dotenv
import streamlit as st
from typing import Type
from tools import search, ScrapeWebsiteTool
from langchain.agents import initialize_agent, Tool, AgentType
from langchain_openai import ChatOpenAI
from langchain.prompts import MessagesPlaceholder
from langchain.memory import ConversationSummaryBufferMemory
from langchain.schema import SystemMessage
# Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
BROWSERLESS_API_KEY = os.getenv("BROWSERLESS_API_KEY")
SERPER_API_KEY = os.getenv("SERPER_API_KEY")
llm = ChatOpenAI(model_name='gpt-4-1106-preview')
tools = [
Tool(name="Search", func=search, description="Answer questions using current events/data. Be specific."),
ScrapeWebsiteTool(),
]
system_message_content = """..."""
agent_kwargs = {
"extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
"system_message": SystemMessage(content=system_message_content),
}
memory = ConversationSummaryBufferMemory(
memory_key="memory", return_messages=True, llm=llm, max_token_limit=1000)
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True,
max_iterations=5,
agent_kwargs=agent_kwargs,
memory=memory,
)
def main():
"""Main Streamlit application."""
st.set_page_config(page_title="Fall Intern", page_icon=":bird:")
st.header(":globe_with_meridians: Fall Intern")
st.subheader('Go deeper on topics and questions.')
query = st.text_input("Research goal")
st.sidebar.title('About the app')
st.sidebar.markdown("Fall Intern is a research assistant that will answer your query by searching, scraping and summmarizing real time results from across the web and return a cogent document with citations.")
if query:
with st.spinner("Researching..."):
result = agent({"input": query})
st.info(result['output'])
if __name__ == '__main__':
main()