Final_Assignment_Template / mistral_hf_wrapper.py
FD900's picture
Update mistral_hf_wrapper.py
a57fcec verified
raw
history blame
603 Bytes
import os
import requests
API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
API_TOKEN = os.getenv("HF_TOKEN")
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}
def query_mistral(system_prompt: str, user_prompt: str) -> str:
"""Query the Mistral model hosted on Hugging Face."""
prompt = f"<s>[INST] {system_prompt.strip()}\n\n{user_prompt.strip()} [/INST]"
response = requests.post(
API_URL,
headers=headers,
json={"inputs": prompt}
)
response.raise_for_status()
return response.json()["generated_text"].strip()