import os from fastapi import FastAPI from pydantic import BaseModel from openai import OpenAI app = FastAPI() # Initialize client client = OpenAI( base_url="https://router.huggingface.co/v1", api_key=os.getenv("HF_TOKEN"), ) # Your custom domain data CUSTOM_CONTEXT = """ You are an auto consultant. Use ONLY the information below to answer. If the answer is not in the context, say: 'I don't have this information.' Context: - We offer car buying advisory. - We help users choose cars based on EMI, budget, mileage. - We provide details about new launches. """ class Query(BaseModel): question: str @app.post("/ask") def ask_bot(payload: Query): response = client.chat.completions.create( model="meta-llama/Llama-3.1-8B-Instruct:novita", messages=[ {"role": "system", "content": CUSTOM_CONTEXT}, {"role": "user", "content": payload.question} ], ) answer = response.choices[0].message return { "question": payload.question, "answer": answer } @app.get("/") def root(): return {"status": "Auto Consultant Model Running"}