Created
June 8, 2025 08:48
-
-
Save jongan69/1d2a8f5d8885612976c2bbdb33e0069b to your computer and use it in GitHub Desktop.
goose api wrapper
This file contains hidden or 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
from fastapi import FastAPI, HTTPException | |
from pydantic import BaseModel | |
import subprocess | |
app = FastAPI() | |
class GooseInput(BaseModel): | |
instructions: str | |
session_name: str = "api-session" | |
@app.post("/run-goose/") | |
def run_goose(input: GooseInput): | |
try: | |
# Save instructions to a file | |
instruction_file = "/tmp/goose_input.txt" | |
with open(instruction_file, "w") as f: | |
f.write(input.instructions) | |
# Run goose with instructions | |
result = subprocess.run( | |
["goose", "run", "--name", input.session_name, "-i", instruction_file], | |
capture_output=True, | |
text=True | |
) | |
if result.returncode != 0: | |
raise HTTPException(status_code=500, detail=result.stderr) | |
return { | |
"stdout": result.stdout, | |
"stderr": result.stderr, | |
"returncode": result.returncode | |
} | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment