Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,18 +1,8 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
-
app = FastAPI(
|
| 7 |
-
|
| 8 |
-
# Enable CORS
|
| 9 |
-
app.add_middleware(
|
| 10 |
-
CORSMiddleware,
|
| 11 |
-
allow_origins=["*"],
|
| 12 |
-
allow_credentials=True,
|
| 13 |
-
allow_methods=["*"],
|
| 14 |
-
allow_headers=["*"],
|
| 15 |
-
)
|
| 16 |
|
| 17 |
class AgenticRequest(BaseModel):
|
| 18 |
task: str
|
|
@@ -21,87 +11,25 @@ class AgenticRequest(BaseModel):
|
|
| 21 |
@app.get("/")
|
| 22 |
async def root():
|
| 23 |
return {
|
| 24 |
-
"message": "AI Model Runner
|
| 25 |
"version": "1.0.0",
|
| 26 |
"status": "running",
|
| 27 |
-
"
|
| 28 |
}
|
| 29 |
|
| 30 |
@app.get("/health")
|
| 31 |
-
async def
|
| 32 |
-
return {"status": "
|
| 33 |
-
|
| 34 |
-
@app.get("/models")
|
| 35 |
-
async def get_models():
|
| 36 |
-
return {
|
| 37 |
-
"models": [
|
| 38 |
-
{
|
| 39 |
-
"name": "agentic-model",
|
| 40 |
-
"status": "loaded",
|
| 41 |
-
"description": "Agentic model with exceptional tool use and Interleaved Thinking"
|
| 42 |
-
}
|
| 43 |
-
]
|
| 44 |
-
}
|
| 45 |
|
| 46 |
@app.post("/agentic")
|
| 47 |
-
async def
|
| 48 |
-
# Simulate Interleaved Thinking process
|
| 49 |
-
task_lower = request.task.lower()
|
| 50 |
-
reasoning_details = ""
|
| 51 |
-
tool_calls = []
|
| 52 |
-
content = ""
|
| 53 |
-
|
| 54 |
-
if "search" in task_lower or "find" in task_lower:
|
| 55 |
-
reasoning_details = "I need to search for information to complete this task. Let me use the search_web tool."
|
| 56 |
-
tool_calls = [{
|
| 57 |
-
"id": f"call_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 58 |
-
"function": {
|
| 59 |
-
"name": "search_web",
|
| 60 |
-
"arguments": f'{{"query": "{request.task}"}}'
|
| 61 |
-
}
|
| 62 |
-
}]
|
| 63 |
-
content = f"I've analyzed your task: '{request.task}'. I'm searching for relevant information."
|
| 64 |
-
elif "code" in task_lower:
|
| 65 |
-
reasoning_details = "This task requires code analysis. I need to analyze the code structure."
|
| 66 |
-
tool_calls = [{
|
| 67 |
-
"id": f"call_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 68 |
-
"function": {
|
| 69 |
-
"name": "analyze_code",
|
| 70 |
-
"arguments": f'{{"code": "{request.context}", "task": "comprehensive_analysis"}}'
|
| 71 |
-
}
|
| 72 |
-
}]
|
| 73 |
-
content = f"Analyzing your code-related task: '{request.task}'."
|
| 74 |
-
elif "weather" in task_lower:
|
| 75 |
-
location = request.context or "current location"
|
| 76 |
-
reasoning_details = "This task requires weather information. I need to get current weather data."
|
| 77 |
-
tool_calls = [{
|
| 78 |
-
"id": f"call_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 79 |
-
"function": {
|
| 80 |
-
"name": "get_weather",
|
| 81 |
-
"arguments": f'{{"location": "{location}"}}'
|
| 82 |
-
}
|
| 83 |
-
}]
|
| 84 |
-
content = f"Getting weather information for: '{request.task}'."
|
| 85 |
-
elif any(char.isdigit() for char in task_lower) and ("+" in task_lower or "-" in task_lower or "*" in task_lower):
|
| 86 |
-
reasoning_details = "This is a mathematical computation task. I need to evaluate the expression."
|
| 87 |
-
tool_calls = [{
|
| 88 |
-
"id": f"call_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 89 |
-
"function": {
|
| 90 |
-
"name": "math_calc",
|
| 91 |
-
"arguments": f'{{"expression": "{request.task}"}}'
|
| 92 |
-
}
|
| 93 |
-
}]
|
| 94 |
-
content = f"Processing mathematical task: '{request.task}'."
|
| 95 |
-
else:
|
| 96 |
-
reasoning_details = "This is a complex reasoning task requiring systematic analysis."
|
| 97 |
-
content = f"Working on your task: '{request.task}'. Applying systematic reasoning."
|
| 98 |
-
|
| 99 |
return {
|
| 100 |
-
"
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
|
|
|
| 105 |
}
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class AgenticRequest(BaseModel):
|
| 8 |
task: str
|
|
|
|
| 11 |
@app.get("/")
|
| 12 |
async def root():
|
| 13 |
return {
|
| 14 |
+
"message": "AI Model Runner",
|
| 15 |
"version": "1.0.0",
|
| 16 |
"status": "running",
|
| 17 |
+
"agentic_endpoint": "/agentic"
|
| 18 |
}
|
| 19 |
|
| 20 |
@app.get("/health")
|
| 21 |
+
async def health():
|
| 22 |
+
return {"status": "ok", "time": datetime.now().isoformat()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
@app.post("/agentic")
|
| 25 |
+
async def agentic(request: AgenticRequest):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return {
|
| 27 |
+
"task": request.task,
|
| 28 |
+
"context": request.context,
|
| 29 |
+
"reasoning": "Task analyzed successfully",
|
| 30 |
+
"tool_calls": [],
|
| 31 |
+
"content": f"Processed task: {request.task}",
|
| 32 |
+
"status": "success"
|
| 33 |
}
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|