File size: 1,132 Bytes
f3ac685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
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"}