XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix HuggingChat provider

d2810cb8
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +10 -29
Modified g4f/Provider/needs_auth/hf/HuggingChat.py +10 -29
@@ -202,35 +202,16 @@ class HuggingChat(AsyncAuthedProvider, ProviderModelMixin):
202 202
203 203 @classmethod
204 204 def fetch_message_id(cls, session: Session, conversation_id: str):
205 # Get the data response and parse it properly
206 response = session.get(f'{cls.url}/conversation/{conversation_id}/__data.json?x-sveltekit-invalidated=11')
205 response = session.get(
206 f"{cls.url}/api/v2/conversations/{conversation_id}"
207 )
207 208 raise_for_status(response)
208 209
209 # Split the response content by newlines and parse each line as JSON
210 210 try:
211 json_data = None
212 for line in response.text.split('\n'):
213 if line.strip():
214 try:
215 parsed = json.loads(line)
216 if isinstance(parsed, dict) and "nodes" in parsed:
217 json_data = parsed
218 break
219 except json.JSONDecodeError:
220 continue
221
222 if not json_data:
223 raise RuntimeError("Failed to parse response data")
224
225 if json_data["nodes"][-1]["type"] == "error":
226 if json_data["nodes"][-1]["status"] == 403:
227 raise MissingAuthError(json_data["nodes"][-1]["error"]["message"])
228 raise ResponseError(json.dumps(json_data["nodes"][-1]))
229
230 data = json_data["nodes"][1]["data"]
231 keys = data[data[0]["messages"]]
232 message_keys = data[keys[-1]]
233 return data[message_keys["id"]]
234
235 except (KeyError, IndexError, TypeError) as e:
236 raise RuntimeError(f"Failed to extract message ID: {str(e)}")
211 data = response.json()['json']
212 except json.JSONDecodeError as e:
213 debug.error(f"Failed to decode JSON: {e}")
214 return None
215
216 messages_data_list = data.get("messages", [])
217 return messages_data_list[-1]['id'] if messages_data_list else None