Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,107 +1,36 @@
|
|
| 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(title="AI
|
| 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
|
| 19 |
-
context: str = ""
|
| 20 |
|
| 21 |
@app.get("/")
|
| 22 |
async def root():
|
| 23 |
return {
|
| 24 |
-
"message": "AI
|
| 25 |
-
"version": "1.0.0",
|
| 26 |
"status": "running",
|
| 27 |
-
"
|
| 28 |
}
|
| 29 |
|
| 30 |
@app.get("/health")
|
| 31 |
-
async def
|
| 32 |
-
return {"status": "healthy"
|
| 33 |
|
| 34 |
-
@app.get("/
|
| 35 |
-
async def
|
| 36 |
return {
|
| 37 |
-
"
|
|
|
|
|
|
|
| 38 |
{
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
@app.post("/agentic")
|
| 47 |
-
async def agentic_endpoint(request: AgenticRequest):
|
| 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 |
-
"reasoning_details": reasoning_details,
|
| 101 |
-
"content": content,
|
| 102 |
-
"tool_calls": tool_calls,
|
| 103 |
"status": "success",
|
| 104 |
-
"thinking_process": "Interleaved thinking enabled
|
| 105 |
}
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
|
| 4 |
+
app = FastAPI(title="AI Agent", version="1.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
@app.get("/")
|
| 7 |
async def root():
|
| 8 |
return {
|
| 9 |
+
"message": "AI Agent Space",
|
|
|
|
| 10 |
"status": "running",
|
| 11 |
+
"timestamp": datetime.now().isoformat()
|
| 12 |
}
|
| 13 |
|
| 14 |
@app.get("/health")
|
| 15 |
+
async def health():
|
| 16 |
+
return {"status": "healthy"}
|
| 17 |
|
| 18 |
+
@app.get("/agentic")
|
| 19 |
+
async def agentic_test():
|
| 20 |
return {
|
| 21 |
+
"reasoning_details": "I am analyzing the task and determining the best approach.",
|
| 22 |
+
"content": "Agentic model is ready for tool use and interleaved thinking.",
|
| 23 |
+
"tool_calls": [
|
| 24 |
{
|
| 25 |
+
"id": "test_call_001",
|
| 26 |
+
"function": {
|
| 27 |
+
"name": "search_web",
|
| 28 |
+
"arguments": '{"query": "test search"}'
|
| 29 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"status": "success",
|
| 33 |
+
"thinking_process": "Interleaved thinking enabled"
|
| 34 |
}
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|