-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into changelong-generation
- Loading branch information
Showing
4 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
import tempfile | ||
|
||
from fastapi import FastAPI | ||
|
||
from codegen.runner.models.apis import ( | ||
RUN_ON_STRING_ENDPOINT, | ||
GetRunOnStringRequest, | ||
GetRunOnStringResult, | ||
) | ||
from codegen.runner.sandbox.executor import SandboxExecutor | ||
from codegen.sdk.codebase.factory.get_session import get_codebase_session | ||
from codegen.sdk.enums import ProgrammingLanguage | ||
from codegen.shared.compilation.string_to_code import create_execute_function_from_codeblock | ||
|
||
logger = logging.getLogger(__name__) | ||
app = FastAPI() | ||
|
||
|
||
@app.post(RUN_ON_STRING_ENDPOINT) | ||
async def run_on_string(request: GetRunOnStringRequest) -> GetRunOnStringResult: | ||
logger.info(f"====[ run_on_string ]====\n> Codemod source: {request.codemod_source}\n> Input: {request.files}\n> Language: {request.language}\n") | ||
language = ProgrammingLanguage(request.language.upper()) | ||
with get_codebase_session(tmpdir=tempfile.mkdtemp(), files=request.files, programming_language=language) as codebase: | ||
executor = SandboxExecutor(codebase) | ||
code_to_exec = create_execute_function_from_codeblock(codeblock=request.codemod_source) | ||
result = await executor.execute(code_to_exec) | ||
logger.info(f"Result: {result}") | ||
return GetRunOnStringResult(result=result) |