add support for default target (#111)

* add support for default target

* add more fixes
This commit is contained in:
Adil Hafeez 2024-10-02 20:43:16 -07:00 committed by GitHub
parent c8d0dbec26
commit 1b57a49c9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 215 additions and 88 deletions

View file

@ -16,4 +16,4 @@ COPY --from=builder /runtime /usr/local
COPY /app /app
WORKDIR /app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--log-level", "info"]

View file

@ -1,12 +1,13 @@
import json
import random
from fastapi import FastAPI, Response
from datetime import datetime, date, timedelta, timezone
import logging
from pydantic import BaseModel
import pytz
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
logger = logging.getLogger('uvicorn.error')
logger.setLevel(logging.INFO)
app = FastAPI()
@ -58,18 +59,28 @@ async def insurance_claim_details(req: InsuranceClaimDetailsRequest, res: Respon
return claim_details
@app.get("/current_time")
async def current_time(timezone: str):
tz = None
try:
timezone.strip('"')
tz = pytz.timezone(timezone)
except pytz.exceptions.UnknownTimeZoneError:
return {
"error": "Invalid timezone: {}".format(timezone)
}
current_time = datetime.now(tz)
return {
"timezone": timezone,
"current_time": current_time.strftime("%Y-%m-%d %H:%M:%S %Z")
}
class DefaultTargetRequest(BaseModel):
arch_messages: list
@app.post("/default_target")
async def default_target(req: DefaultTargetRequest, res: Response):
logger.info(f"Received arch_messages: {req.arch_messages}")
resp = {
"choices": [
{
"message": {
"role": "assistant",
"content": "hello world from api server"
},
"finish_reason": "completed",
"index": 0
}
],
"model": "api_server",
"usage": {
"completion_tokens": 0
}
}
logger.info(f"sending response: {json.dumps(resp)}")
return resp

View file

@ -1,3 +1,3 @@
fastapi
uvicorn
pytz
pyyaml

View file

@ -47,21 +47,6 @@ prompt_targets:
- Use farenheight for temperature
- Use miles per hour for wind speed
- name: system_time
description: This function provides the current system time.
parameters:
- name: timezone
description: The city for which the weather forecast is requested.
default: US/Pacific
type: string
endpoint:
name: api_server
path: /current_time
system_prompt: |
You are a helpful system time provider. Use system time data that is provided to you. Please following following guidelines when responding to user queries:
- Use 12 hour time format
- Use AM/PM for time
- name: insurance_claim_details
description: This function resolver provides insurance claim details for a given policy number.
parameters:
@ -80,6 +65,18 @@ prompt_targets:
You are a helpful insurance claim details provider. Use insurance claim data that is provided to you. Please following following guidelines when responding to user queries:
- Use policy number to retrieve insurance claim details
- name: default_target
default: true
description: This is the default target for all unmatched prompts.
endpoint:
name: api_server
path: /default_target
system_prompt: |
You are a helpful assistant. Use the information that is provided to you.
# if it is set to false arch will send response that it received from this prompt target to the user
# if true arch will forward the response to the default LLM
auto_llm_dispatch_on_response: true
ratelimits:
- provider: gpt-3.5-turbo
selector: