File size: 1,017 Bytes
0f43f8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
from skills.skill import Skill
import openai

class Drawing(Skill):
    name = 'drawing'
    description = "A tool that draws on an HTML canvas using OpenAI."
    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):
        if not self.valid:
            return
        
        task_prompt = f"Do a detailed HTML canvas drawing of the user request: {params}. Start with <canvas> and end with </canvas>. Only provide code.:"
      
        messages = [
            {"role": "user", "content": task_prompt}
        ]
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo-16k",
            messages=messages,
            temperature=0.4,
            max_tokens=4000,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0
        )
    
        return "\n\n"+response.choices[0].message['content'].strip()