artecnosomatic Claude Opus 4.6 commited on
Commit
3fdc5b7
·
1 Parent(s): 417a25d

Switch to OpenAI-compatible chat API with Qwen2.5-7B

Browse files

Old HF Inference API format (inputs/parameters) is dead. New router
uses OpenAI-compatible /v1/chat/completions with messages array.
Mistral-7B no longer available on free tier; switch to Qwen2.5-7B
which is recommended and warm. v0.9.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +15 -16
  2. templates/index.html +1 -1
app.py CHANGED
@@ -10,7 +10,7 @@ app = Flask(__name__, template_folder=os.path.join(BASE_DIR, 'templates'))
10
 
11
  # --- CONFIGURATION ---
12
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
13
- LLM_MODEL = "mistralai/Mistral-7B-Instruct-v0.2"
14
 
15
  # British female voice — sharp RP diction
16
  TTS_VOICE = "en-GB-SoniaNeural"
@@ -53,27 +53,26 @@ def chat():
53
  if not user_msg:
54
  return jsonify({"response": "Darling, silence is only for those who have nothing to say."})
55
 
56
- prompt = f"""<s>[INST] {SYSTEM_PROMPT}
57
-
58
- User: {user_msg} [/INST]"""
59
-
60
  try:
61
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
 
 
 
62
  payload = {
63
- "inputs": prompt,
64
- "parameters": {
65
- "max_new_tokens": 100,
66
- "temperature": 0.9,
67
- "top_p": 0.95,
68
- "return_full_text": False
69
- }
 
70
  }
71
 
72
- response = requests.post(f"https://router.huggingface.co/hf-inference/models/{LLM_MODEL}", headers=headers, json=payload)
73
 
74
  if response.status_code == 200:
75
- ai_msg = response.json()[0]['generated_text'].strip()
76
- ai_msg = ai_msg.replace("Assistant:", "").strip()
77
  return jsonify({"response": ai_msg})
78
  else:
79
  err = response.text[:200]
 
10
 
11
  # --- CONFIGURATION ---
12
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
13
+ LLM_MODEL = "Qwen/Qwen2.5-7B-Instruct-1M"
14
 
15
  # British female voice — sharp RP diction
16
  TTS_VOICE = "en-GB-SoniaNeural"
 
53
  if not user_msg:
54
  return jsonify({"response": "Darling, silence is only for those who have nothing to say."})
55
 
 
 
 
 
56
  try:
57
+ headers = {
58
+ "Authorization": f"Bearer {HF_TOKEN}",
59
+ "Content-Type": "application/json"
60
+ }
61
  payload = {
62
+ "model": LLM_MODEL,
63
+ "messages": [
64
+ {"role": "system", "content": SYSTEM_PROMPT},
65
+ {"role": "user", "content": user_msg}
66
+ ],
67
+ "max_tokens": 150,
68
+ "temperature": 0.9,
69
+ "top_p": 0.95
70
  }
71
 
72
+ response = requests.post("https://router.huggingface.co/v1/chat/completions", headers=headers, json=payload)
73
 
74
  if response.status_code == 200:
75
+ ai_msg = response.json()["choices"][0]["message"]["content"].strip()
 
76
  return jsonify({"response": ai_msg})
77
  else:
78
  err = response.text[:200]
templates/index.html CHANGED
@@ -97,7 +97,7 @@
97
  <input type="text" id="userInput" placeholder="Type here..." autocomplete="off">
98
  <button id="sendBtn">SEND</button>
99
  </div>
100
- <div id="status" class="status">Ready. <span style="float:right;color:#444;">v0.7</span></div>
101
  <audio id="player"></audio>
102
  </div>
103
  </div>
 
97
  <input type="text" id="userInput" placeholder="Type here..." autocomplete="off">
98
  <button id="sendBtn">SEND</button>
99
  </div>
100
+ <div id="status" class="status">Ready. <span style="float:right;color:#444;">v0.9</span></div>
101
  <audio id="player"></audio>
102
  </div>
103
  </div>