From bf0e7164016e95714946209fb9943e470c880fec Mon Sep 17 00:00:00 2001 From: DSri01 Date: Sun, 20 Oct 2024 20:05:20 +0800 Subject: [PATCH] Fixed Windows Docker Code File Not found Issue --- llm_sandbox/docker.py | 34 ++++++++++++++++++---------------- pyproject.toml | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/llm_sandbox/docker.py b/llm_sandbox/docker.py index 2b1b972..0f0704b 100644 --- a/llm_sandbox/docker.py +++ b/llm_sandbox/docker.py @@ -2,6 +2,7 @@ import os import docker import tarfile +import tempfile from typing import List, Optional, Union from docker.models.images import Image @@ -163,27 +164,28 @@ def run(self, code: str, libraries: Optional[List] = None) -> ConsoleOutput: for library in libraries: command = get_libraries_installation_command(self.lang, library) _ = self.execute_command(command) + with tempfile.TemporaryDirectory() as directory_name: - code_file = f"/tmp/code.{get_code_file_extension(self.lang)}" - if self.lang == SupportedLanguage.GO: - code_dest_file = "/example/code.go" - else: - code_dest_file = code_file + code_file = os.path.join(directory_name,f"code.{get_code_file_extension(self.lang)}") + if self.lang == SupportedLanguage.GO: + code_dest_file = "/example/code.go" + else: + code_dest_file = f"/tmp/code.{get_code_file_extension(self.lang)}"# code_file - with open(code_file, "w") as f: - f.write(code) + with open(code_file, "w") as f: + f.write(code) - self.copy_to_runtime(code_file, code_dest_file) + self.copy_to_runtime(code_file, code_dest_file) - output = ConsoleOutput("") - commands = get_code_execution_command(self.lang, code_dest_file) - for command in commands: - if self.lang == SupportedLanguage.GO: - output = self.execute_command(command, workdir="/example") - else: - output = self.execute_command(command) + output = ConsoleOutput("") + commands = get_code_execution_command(self.lang, code_dest_file) + for command in commands: + if self.lang == SupportedLanguage.GO: + output = self.execute_command(command, workdir="/example") + else: + output = self.execute_command(command) - return output + return output def copy_from_runtime(self, src: str, dest: str): if not self.container: diff --git a/pyproject.toml b/pyproject.toml index 3d59411..81b86d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "llm-sandbox" -version = "0.1.1" +version = "0.1.1-alpha" description = "Lightweight and portable LLM sandbox runtime (code interpreter) Python library" authors = ["Duy Huynh "] license = "MIT"