-
Notifications
You must be signed in to change notification settings - Fork 46
Description
from taskgen import *
from langchain_google_vertexai import ChatVertexAI
chat_model = ChatVertexAI(model_name="chat-bison", temperature=0)
def llm(system_prompt: str, user_prompt: str) -> str:
# Generate response using `invoke` method
response = chat_model.invoke(
input=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
]
)
return response.content # Return the content of the response
Verify that llm function is working
llm(system_prompt = 'You are a CLASSIFIER to classify the sentiment of a sentence',
user_prompt = 'It is a hot and sunny day')
my_agent = Agent('Helpful assistant', 'You are a generalist agent', llm = llm)
my_agent.status()
my_agent.reset()
output = my_agent.run('Give me 5 words rhyming with cool, and then make a 4-sentence poem using them')
error :
An exception occurred: The key "###Observation###" is not present in json output. Ensure that you include this key in the json output.
Current invalid json format: { Observation: The user has requested five words that rhyme with "cool" and a four-sentence poem using those words.
Thoughts: To complete this task, I will need to generate five words that rhyme with "cool" and then use those words to create a four-sentence poem.
Current Subtask: Generate five words that rhyme with "cool".
Equipped Function Name: use_llm}
An exception occurred: The key "###Observation###" is not present in json output. Ensure that you include this key in the json output.
Current invalid json format: { Observation: The user has requested five words that rhyme with "cool" and a four-sentence poem using those words.
KeyError Traceback (most recent call last)
Cell In[12], line 26
23 my_agent.status()
25 my_agent.reset()
---> 26 output = my_agent.run('Give me 5 words rhyming with cool, and then make a 4-sentence poem using them')
File /opt/conda/lib/python3.10/site-packages/taskgen/agent.py:538, in Agent.run(self, task, overall_task, num_subtasks)
534 else:
535 # otherwise do the task
536 for i in range(num_subtasks):
537 # Determine next subtask, or if task is complete. Always execute if it is the first subtask
--> 538 subtask, function_name, function_params = self.get_next_subtask()
539 if function_name == 'end_task':
540 self.task_completed = True
File /opt/conda/lib/python3.10/site-packages/taskgen/agent.py:421, in Agent.get_next_subtask(self, task)
410 res = self.query(query = f'''{background_info}{rag_info}\nBased on everything before, provide suitable Observation and Thoughts, and also generate the Current Subtask and the corresponding Equipped Function Name to complete a part of Assigned Task.
411 You are only given the Assigned Task from User with no further inputs. Only focus on the Assigned Task and do not do more than required.
412 End Task if Assigned Task is completed.''',
(...)
417 provide_function_list = True,
418 task = task)
420 if self.verbose:
--> 421 print(colored(f"Observation: {res['Observation']}", 'black', attrs = ['bold']))
422 print(colored(f"Thoughts: {res['Thoughts']}", 'green', attrs = ['bold']))
424 # end task if equipped function is incorrect
KeyError: 'Observation'