acecalisto3 commited on
Commit
a5957ee
·
verified ·
1 Parent(s): 7cfcffc

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +29 -0
api.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # api.py
2
+ import openai
3
+ import logging
4
+
5
+ # Setup logging
6
+ logging.basicConfig(level=logging.INFO)
7
+ logger = logging.getLogger(__name__)
8
+
9
+ class AutoAPI:
10
+ def __init__(self, api_key, ai_name, ai_role, top_5_goals):
11
+ self.api_key = api_key
12
+ self.ai_name = ai_name
13
+ self.ai_role = ai_role
14
+ self.top_5_goals = top_5_goals
15
+ openai.api_key = self.api_key
16
+
17
+ def infer_tasks(self, description):
18
+ 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."
19
+ try:
20
+ response = openai.ChatCompletion.create(
21
+ model="gpt-3.5-turbo", # or the model you are using
22
+ messages=[{"role": "user", "content": prompt}],
23
+ max_tokens=150
24
+ )
25
+ tasks = response['choices'][0]['message']['content']
26
+ return tasks.split('\n') # Assuming tasks are returned as a newline-separated string
27
+ except Exception as e:
28
+ logger.error("Error inferring tasks: %s", str(e))
29
+ return ["Error inferring tasks. Please check the API key and input."]