Spaces:
Paused
Paused
File size: 1,167 Bytes
6330947 |
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 40 41 |
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)
|