Dominic commited on
Commit
e1776b1
·
unverified ·
1 Parent(s): 1e04ad2
codeinterpreterapi/config.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseSettings
2
+ from dotenv import load_dotenv
3
+
4
+ # .env file
5
+ load_dotenv()
6
+
7
+
8
+ class CodeInterpreterAPISettings(BaseSettings):
9
+ """
10
+ CodeInterpreter API Config
11
+ """
12
+ CODEBOX_API_KEY: str = None
13
+ CODEBOX_VERBOSE: bool = False
14
+
15
+ OPENAI_API_KEY: str = ""
16
+
17
+
18
+ settings = CodeInterpreterAPISettings()
codeinterpreterapi/schemas.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from promptkit import AssistantResponse
2
+ from promptkit.schema import UserMessage
3
+
4
+
5
+ class UserRequest(UserMessage):
6
+ text: str = ""
7
+ files: list[dict[str, bytes]] = []
8
+
9
+
10
+ class CodeInterpreterResponse(AssistantResponse):
11
+ files: list[dict[str, bytes]] = []
12
+ final_code: str = ""
13
+ final_output: str = ""
codeinterpreterapi/session.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from codeboxapi import CodeBox
2
+ from promptkit import ChatSession
3
+
4
+
5
+ class CodeInterpreterSession():
6
+
7
+ def __init__(self):
8
+ self.chatgpt = ChatSession()
9
+ self.codebox = CodeBox()
10
+
11
+ async def _init(self):
12
+ await self.codebox.start()
13
+
14
+ async def _close(self):
15
+ await self.codebox.stop()
16
+
17
+ async def code_decision(self, user_request: str):
18
+ # check if the user wants something that requires python code execution
19
+ # if yes, return "code"
20
+ # if no, return "default"
21
+ pass
22
+
23
+ async def generate_response(self, text: str, files: list[dict[str, bytes]]): # list of "file_name" x "file_content"
24
+ """ Generate a Code Interpreter response based on the user's input."""
25
+ if self.code_decision() == "code":
26
+ pass
27
+ # plan what code to write (potentially multiple steps)
28
+ # code = chatgpt.run(code generation template)
29
+ # codebox.run(code)
30
+ # on error
31
+ # check if package is required
32
+ # if yes, install package
33
+ # ask for analysis if the error can be fixed
34
+ # if yes, continue code generation
35
+ # if no, return AssistantResponse
36
+ # on success
37
+ # check if to output files to the user
38
+ # if yes, return AssistantResponse with files
39
+ # write a response based on the code execution
40
+ # return AssistantResponse
41
+ else:
42
+ pass
43
+ # return AssistantResponse
44
+ pass
45
+
46
+
pyproject.toml ADDED
File without changes