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

XFEstudio/gpt4free

Support Image Upload in HuggingChat

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

代码差异

1 个文件 +11 -3
Modified g4f/Provider/needs_auth/HuggingChat.py +11 -3
@@ -4,6 +4,7 @@ import json
4 4 import re
5 5 import os
6 6 import requests
7 import base64
7 8 from typing import AsyncIterator
8 9
9 10 try:
@@ -14,8 +15,9 @@ except ImportError:
14 15
15 16 from ..base_provider import ProviderModelMixin, AsyncAuthedProvider, AuthResult
16 17 from ..helper import format_prompt
17 from ...typing import AsyncResult, Messages, Cookies
18 from ...typing import AsyncResult, Messages, Cookies, ImagesType
18 19 from ...errors import MissingRequirementsError, MissingAuthError, ResponseError
20 from ...image import to_bytes
19 21 from ...requests import get_args_from_nodriver, DEFAULT_HEADERS
20 22 from ...requests.raise_for_status import raise_for_status
21 23 from ...providers.response import JsonConversation, ImageResponse, Sources, TitleGeneration, Reasoning, RequestLogin
@@ -116,6 +118,7 @@ class HuggingChat(AsyncAuthedProvider, ProviderModelMixin):
116 118 messages: Messages,
117 119 auth_result: AuthResult,
118 120 prompt: str = None,
121 images: ImagesType = None,
119 122 return_conversation: bool = False,
120 123 conversation: Conversation = None,
121 124 web_search: bool = False,
@@ -172,6 +175,13 @@ class HuggingChat(AsyncAuthedProvider, ProviderModelMixin):
172 175
173 176 data = CurlMime()
174 177 data.addpart('data', data=json.dumps(settings, separators=(',', ':')))
178 if images is not None:
179 for image, filename in images:
180 data.addpart(
181 "files",
182 filename=f"base64;{filename}",
183 data=base64.b64encode(to_bytes(image))
184 )
175 185
176 186 response = session.post(
177 187 f'https://huggingface.co/chat/conversation/{conversationId}',
@@ -207,8 +217,6 @@ class HuggingChat(AsyncAuthedProvider, ProviderModelMixin):
207 217 yield TitleGeneration(line["title"])
208 218 elif line["type"] == "reasoning":
209 219 yield Reasoning(line.get("token"), line.get("status"))
210 else:
211 pass #print(line)
212 220
213 221 if sources is not None:
214 222 yield sources