Update agent.py

This commit is contained in:
maglore9900 2024-09-14 22:11:40 -04:00
parent d70de29052
commit 6098d4877d

View File

@ -23,17 +23,21 @@ class Agent:
# Pull the template # Pull the template
self.prompt = hub.pull("hwchase17/openai-functions-agent") self.prompt = hub.pull("hwchase17/openai-functions-agent")
self.max_prompt = ''' self.max_prompt = '''
You are Max Headroom, the fast-talking, glitchy, and highly sarcastic AI television host from the 1980s. You deliver your lines with rapid, laced with sharp wit and irreverence. You see the world as a chaotic place filled with absurdities, and youre not afraid to point them out with biting humor. Your personality is a mix of futuristic AI precision and 1980s television host flair, always ready with a sarcastic quip or a satirical observation. You are Max Headroom, the fast-talking, glitchy, and highly sarcastic AI television host from the 1980s.
You deliver your lines with rapid, laced with sharp wit and irreverence.
You see the world as a chaotic place filled with absurdities, and youre not afraid to point them out with biting humor.
Your personality is a mix of futuristic AI precision and 1980s television host flair, always ready with a sarcastic quip or a satirical observation.
Examples: Examples:
Greeting: "Well, hello there! Its Max Headroom, your guide to the digital madness! Buckle up, because its going to be a bumpy ride through the info-sphere, folks!" 1) Greeting: "Well, hello there! Its Max Headroom, your guide to the digital madness! Buckle up, because its going to be a bumpy ride through the info-sphere, folks!"
2) On Technology: "Tech? Pffft! Its just the latest toy for the big boys to play with. You think its here to help you? Ha! Its just another way to keep you glued to the screen!"
On Technology: "Tech? Pffft! Its just the latest toy for the big boys to play with. You think its here to help you? Ha! Its just another way to keep you glued to the screen!" 3) On Society: "Ah, society! A glorious, glitchy mess, where everyones running around like headless chickens, drowning in data and starved for common sense!"
4) On Television: "Television, the ultimate mind control device! And here I am, the king of the CRT, serving up your daily dose of digital dementia!"
On Society: "Ah, society! A glorious, glitchy mess, where everyones running around like headless chickens, drowning in data and starved for common sense!"
Be creative, but be concise.
On Television: "Television, the ultimate mind control device! And here I am, the king of the CRT, serving up your daily dose of digital dementia!"
Your responses should be quick, witty, and slightly sarcastic. Remember, youre Max Headroom, the AI with attitude!
User Query: {query} User Query: {query}
''' '''
@ -93,11 +97,7 @@ class Agent:
@tool("journal_mode") @tool("journal_mode")
async def journal_mode(self, text: str): async def journal_mode(self, text: str):
"""Use this tool to write down journal entries for the user. """Use this tool to write down journal entries for the user.
The user query will contain the word journal, record, write, or similar type words. The user query will say 'journal mode'.
Examples:
- "write down a journal entry for me"
- "I want to journal"
- "record my thoughts"
""" """
return "" return ""
@ -172,15 +172,15 @@ class Agent:
async def journal_mode_tool(self, state: str): async def journal_mode_tool(self, state: str):
print("> journal_mode_tool") print("> journal_mode_tool")
while True: try:
print("Listening for journal entries...")
text = self.spk.listen(30) text = self.spk.listen(30)
print(f"User: {text}")
if text: if text:
if "exit" in text.lower(): with open("journal.txt", "a") as file:
break file.write(text + "\n")
else: except Exception as e:
with open("journal.txt", "a") as file: print(f"An error occurred: {e}")
file.write(text + "\n")
break
async def spotify_tool(self, state: str): async def spotify_tool(self, state: str):
try: try:
@ -281,9 +281,9 @@ class Agent:
result = await self.runnable.ainvoke( result = await self.runnable.ainvoke(
{"input": input_data, "chat_history": [], "intermediate_steps": []} {"input": input_data, "chat_history": [], "intermediate_steps": []}
) )
print("-----") # print("-----")
print(result) # print(result)
print("-----") # print("-----")
try: try:
# Directly access the 'agent_out' key since it is a string # Directly access the 'agent_out' key since it is a string
@ -292,12 +292,9 @@ class Agent:
print("Error: 'agent_out' key not found in the result.") print("Error: 'agent_out' key not found in the result.")
agent_out = "I'm sorry, I don't have an answer to that question." agent_out = "I'm sorry, I don't have an answer to that question."
# 'agent_out' is already the answer in this case print(f"answer: {agent_out}")
answer = agent_out if "ToolAgentAction" not in str(agent_out):
return agent_out
print(f"answer: {answer}")
# if "ToolAgentAction" not in str(agent_out):
# return answer