Set python interpret sandbox url via environment variable

This commit is contained in:
Debanjum Singh Solanky 2024-10-10 00:28:51 -07:00
parent 2dc5804571
commit 9e7025b330

View file

@ -2,6 +2,7 @@ import asyncio
import datetime import datetime
import json import json
import logging import logging
import os
from typing import Any, Callable, List, Optional from typing import Any, Callable, List, Optional
import aiohttp import aiohttp
@ -21,6 +22,9 @@ from khoj.utils.rawconfig import LocationData
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
SANDBOX_URL = os.getenv("KHOJ_TERRARIUM_URL", "http://localhost:8080")
async def run_code( async def run_code(
query: str, query: str,
conversation_history: dict, conversation_history: dict,
@ -29,7 +33,7 @@ async def run_code(
send_status_func: Optional[Callable] = None, send_status_func: Optional[Callable] = None,
uploaded_image_url: str = None, uploaded_image_url: str = None,
agent: Agent = None, agent: Agent = None,
sandbox_url: str = "http://localhost:8080", sandbox_url: str = SANDBOX_URL,
): ):
# Generate Code # Generate Code
if send_status_func: if send_status_func:
@ -104,7 +108,7 @@ async def generate_python_code(
return codes return codes
async def execute_sandboxed_python(code: str, sandbox_url: str = "http://localhost:8080") -> dict[str, Any]: async def execute_sandboxed_python(code: str, sandbox_url: str = SANDBOX_URL) -> dict[str, Any]:
""" """
Takes code to run as a string and calls the terrarium API to execute it. Takes code to run as a string and calls the terrarium API to execute it.
Returns the result of the code execution as a dictionary. Returns the result of the code execution as a dictionary.