Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,11 @@ from openai import AsyncOpenAI
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
async def generate_ai_response(prompt: str, model: str):
|
| 9 |
-
# Configuration for unofficial GitHub AI endpoint
|
| 10 |
token = os.getenv("GITHUB_TOKEN")
|
| 11 |
if not token:
|
| 12 |
raise HTTPException(status_code=500, detail="GitHub token not configured")
|
| 13 |
|
| 14 |
endpoint = "https://models.github.ai/inference"
|
| 15 |
-
|
| 16 |
client = AsyncOpenAI(base_url=endpoint, api_key=token)
|
| 17 |
|
| 18 |
try:
|
|
@@ -33,12 +31,15 @@ async def generate_ai_response(prompt: str, model: str):
|
|
| 33 |
|
| 34 |
except Exception as err:
|
| 35 |
yield f"Error: {str(err)}"
|
| 36 |
-
raise HTTPException(status_code=500, detail="AI generation failed")
|
| 37 |
|
| 38 |
@app.post("/generate")
|
| 39 |
-
async def generate_response(
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
return StreamingResponse(
|
| 44 |
generate_ai_response(prompt, model),
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
async def generate_ai_response(prompt: str, model: str):
|
|
|
|
| 9 |
token = os.getenv("GITHUB_TOKEN")
|
| 10 |
if not token:
|
| 11 |
raise HTTPException(status_code=500, detail="GitHub token not configured")
|
| 12 |
|
| 13 |
endpoint = "https://models.github.ai/inference"
|
|
|
|
| 14 |
client = AsyncOpenAI(base_url=endpoint, api_key=token)
|
| 15 |
|
| 16 |
try:
|
|
|
|
| 31 |
|
| 32 |
except Exception as err:
|
| 33 |
yield f"Error: {str(err)}"
|
| 34 |
+
raise HTTPException(status_code=500, detail=f"AI generation failed: {str(err)}")
|
| 35 |
|
| 36 |
@app.post("/generate")
|
| 37 |
+
async def generate_response(
|
| 38 |
+
prompt: str = Query(...),
|
| 39 |
+
model: str = Query(...)
|
| 40 |
+
):
|
| 41 |
+
if not prompt or not model:
|
| 42 |
+
raise HTTPException(status_code=400, detail="Prompt and model must be provided")
|
| 43 |
|
| 44 |
return StreamingResponse(
|
| 45 |
generate_ai_response(prompt, model),
|