File size: 1,631 Bytes
e1776b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from codeboxapi import CodeBox
from promptkit import ChatSession


class CodeInterpreterSession():
    
    def __init__(self):
        self.chatgpt = ChatSession()
        self.codebox = CodeBox()
    
    async def _init(self):
        await self.codebox.start()
        
    async def _close(self):
        await self.codebox.stop()
    
    async def code_decision(self, user_request: str):
        # check if the user wants something that requires python code execution
        # if yes, return "code"
        # if no, return "default"
        pass
    
    async def generate_response(self, text: str, files: list[dict[str, bytes]]):  # list of "file_name" x "file_content"
        """ Generate a Code Interpreter response based on the user's input."""
        if self.code_decision() == "code":
            pass
            # plan what code to write (potentially multiple steps)
            # code = chatgpt.run(code generation template)
            # codebox.run(code)
                # on error
                    # check if package is required
                        # if yes, install package
                    # ask for analysis if the error can be fixed
                        # if yes, continue code generation
                        # if no, return AssistantResponse
                # on success
                    # check if to output files to the user
                        # if yes, return AssistantResponse with files
            # write a response based on the code execution
            # return AssistantResponse
        else:
            pass
            # return AssistantResponse
        pass