Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ import json
|
|
6 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
7 |
print("Access token loaded.")
|
8 |
|
9 |
-
# Initialize the HF Inference Client
|
10 |
-
client = InferenceClient(token=ACCESS_TOKEN)
|
11 |
-
print("Hugging Face Inference Client initialized.")
|
12 |
-
|
13 |
def respond(
|
14 |
message,
|
15 |
history: list[tuple[str, str]],
|
@@ -30,6 +26,11 @@ def respond(
|
|
30 |
print(f"Selected model (custom_model): {custom_model}")
|
31 |
print(f"Selected provider: {provider}")
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
# Convert seed to None if -1 (meaning random)
|
34 |
if seed == -1:
|
35 |
seed = None
|
@@ -72,14 +73,14 @@ def respond(
|
|
72 |
if seed is not None:
|
73 |
parameters["seed"] = seed
|
74 |
|
75 |
-
# Use the InferenceClient for making the request
|
76 |
try:
|
77 |
# Create a generator for the streaming response
|
|
|
78 |
stream = client.chat_completion(
|
79 |
model=model_to_use,
|
80 |
messages=messages,
|
81 |
stream=True,
|
82 |
-
provider=provider, # Use the selected provider
|
83 |
**parameters # Pass all other parameters
|
84 |
)
|
85 |
|
|
|
6 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
7 |
print("Access token loaded.")
|
8 |
|
|
|
|
|
|
|
|
|
9 |
def respond(
|
10 |
message,
|
11 |
history: list[tuple[str, str]],
|
|
|
26 |
print(f"Selected model (custom_model): {custom_model}")
|
27 |
print(f"Selected provider: {provider}")
|
28 |
|
29 |
+
# Initialize the Inference Client with the provider
|
30 |
+
# Provider is specified during initialization, not in the method call
|
31 |
+
client = InferenceClient(token=ACCESS_TOKEN, provider=provider)
|
32 |
+
print(f"Hugging Face Inference Client initialized with {provider} provider.")
|
33 |
+
|
34 |
# Convert seed to None if -1 (meaning random)
|
35 |
if seed == -1:
|
36 |
seed = None
|
|
|
73 |
if seed is not None:
|
74 |
parameters["seed"] = seed
|
75 |
|
76 |
+
# Use the InferenceClient for making the request
|
77 |
try:
|
78 |
# Create a generator for the streaming response
|
79 |
+
# The provider is already set when initializing the client
|
80 |
stream = client.chat_completion(
|
81 |
model=model_to_use,
|
82 |
messages=messages,
|
83 |
stream=True,
|
|
|
84 |
**parameters # Pass all other parameters
|
85 |
)
|
86 |
|