jin-e / app.py
hamxahbhattii's picture
added Jine
6330947
raw
history blame
1.17 kB
from fastapi import FastAPI, HTTPException, Query
# Import the Jine class and other necessary modules
from jine import Jine # Replace 'your_module_name' with the actual module name
from pydantic import BaseModel
# Load your environment variables
from dotenv import load_dotenv
import os
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
DATA_DIRECTORY = os.getenv("DATA_DIRECTORY")
VECTOR_STORE_DIRECTORY = os.getenv("VECTOR_STORE_DIRCTORY")
VECTOR_STORE_CHECK = os.getenv("VECTOR_STORE_CHECK")
DEBUG = os.getenv("DEBUG")
# Initialize Jine
jine = Jine(OPENAI_API_KEY, VECTOR_STORE_DIRECTORY, VECTOR_STORE_CHECK, DATA_DIRECTORY, DEBUG)
jine.load_model()
# Create a FastAPI app
app = FastAPI()
# Define a request model
class ChatRequest(BaseModel):
user_question: str
# Define a response model
class ChatResponse(BaseModel):
user_question: str
chatbot_response: str
# Define the chatbot endpoint
@app.post("/chatbot/")
def chat_with_bot(request: ChatRequest):
user_question = request.user_question
chatbot_response = jine.chat(user_question)
return ChatResponse(user_question=user_question, chatbot_response=chatbot_response)