Skip to content

Commit ec167b0

Browse files
authored
Adding OpenAI LLM support
Imported missing libraries. imported OpenAI for ChatGPT support. Corrected prompt path and reading style. Added optional memory saving.
1 parent 941a33c commit ec167b0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

main.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
from llama_index.core.tools import FunctionTool
33
from llama_index.core.memory import ChatMemoryBuffer
44

5-
from llama_index.llms.anthropic import Anthropic
65
from tools import PDFExtractor, AskVisionModel, StructuredFileReader, Report
76

7+
from llama_index.llms.anthropic import Anthropic
8+
from llama_index.llms.ollama import Ollama
9+
from llama_index.llms.openai import OpenAI
10+
811
CLAUDE_API_KEY="<ANTROPIC-API-KEY>"
912
llm = Anthropic(model="claude-3-opus-20240229", # you can change the model
1013
api_key=CLAUDE_API_KEY)
14+
OPENAI_API_KEY="<OPENAI_API_KEY>"
15+
#llm = OpenAI(model="gpt-4", api_key=OPENAI_API_KEY)
1116

1217
#llm = Ollama(model="llama3", request_timeout=360)
1318

@@ -28,17 +33,24 @@
2833
name="Report",
2934
description="""Useful when you are done with analysis and want to save the final version of the report.""")
3035

31-
with open("claude_prompt.txt", "r") as f:
36+
with open("prompts/claude_prompt.txt", "r") as f:
3237
prompt = f.readlines()
3338

3439
agent = ReActAgent.from_tools(llm=llm,
35-
max_iterations = 20,
40+
max_iterations=20,
3641
tools=[pdf_tool, askvision_tool, directory_tool, report_tool],
3742
verbose=True,
3843
memory=ChatMemoryBuffer.from_defaults(llm=llm),
3944
chat_history=[
4045
{"role":"system", "content": prompt}])
4146

42-
#text = "I want you to read files provided and create a complete analysis of my company's stats"
47+
#text = "I want you to read files provided and create a complete analysis of my company's stats."
4348
text = input("Ask: ")
44-
print(agent.chat(text))
49+
print(agent.chat(text))
50+
51+
52+
# Optional: saving Agent's memory to a file
53+
#memory_path = "memory.txt"
54+
#with open(memory_path, "w") as file:
55+
# file.write(str(agent.memory.to_string()))
56+
#print(f"Memory saved to {memory_path}")

0 commit comments

Comments
 (0)