feat: Add NaliiaBot API
This commit is contained in:
0
src/naliiabotapi/__init__.py
Normal file
0
src/naliiabotapi/__init__.py
Normal file
16
src/naliiabotapi/api/dependencies.py
Normal file
16
src/naliiabotapi/api/dependencies.py
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
import os
|
||||
from src.naliiabot.bot.agent.agent import Agent
|
||||
from src.naliiabot.bot.factories.llm_factory import LLMFactory
|
||||
|
||||
MODEL_NAME = os.getenv("LLM_MODEL", "anthropic")
|
||||
|
||||
def get_agent():
|
||||
"""
|
||||
Dependency function to get an instance of the Agent class.
|
||||
|
||||
Returns:
|
||||
Agent: An instance of the Agent class.
|
||||
"""
|
||||
model = LLMFactory(MODEL_NAME).get_model()
|
||||
return Agent(model=model)
|
||||
0
src/naliiabotapi/api/v1/__init__.py
Normal file
0
src/naliiabotapi/api/v1/__init__.py
Normal file
0
src/naliiabotapi/api/v1/endpoints/__init__.py
Normal file
0
src/naliiabotapi/api/v1/endpoints/__init__.py
Normal file
22
src/naliiabotapi/api/v1/endpoints/chat.py
Normal file
22
src/naliiabotapi/api/v1/endpoints/chat.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from ...dependencies import get_agent
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/chat")
|
||||
def chat(messages: dict, agent = Depends(get_agent)):
|
||||
"""
|
||||
Simulate a chat response based on the input message.
|
||||
|
||||
Args:
|
||||
message (str): The input message from the user.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the response message.
|
||||
"""
|
||||
|
||||
messages = [HumanMessage(content=messages["messages"])]
|
||||
response_message = agent.invoke({"messages": messages})
|
||||
|
||||
return {"response": response_message}
|
||||
18
src/naliiabotapi/main.py
Normal file
18
src/naliiabotapi/main.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import FastAPI
|
||||
from src.naliiabotapi.api.v1.endpoints.chat import router as chat_router
|
||||
|
||||
app = FastAPI(
|
||||
title="NaliiaBot API",
|
||||
description="API for NaliiaBot, a chatbot that provides customer service and related topics.",
|
||||
version="1.0.0"
|
||||
)
|
||||
|
||||
app.include_router(chat_router)
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Hello": "World"}
|
||||
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user