abdullahalioo commited on
Commit
585fc5c
·
verified ·
1 Parent(s): 3314587

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
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(prompt: str = Query(...), model: str = Query("openai/gpt-4.1-mini")):
40
- if not prompt:
41
- raise HTTPException(status_code=400, detail="Prompt cannot be empty")
 
 
 
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),