Update apis/chat_api.py
Browse files- apis/chat_api.py +12 -12
apis/chat_api.py
CHANGED
|
@@ -116,17 +116,6 @@ class ChatAPIApp:
|
|
| 116 |
model_name: str = Field(..., example="bert-base-uncased")
|
| 117 |
api_key: str = Field(..., example="your_hf_api_key_here")
|
| 118 |
|
| 119 |
-
async def chat_embedding(texts, model_name, api_key):
|
| 120 |
-
api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_name}"
|
| 121 |
-
headers = {"Authorization": f"Bearer {api_key}"}
|
| 122 |
-
response = requests.post(api_url, headers=headers, json={"inputs": texts})
|
| 123 |
-
result = response.json()
|
| 124 |
-
if isinstance(result, list) and len(result) > 0 and isinstance(result[0], list):
|
| 125 |
-
return result
|
| 126 |
-
elif "error" in result:
|
| 127 |
-
raise RuntimeError("The model is currently loading, please re-run the query.")
|
| 128 |
-
else:
|
| 129 |
-
raise RuntimeError("Unexpected response format.")
|
| 130 |
|
| 131 |
class ChatCompletionsPostItem(BaseModel):
|
| 132 |
model: str = Field(
|
|
@@ -186,7 +175,18 @@ class ChatAPIApp:
|
|
| 186 |
data_response = streamer.chat_return_dict(stream_response)
|
| 187 |
return data_response
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
async def embedding(request: QueryRequest):
|
| 192 |
try:
|
|
|
|
| 116 |
model_name: str = Field(..., example="bert-base-uncased")
|
| 117 |
api_key: str = Field(..., example="your_hf_api_key_here")
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
class ChatCompletionsPostItem(BaseModel):
|
| 121 |
model: str = Field(
|
|
|
|
| 175 |
data_response = streamer.chat_return_dict(stream_response)
|
| 176 |
return data_response
|
| 177 |
|
| 178 |
+
async def chat_embedding(texts, model_name, api_key):
|
| 179 |
+
api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_name}"
|
| 180 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
| 181 |
+
response = requests.post(api_url, headers=headers, json={"inputs": texts})
|
| 182 |
+
result = response.json()
|
| 183 |
+
if isinstance(result, list) and len(result) > 0 and isinstance(result[0], list):
|
| 184 |
+
return result
|
| 185 |
+
elif "error" in result:
|
| 186 |
+
raise RuntimeError("The model is currently loading, please re-run the query.")
|
| 187 |
+
else:
|
| 188 |
+
raise RuntimeError("Unexpected response format.")
|
| 189 |
+
|
| 190 |
|
| 191 |
async def embedding(request: QueryRequest):
|
| 192 |
try:
|