Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,16 @@ from openai import AsyncOpenAI
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
# Define a request model for the prompt and required model name
|
| 10 |
class GenerateRequest(BaseModel):
|
| 11 |
prompt: str
|
| 12 |
model: str # Model is required, no default
|
| 13 |
|
| 14 |
async def generate_ai_response(prompt: str, model: str):
|
| 15 |
-
# Configuration for unofficial GitHub AI endpoint
|
| 16 |
token = os.getenv("GITHUB_TOKEN")
|
| 17 |
if not token:
|
| 18 |
raise HTTPException(status_code=500, detail="GitHub token not configured")
|
| 19 |
|
| 20 |
endpoint = "https://models.github.ai/inference"
|
| 21 |
-
|
| 22 |
client = AsyncOpenAI(base_url=endpoint, api_key=token)
|
| 23 |
|
| 24 |
try:
|
|
@@ -45,7 +42,6 @@ async def generate_ai_response(prompt: str, model: str):
|
|
| 45 |
async def generate_response(request: GenerateRequest):
|
| 46 |
if not request.prompt:
|
| 47 |
raise HTTPException(status_code=400, detail="Prompt cannot be empty")
|
| 48 |
-
|
| 49 |
if not request.model:
|
| 50 |
raise HTTPException(status_code=400, detail="Model must be specified")
|
| 51 |
|
|
@@ -55,4 +51,4 @@ async def generate_response(request: GenerateRequest):
|
|
| 55 |
)
|
| 56 |
|
| 57 |
def get_app():
|
| 58 |
-
return app
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 9 |
class GenerateRequest(BaseModel):
|
| 10 |
prompt: str
|
| 11 |
model: str # Model is required, no default
|
| 12 |
|
| 13 |
async def generate_ai_response(prompt: str, model: str):
|
|
|
|
| 14 |
token = os.getenv("GITHUB_TOKEN")
|
| 15 |
if not token:
|
| 16 |
raise HTTPException(status_code=500, detail="GitHub token not configured")
|
| 17 |
|
| 18 |
endpoint = "https://models.github.ai/inference"
|
|
|
|
| 19 |
client = AsyncOpenAI(base_url=endpoint, api_key=token)
|
| 20 |
|
| 21 |
try:
|
|
|
|
| 42 |
async def generate_response(request: GenerateRequest):
|
| 43 |
if not request.prompt:
|
| 44 |
raise HTTPException(status_code=400, detail="Prompt cannot be empty")
|
|
|
|
| 45 |
if not request.model:
|
| 46 |
raise HTTPException(status_code=400, detail="Model must be specified")
|
| 47 |
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
def get_app():
|
| 54 |
+
return app
|