-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.py
More file actions
39 lines (30 loc) · 1.15 KB
/
backend.py
File metadata and controls
39 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pydantic import BaseModel
from typing import List
class RequestState(BaseModel):
model_name: str
model_provider: str
system_prompt: str
messages: List[str]
allow_search: bool
from fastapi import FastAPI
from ai_agent import get_response_from_ai_agent
ALLOWED_MODEL_NAMES=["llama-3.3-70b-versatile", "gpt-4o-mini", "llama3-70b-8192", "mixtral-8x7b-32768"]
app = FastAPI(title="LangGraph AI Agent")
@app.post("/chat")
def chat_endpoint(request: RequestState):
"""
API endpoint to interact with the chatbot using langgraph and search tools.
It dynamically selects the model specified in the request.
"""
if request.model_name not in ALLOWED_MODEL_NAMES:
return {"error": "Invalid model name. Please choose one of the following: " + ", ".join(ALLOWED_MODEL_NAMES)}
llm_id = request.model_name
query = request.messages
allow_search = request.allow_search
system_prompt = request.system_prompt
provider = request.model_provider
response = get_response_from_ai_agent(llm_id, query, allow_search, system_prompt, provider)
return response;
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=9999)