watasu-code-interpreter 0.1.48__tar.gz → 0.1.49__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/PKG-INFO +1 -1
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/pyproject.toml +1 -1
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/models.py +42 -16
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/.gitignore +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/README.md +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/__init__.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/charts.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/code_interpreter_async.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/code_interpreter_sync.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/constants.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/exceptions.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/main.py +0 -0
- {watasu_code_interpreter-0.1.48 → watasu_code_interpreter-0.1.49}/src/watasu_code_interpreter/py.typed +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json as jsonlib
|
|
3
4
|
import time
|
|
4
5
|
from dataclasses import dataclass, field
|
|
5
6
|
from typing import Any, Callable, Dict, List, Optional, TypeVar
|
|
@@ -25,12 +26,12 @@ class OutputMessage:
|
|
|
25
26
|
def __str__(self) -> str:
|
|
26
27
|
return self.line
|
|
27
28
|
|
|
28
|
-
def to_json(self) ->
|
|
29
|
-
return {
|
|
29
|
+
def to_json(self) -> str:
|
|
30
|
+
return jsonlib.dumps({
|
|
30
31
|
"line": self.line,
|
|
31
32
|
"timestamp": self.timestamp,
|
|
32
33
|
"error": self.error,
|
|
33
|
-
}
|
|
34
|
+
})
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
@dataclass
|
|
@@ -40,11 +41,11 @@ class Logs:
|
|
|
40
41
|
stdout: List[OutputMessage] = field(default_factory=list)
|
|
41
42
|
stderr: List[OutputMessage] = field(default_factory=list)
|
|
42
43
|
|
|
43
|
-
def to_json(self) ->
|
|
44
|
-
return {
|
|
45
|
-
"stdout": [message
|
|
46
|
-
"stderr": [message
|
|
47
|
-
}
|
|
44
|
+
def to_json(self) -> str:
|
|
45
|
+
return jsonlib.dumps({
|
|
46
|
+
"stdout": [_message_line(message) for message in self.stdout],
|
|
47
|
+
"stderr": [_message_line(message) for message in self.stderr],
|
|
48
|
+
})
|
|
48
49
|
|
|
49
50
|
|
|
50
51
|
@dataclass
|
|
@@ -55,12 +56,12 @@ class ExecutionError:
|
|
|
55
56
|
value: str
|
|
56
57
|
traceback: str
|
|
57
58
|
|
|
58
|
-
def to_json(self) ->
|
|
59
|
-
return {
|
|
59
|
+
def to_json(self) -> str:
|
|
60
|
+
return jsonlib.dumps({
|
|
60
61
|
"name": self.name,
|
|
61
62
|
"value": self.value,
|
|
62
63
|
"traceback": self.traceback,
|
|
63
|
-
}
|
|
64
|
+
})
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
@dataclass
|
|
@@ -181,13 +182,12 @@ class Execution:
|
|
|
181
182
|
return result.text
|
|
182
183
|
return None
|
|
183
184
|
|
|
184
|
-
def to_json(self) ->
|
|
185
|
-
return {
|
|
186
|
-
"results":
|
|
185
|
+
def to_json(self) -> str:
|
|
186
|
+
return jsonlib.dumps({
|
|
187
|
+
"results": serialize_results(self.results),
|
|
187
188
|
"logs": self.logs.to_json(),
|
|
188
189
|
"error": self.error.to_json() if self.error else None,
|
|
189
|
-
|
|
190
|
-
}
|
|
190
|
+
})
|
|
191
191
|
|
|
192
192
|
|
|
193
193
|
@dataclass(init=False)
|
|
@@ -217,6 +217,32 @@ class Context:
|
|
|
217
217
|
"cwd": self.cwd,
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
@classmethod
|
|
221
|
+
def from_json(cls, data: Dict[str, str]):
|
|
222
|
+
return cls(
|
|
223
|
+
context_id=data.get("id"),
|
|
224
|
+
language=data.get("language"),
|
|
225
|
+
cwd=data.get("cwd"),
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def serialize_results(results: List[Result]) -> List[Dict[str, Any]]:
|
|
230
|
+
serialized = []
|
|
231
|
+
for result in results:
|
|
232
|
+
item = {}
|
|
233
|
+
for key in result.formats():
|
|
234
|
+
if key == "chart" and result.chart is not None:
|
|
235
|
+
item[key] = result.chart.to_dict()
|
|
236
|
+
else:
|
|
237
|
+
item[key] = result[key]
|
|
238
|
+
item["text"] = result.text
|
|
239
|
+
serialized.append(item)
|
|
240
|
+
return serialized
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _message_line(message: Any) -> str:
|
|
244
|
+
return str(message.line) if hasattr(message, "line") else str(message)
|
|
245
|
+
|
|
220
246
|
|
|
221
247
|
def execution_from_api(payload: Dict[str, Any]) -> Execution:
|
|
222
248
|
execution = payload.get("execution") or payload
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|