|
from skills.skill import Skill |
|
import openai |
|
|
|
|
|
class CallBabyagi(Skill): |
|
name = 'call_babyagi' |
|
description = 'A skill that rewrites a task description into an objective, and sends it to itself (an autonomous agent) to complete. Helpful for research.' |
|
api_keys_required = [['openai']] |
|
|
|
def __init__(self, api_keys, main_loop_function): |
|
super().__init__(api_keys, main_loop_function) |
|
|
|
def execute(self, params, dependent_task_outputs, objective): |
|
|
|
new_objective = self.generate_new_objective(params) |
|
|
|
LOAD_SKILLS = ['web_search','text_completion'] |
|
|
|
result = self.main_loop_function(new_objective, LOAD_SKILLS, self.api_keys, False) |
|
|
|
|
|
return result |
|
|
|
|
|
def generate_new_objective(self, task_description): |
|
prompt = f"You are an AI assistant tasked with rewriting the following task description into an objective, and remove any mention of call_babyagi: {task_description}\nObjective:" |
|
|
|
messages = [ |
|
{"role": "user", "content": prompt} |
|
] |
|
response = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo-16k", |
|
messages=messages, |
|
temperature=0.2, |
|
max_tokens=1500, |
|
top_p=1, |
|
frequency_penalty=0, |
|
presence_penalty=0 |
|
) |
|
|
|
return response.choices[0].message['content'].strip() |
|
|