Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,6 +51,47 @@ def gen(prompt):
|
|
| 51 |
print(f"GenAI Error: {e}")
|
| 52 |
raise HTTPException(status_code=500, detail="AI Generation Failed")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
@app.get("/", response_class=HTMLResponse)
|
| 55 |
async def read_items():
|
| 56 |
html_content = """
|
|
|
|
| 51 |
print(f"GenAI Error: {e}")
|
| 52 |
raise HTTPException(status_code=500, detail="AI Generation Failed")
|
| 53 |
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
AGENTS_MD_CONTENT = """# AI Prompt Optimizer Agent
|
| 58 |
+
|
| 59 |
+
An asynchronous FastAPI microservice that optimizes input prompts using the Google GenAI SDK (`gemma-4-26b-a4b-it`).
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
## API Endpoints
|
| 64 |
+
|
| 65 |
+
### Optimize Prompt
|
| 66 |
+
|
| 67 |
+
* **Endpoint:** `/optimize`
|
| 68 |
+
* **Method:** `POST`
|
| 69 |
+
* **Content-Type:** `application/json`
|
| 70 |
+
|
| 71 |
+
#### Request Body
|
| 72 |
+
```json
|
| 73 |
+
{"input_prompt": "Your text or prompt to optimize here."}
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
#### Response Body
|
| 78 |
+
|
| 79 |
+
```json
|
| 80 |
+
{"optimized_text": "The optimized result string."}
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
+
|
| 86 |
+
## Error Handling
|
| 87 |
+
|
| 88 |
+
* **500 Internal Server Error:** Raised with detail `AI Generation Failed` if the GenAI SDK encounters communication issues, API limits, or parsing exceptions."""
|
| 89 |
+
|
| 90 |
+
@app.get("/agents.md")
|
| 91 |
+
async def get_agents_md():
|
| 92 |
+
return Response(content=AGENTS_MD_CONTENT, media_type="text/markdown")
|
| 93 |
+
|
| 94 |
+
|
| 95 |
@app.get("/", response_class=HTMLResponse)
|
| 96 |
async def read_items():
|
| 97 |
html_content = """
|