Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code interpreter response format + grooming #47

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions oracles/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ async def _call_function(function_call: FunctionCall, semaphore: Semaphore):
python_interpreter_result = await python_interpreter_use_case.execute(
formatted_input
)
response = python_interpreter_result.stdout
error_message = python_interpreter_result.stderr
response = python_interpreter_result.output
error_message = python_interpreter_result.error
else:
response = ""
error_message = f"Unknown function '{function_call.function_type}'"
Expand Down
4 changes: 2 additions & 2 deletions oracles/src/domain/tools/code_interpreter/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

@dataclass
class PythonInterpreterResult:
stdout: str
stderr: str
output: str
error: str
exit_code: int
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import re
import json
import base64
import aiohttp
import settings
from typing import Optional
from src.domain.tools.code_interpreter.entities import PythonInterpreterResult


async def _interpret_code(code: str) -> Optional[PythonInterpreterResult]:
async def _interpret_code(code: str) -> PythonInterpreterResult:
try:
async with aiohttp.ClientSession() as session:
async with session.post(
Expand All @@ -23,21 +23,16 @@ async def _interpret_code(code: str) -> Optional[PythonInterpreterResult]:
) as response:
response.raise_for_status()
data = await response.json()
stdout = base64.b64decode(data["stdoutBasesixtyfour"]).decode() if data["stdoutBasesixtyfour"] else ""
stderr = base64.b64decode(data["stderrBasesixtyfour"]).decode() if data["stderrBasesixtyfour"] else ""
output = json.dumps({"stdout": stdout, "stderr": stderr})
return PythonInterpreterResult(
stdout=(
base64.b64decode(data["stdoutBasesixtyfour"]).decode()
if data["stdoutBasesixtyfour"]
else ""
),
stderr=(
base64.b64decode(data["stderrBasesixtyfour"]).decode()
if data["stderrBasesixtyfour"]
else ""
),
output=output,
error="",
exit_code=data["exitCode"],
)
except Exception as e:
return PythonInterpreterResult(stdout="", stderr=str(e), exit_code=1)
return PythonInterpreterResult(output="", error=str(e), exit_code=1)


async def _strip_markdown_code(md_string: str) -> str:
Expand All @@ -46,7 +41,7 @@ async def _strip_markdown_code(md_string: str) -> str:
return stripped_string


async def execute(code: str) -> Optional[PythonInterpreterResult]:
async def execute(code: str) -> PythonInterpreterResult:
clean_code = await _strip_markdown_code(code)
return await _interpret_code(clean_code)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading