mirror of
https://github.com/katanemo/plano.git
synced 2026-04-26 09:16:24 +02:00
move demo functions out of model_server (#67)
* pending * remove * fix docker build
This commit is contained in:
parent
ca5c9e4824
commit
31f26ef7ac
9 changed files with 122 additions and 50 deletions
16
demos/function_calling/api_server/.vscode/launch.json
vendored
Normal file
16
demos/function_calling/api_server/.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "function-calling api server",
|
||||
"cwd": "${workspaceFolder}/app",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"module": "uvicorn",
|
||||
"args": ["main:app","--reload", "--port", "8001"],
|
||||
}
|
||||
]
|
||||
}
|
||||
19
demos/function_calling/api_server/Dockerfile
Normal file
19
demos/function_calling/api_server/Dockerfile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
FROM python:3 AS base
|
||||
|
||||
FROM base AS builder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY requirements.txt /src/
|
||||
RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt
|
||||
|
||||
COPY . /src
|
||||
|
||||
FROM python:3-slim AS output
|
||||
|
||||
COPY --from=builder /runtime /usr/local
|
||||
|
||||
COPY /app /app
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
58
demos/function_calling/api_server/app/main.py
Normal file
58
demos/function_calling/api_server/app/main.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import random
|
||||
from fastapi import FastAPI, Response
|
||||
from datetime import datetime, date, timedelta, timezone
|
||||
import logging
|
||||
from pydantic import BaseModel
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/healthz")
|
||||
async def healthz():
|
||||
return {
|
||||
"status": "ok"
|
||||
}
|
||||
|
||||
class WeatherRequest(BaseModel):
|
||||
city: str
|
||||
|
||||
|
||||
@app.post("/weather")
|
||||
async def weather(req: WeatherRequest, res: Response):
|
||||
|
||||
weather_forecast = {
|
||||
"city": req.city,
|
||||
"temperature": [],
|
||||
"unit": "F",
|
||||
}
|
||||
for i in range(7):
|
||||
min_temp = random.randrange(50,90)
|
||||
max_temp = random.randrange(min_temp+5, min_temp+20)
|
||||
weather_forecast["temperature"].append({
|
||||
"date": str(date.today() + timedelta(days=i)),
|
||||
"temperature": {
|
||||
"min": min_temp,
|
||||
"max": max_temp
|
||||
}
|
||||
})
|
||||
|
||||
return weather_forecast
|
||||
|
||||
|
||||
class InsuranceClaimDetailsRequest(BaseModel):
|
||||
policy_number: str
|
||||
|
||||
@app.post("/insurance_claim_details")
|
||||
async def insurance_claim_details(req: InsuranceClaimDetailsRequest, res: Response):
|
||||
|
||||
claim_details = {
|
||||
"policy_number": req.policy_number,
|
||||
"claim_status": "Approved",
|
||||
"claim_amount": random.randrange(1000, 10000),
|
||||
"claim_date": str(date.today() - timedelta(days=random.randrange(1, 30))),
|
||||
"claim_reason": "Car Accident",
|
||||
}
|
||||
|
||||
return claim_details
|
||||
2
demos/function_calling/api_server/requirements.txt
Normal file
2
demos/function_calling/api_server/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fastapi
|
||||
uvicorn
|
||||
Loading…
Add table
Add a link
Reference in a new issue