Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ def _secret(key: str, fallback: str = "") -> str:
|
|
16 |
def respond(
|
17 |
message: str,
|
18 |
history: list[dict[str, str]],
|
19 |
-
model_name: str,
|
20 |
):
|
21 |
"""
|
22 |
Generate a response using OpenRouter API via OpenAI client.
|
@@ -35,10 +35,20 @@ def respond(
|
|
35 |
)
|
36 |
|
37 |
# 3οΈβ£ Initialize OpenAI client with OpenRouter configuration
|
|
|
|
|
|
|
|
|
|
|
38 |
client = OpenAI(
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# 4οΈβ£ Build the message list for the chat completion
|
44 |
messages = []
|
@@ -48,7 +58,7 @@ def respond(
|
|
48 |
# 5οΈβ£ Stream the response back to the UI
|
49 |
response = ""
|
50 |
stream = client.chat.completions.create(
|
51 |
-
model=model_name,
|
52 |
messages=messages,
|
53 |
max_tokens=8096,
|
54 |
stream=True
|
@@ -61,12 +71,12 @@ def respond(
|
|
61 |
yield response
|
62 |
|
63 |
|
64 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
65 |
-
# List of models available through OpenRouter
|
66 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
67 |
-
AVAILABLE_MODELS = [
|
68 |
-
"@preset/precise-chat-agent"
|
69 |
-
]
|
70 |
|
71 |
# ----------------------------------------------------------------------
|
72 |
# UI β the systemβprompt textbox has been removed.
|
|
|
16 |
def respond(
|
17 |
message: str,
|
18 |
history: list[dict[str, str]],
|
19 |
+
# model_name: str,
|
20 |
):
|
21 |
"""
|
22 |
Generate a response using OpenRouter API via OpenAI client.
|
|
|
35 |
)
|
36 |
|
37 |
# 3οΈβ£ Initialize OpenAI client with OpenRouter configuration
|
38 |
+
# client = OpenAI(
|
39 |
+
# base_url="https://openrouter.ai/api/v1",
|
40 |
+
# api_key=openrouter_api_key,
|
41 |
+
# )
|
42 |
+
|
43 |
client = OpenAI(
|
44 |
+
base_url="https://openrouter.ai/api/v1",
|
45 |
+
api_key=openrouter_api_key,
|
46 |
+
default_headers={
|
47 |
+
# "HTTP-Referer": "<YOUR_SITE_URL>", # Optional. Set your site URL for tracking.
|
48 |
+
"X-Title": "hf_precise", # Optional. Set your app name for tracking.
|
49 |
+
"X-OpenRouter-Preset": "@preset/precise-chat-agent" # <<< The crucial line
|
50 |
+
},
|
51 |
+
)
|
52 |
|
53 |
# 4οΈβ£ Build the message list for the chat completion
|
54 |
messages = []
|
|
|
58 |
# 5οΈβ£ Stream the response back to the UI
|
59 |
response = ""
|
60 |
stream = client.chat.completions.create(
|
61 |
+
# model=model_name,
|
62 |
messages=messages,
|
63 |
max_tokens=8096,
|
64 |
stream=True
|
|
|
71 |
yield response
|
72 |
|
73 |
|
74 |
+
# # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
75 |
+
# # List of models available through OpenRouter
|
76 |
+
# # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
77 |
+
# AVAILABLE_MODELS = [
|
78 |
+
# "@preset/precise-chat-agent"
|
79 |
+
# ]
|
80 |
|
81 |
# ----------------------------------------------------------------------
|
82 |
# UI β the systemβprompt textbox has been removed.
|