Created
July 8, 2023 16:30
-
-
Save NotoriousArnav/bb91c0350613ebca293524e11699e226 to your computer and use it in GitHub Desktop.
SmartGPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import wikipedia, langchain, dotenv | |
except ImportError: | |
os.system("python -m pip install wikipedia langchain python-dotenv") | |
print("Rerun the app app since wikipedia got reinstalled") | |
exit() | |
from langchain.llms import OpenAI | |
from langchain.agents import load_tools, initialize_agent | |
from langchain.chains import LLMChain, ConversationChain | |
from langchain.chains.conversation.memory import ( | |
ConversationBufferMemory, | |
ConversationSummaryMemory, | |
ConversationBufferWindowMemory, | |
ConversationKGMemory | |
) | |
from dotenv import load_dotenv | |
import os | |
load_dotenv() | |
llm = OpenAI(temperature=0.9) | |
tools = load_tools(['serpapi', 'wikipedia', 'llm-math'], llm=llm) | |
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) | |
conversation = ConversationChain( | |
llm=llm | |
) | |
logs = [] | |
while True: | |
try: | |
inp = input("Prompt: ") | |
data = agent.run(inp) | |
print(data) | |
logs.append([inp, data]) | |
except Exception as e: | |
if isinstance(e, EOFError) or isinstance(e, KeyboardInterrupt): | |
break | |
import json, datetime | |
with open(f'.logs/log-{datetime.datetime.now()}.json', 'w') as f: f.write(json.dumps(logs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment