Spaces:
Sleeping
Sleeping
Download main.py from sumit63111/chat_bot_auto: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/sumit63111/chat_bot_auto/resolve/main/main.py
- Command line
-
hf download hf://spaces/sumit63111/chat_bot_auto/main.py
-
curl -L -o main.py https://huggingface.co/spaces/sumit63111/chat_bot_auto/resolve/main/main.py
1.13 kB
| 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 | |
| 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 | |
| } | |
| def root(): | |
| return {"status": "Auto Consultant Model Running"} | |