File size: 1,204 Bytes
a5957ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# api.py
import openai
import logging

# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

class AutoAPI:
    def __init__(self, api_key, ai_name, ai_role, top_5_goals):
        self.api_key = api_key
        self.ai_name = ai_name
        self.ai_role = ai_role
        self.top_5_goals = top_5_goals
        openai.api_key = self.api_key

    def infer_tasks(self, description):
        prompt = f"Based on the role '{self.ai_role}' and the description '{description}', infer five delegated tasks that encompass all tasks and subtasks related to the deployment of the project."
        try:
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",  # or the model you are using
                messages=[{"role": "user", "content": prompt}],
                max_tokens=150
            )
            tasks = response['choices'][0]['message']['content']
            return tasks.split('\n')  # Assuming tasks are returned as a newline-separated string
        except Exception as e:
            logger.error("Error inferring tasks: %s", str(e))
            return ["Error inferring tasks. Please check the API key and input."]