|
1 | 1 | import asyncio |
2 | 2 |
|
3 | 3 | from typing import Any |
| 4 | +from langchain.schema import AIMessage, HumanMessage |
4 | 5 | from langchain.pydantic_v1 import BaseModel |
| 6 | +from codeboxapi.schema import CodeBoxStatus |
5 | 7 |
|
6 | 8 |
|
7 | 9 | class File(BaseModel): |
@@ -87,3 +89,54 @@ def __str__(self) -> str: |
87 | 89 |
|
88 | 90 | def __repr__(self) -> str: |
89 | 91 | return f"File(name={self.name})" |
| 92 | + |
| 93 | + |
| 94 | +class CodeInput(BaseModel): |
| 95 | + code: str |
| 96 | + |
| 97 | + |
| 98 | +class FileInput(BaseModel): |
| 99 | + filename: str |
| 100 | + |
| 101 | + |
| 102 | +class UserRequest(HumanMessage): |
| 103 | + files: list[File] = [] |
| 104 | + |
| 105 | + def __str__(self) -> str: |
| 106 | + return str(self.content) |
| 107 | + |
| 108 | + def __repr__(self) -> str: |
| 109 | + return f"UserRequest(content={self.content}, files={self.files})" |
| 110 | + |
| 111 | + |
| 112 | +class CodeInterpreterResponse(AIMessage): |
| 113 | + """ |
| 114 | + Response from the code interpreter agent. |
| 115 | +
|
| 116 | + files: list of files to be sent to the user (File ) |
| 117 | + code_log: list[tuple[str, str]] = [] |
| 118 | + """ |
| 119 | + |
| 120 | + files: list[File] = [] |
| 121 | + code_log: list[tuple[str, str]] = [] |
| 122 | + |
| 123 | + def show(self) -> None: |
| 124 | + print("AI: ", self.content) |
| 125 | + for file in self.files: |
| 126 | + print("File: ", file.name) |
| 127 | + file.show_image() |
| 128 | + |
| 129 | + def __str__(self) -> str: |
| 130 | + return str(self.content) |
| 131 | + |
| 132 | + def __repr__(self) -> str: |
| 133 | + return f"CodeInterpreterResponse(content={self.content}, files={self.files})" |
| 134 | + |
| 135 | + |
| 136 | +class SessionStatus(CodeBoxStatus): |
| 137 | + @classmethod |
| 138 | + def from_codebox_status(cls, cbs: CodeBoxStatus) -> "SessionStatus": |
| 139 | + return cls(status=cbs.status) |
| 140 | + |
| 141 | + def __repr__(self) -> str: |
| 142 | + return f"<SessionStatus status={self.status}>" |
0 commit comments