ndc8
commited on
Commit
·
04d695c
1
Parent(s):
2cd680b
Fix: Update to valid HuggingFace model and fix deprecation warnings
Browse files- Changed model from 'gemma-3n-E4B-it-GGUF' to 'microsoft/DialoGPT-medium'
- Fixed deprecated 'use_auth_token' parameter to 'token'
- Updated test file to use the correct model name
- backend_service.py +3 -3
- test_hf_api.py +23 -0
backend_service.py
CHANGED
@@ -75,7 +75,7 @@ class ChatMessage(BaseModel):
|
|
75 |
return v
|
76 |
|
77 |
class ChatCompletionRequest(BaseModel):
|
78 |
-
model: str = Field(default="
|
79 |
messages: List[ChatMessage] = Field(..., description="List of messages in the conversation")
|
80 |
max_tokens: Optional[int] = Field(default=512, ge=1, le=2048, description="Maximum tokens to generate")
|
81 |
temperature: Optional[float] = Field(default=0.7, ge=0.0, le=2.0, description="Sampling temperature")
|
@@ -124,7 +124,7 @@ class CompletionRequest(BaseModel):
|
|
124 |
# Global variables for model management
|
125 |
inference_client: Optional[InferenceClient] = None
|
126 |
image_text_pipeline = None # type: ignore
|
127 |
-
current_model = "
|
128 |
vision_model = "Salesforce/blip-image-captioning-base" # Working model for image captioning
|
129 |
tokenizer = None
|
130 |
|
@@ -198,7 +198,7 @@ async def lifespan(app: FastAPI):
|
|
198 |
if hf_token:
|
199 |
tokenizer = AutoTokenizer.from_pretrained(
|
200 |
current_model,
|
201 |
-
|
202 |
) # type: ignore
|
203 |
else:
|
204 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
75 |
return v
|
76 |
|
77 |
class ChatCompletionRequest(BaseModel):
|
78 |
+
model: str = Field(default="microsoft/DialoGPT-medium", description="The model to use for completion")
|
79 |
messages: List[ChatMessage] = Field(..., description="List of messages in the conversation")
|
80 |
max_tokens: Optional[int] = Field(default=512, ge=1, le=2048, description="Maximum tokens to generate")
|
81 |
temperature: Optional[float] = Field(default=0.7, ge=0.0, le=2.0, description="Sampling temperature")
|
|
|
124 |
# Global variables for model management
|
125 |
inference_client: Optional[InferenceClient] = None
|
126 |
image_text_pipeline = None # type: ignore
|
127 |
+
current_model = "microsoft/DialoGPT-medium" # Valid HuggingFace model for chat
|
128 |
vision_model = "Salesforce/blip-image-captioning-base" # Working model for image captioning
|
129 |
tokenizer = None
|
130 |
|
|
|
198 |
if hf_token:
|
199 |
tokenizer = AutoTokenizer.from_pretrained(
|
200 |
current_model,
|
201 |
+
token=hf_token
|
202 |
) # type: ignore
|
203 |
else:
|
204 |
tokenizer = AutoTokenizer.from_pretrained(
|
test_hf_api.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
# Hugging Face Space API endpoint
|
4 |
+
API_URL = "https://cong182-firstai.hf.space/v1/chat/completions"
|
5 |
+
|
6 |
+
# Example payload for OpenAI-compatible chat completion
|
7 |
+
payload = {
|
8 |
+
"model": "microsoft/DialoGPT-medium",
|
9 |
+
"messages": [
|
10 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
11 |
+
{"role": "user", "content": "Hello, who won the world cup in 2018?"}
|
12 |
+
],
|
13 |
+
"max_tokens": 64,
|
14 |
+
"temperature": 0.7
|
15 |
+
}
|
16 |
+
|
17 |
+
try:
|
18 |
+
response = requests.post(API_URL, json=payload, timeout=30)
|
19 |
+
response.raise_for_status()
|
20 |
+
print("Status:", response.status_code)
|
21 |
+
print("Response:", response.json())
|
22 |
+
except Exception as e:
|
23 |
+
print("Error during API call:", e)
|