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

XFEstudio/gpt4free

Bugfix Bing.py - Resolved Issues with system prompt, Bing personalities and enabled all supported user requests

I used this repository (https://github.com/waylaidwanderer/node-chatgpt-api/) as a reference to fix all the bugs related to Bing "personality." I included all the required fields in the allowedMessageTypes and optionsSets (as well as sliceIds) to allow it to respond to any requests it actually supports. Will also finish the code to fully implement the image generation functionality.

21e56a1a
Luneye <73485421+Luneye@users.noreply.github.com>
提交于

代码差异

1 个文件 +45 -47
Modified g4f/Provider/Bing.py +45 -47
@@ -57,7 +57,7 @@ class Bing(AsyncGeneratorProvider):
57 57
58 58 def create_context(messages: Messages):
59 59 return "".join(
60 f"[{message['role']}](#message)\n{message['content']}\n\n"
60 f"[{message['role']}]" + ("(#message)" if message['role']!="system" else "(#additional_instructions)") + f"\n{message['content']}\n\n"
61 61 for message in messages
62 62 )
63 63
@@ -166,9 +166,9 @@ class Defaults:
166 166 "ActionRequest",
167 167 "Chat",
168 168 "Context",
169 "Disengaged",
169 # "Disengaged", unwanted
170 170 "Progress",
171 "AdsQuery",
171 # "AdsQuery", unwanted
172 172 "SemanticSerp",
173 173 "GenerateContentQuery",
174 174 "SearchQuery",
@@ -176,34 +176,21 @@ class Defaults:
176 176 # useless messages (such as "Analyzing images" or "Searching the web") while it's retrieving the AI response
177 177 # "InternalSearchQuery",
178 178 # "InternalSearchResult",
179 # Not entirely certain about these two, but these parameters may be used for real-time markdown rendering.
180 # Keeping them could potentially complicate the retrieval of the messages because link references written while
181 # the AI is responding would then be moved to the very end of its message.
182 # "RenderCardRequest",
179 "RenderCardRequest",
183 180 # "RenderContentRequest"
184 181 ]
185 182
186 183 sliceIds = [
187 "wrapuxslimt5",
188 "wrapalgo",
189 "wraptopalgo",
190 "st14",
191 "arankr1_1_9_9",
192 "0731ziv2s0",
193 "voiceall",
194 "1015onstblg",
195 "vsspec",
196 "cacdiscf",
197 "909ajcopus0",
198 "scpbfmob",
199 "rwt1",
200 "cacmuidarb",
201 "sappdlpt",
202 "917fluxv14",
203 "delaygc",
204 "remsaconn3p",
205 "splitcss3p",
206 "sydconfigoptt"
184 'abv2',
185 'srdicton',
186 'convcssclick',
187 'stylewv2',
188 'contctxp2tf',
189 '802fluxv1pc_a',
190 '806log2sphs0',
191 '727savemem',
192 '277teditgnds0',
193 '207hlthgrds0',
207 194 ]
208 195
209 196 location = {
@@ -248,19 +235,21 @@ class Defaults:
248 235 }
249 236
250 237 optionsSets = [
251 "nlu_direct_response_filter",
252 "deepleo",
253 "disable_emoji_spoken_text",
254 "responsible_ai_policy_235",
255 "enablemm",
256 "dv3sugg",
257 "iyxapbing",
258 "iycapbing",
259 "h3imaginative",
260 "clgalileo",
261 "gencontentv3",
262 "fluxv14",
263 "eredirecturl"
238 'nlu_direct_response_filter',
239 'deepleo',
240 'disable_emoji_spoken_text',
241 'responsible_ai_policy_235',
242 'enablemm',
243 'iyxapbing',
244 'iycapbing',
245 'gencontentv3',
246 'fluxsrtrunc',
247 'fluxtrunc',
248 'fluxv1',
249 'rai278',
250 'replaceurl',
251 'eredirecturl',
252 'nojbfedge'
264 253 ]
265 254
266 255 def format_message(msg: dict) -> str:
@@ -297,7 +286,7 @@ def build_image_upload_api_payload(image_bin: str, conversation: Conversation, t
297 286 )
298 287 return data, boundary
299 288
300 def is_data_uri_an_image(data_uri):
289 def is_data_uri_an_image(data_uri: str):
301 290 try:
302 291 # Check if the data URI starts with 'data:image' and contains an image format (e.g., jpeg, png, gif)
303 292 if not re.match(r'data:image/(\w+);base64,', data_uri):
@@ -310,7 +299,7 @@ def is_data_uri_an_image(data_uri):
310 299 except Exception as e:
311 300 raise e
312 301
313 def is_accepted_format(binary_data):
302 def is_accepted_format(binary_data: bytes) -> bool:
314 303 try:
315 304 check = False
316 305 if binary_data.startswith(b'\xFF\xD8\xFF'):
@@ -331,7 +320,7 @@ def is_accepted_format(binary_data):
331 320 except Exception as e:
332 321 raise e
333 322
334 def extract_data_uri(data_uri):
323 def extract_data_uri(data_uri: str) -> bytes:
335 324 try:
336 325 data = data_uri.split(",")[1]
337 326 data = base64.b64decode(data)
@@ -339,7 +328,7 @@ def extract_data_uri(data_uri):
339 328 except Exception as e:
340 329 raise e
341 330
342 def get_orientation(data: bytes):
331 def get_orientation(data: bytes) -> int:
343 332 try:
344 333 if data[:2] != b'\xFF\xD8':
345 334 raise Exception('NotJpeg')
@@ -352,7 +341,7 @@ def get_orientation(data: bytes):
352 341 except Exception:
353 342 pass
354 343
355 def process_image(orientation, img, new_width, new_height):
344 def process_image(orientation: int, img: Image.Image, new_width: int, new_height: int) -> Image.Image:
356 345 try:
357 346 # Initialize the canvas
358 347 new_img = Image.new("RGB", (new_width, new_height), color="#FFFFFF")
@@ -370,7 +359,7 @@ def process_image(orientation, img, new_width, new_height):
370 359 except Exception as e:
371 360 raise e
372 361
373 def compress_image_to_base64(img, compression_rate):
362 def compress_image_to_base64(img, compression_rate) -> str:
374 363 try:
375 364 output_buffer = io.BytesIO()
376 365 img.save(output_buffer, format="JPEG", quality=int(compression_rate * 100))
@@ -379,13 +368,22 @@ def compress_image_to_base64(img, compression_rate):
379 368 raise e
380 369
381 370 def create_message(conversation: Conversation, prompt: str, tone: str, context: str=None) -> str:
371 options_sets = Defaults.optionsSets
372 if tone == Tones.creative:
373 options_sets.append("h3imaginative")
374 elif tone == Tones.precise:
375 options_sets.append("h3precise")
376 elif tone == Tones.balanced:
377 options_sets.append("galileo")
378 else:
379 options_sets.append("harmonyv3")
382 380
383 381 request_id = str(uuid.uuid4())
384 382 struct = {
385 383 'arguments': [
386 384 {
387 385 'source': 'cib',
388 'optionsSets': Defaults.optionsSets,
386 'optionsSets': options_sets,
389 387 'allowedMessageTypes': Defaults.allowedMessageTypes,
390 388 'sliceIds': Defaults.sliceIds,
391 389 'traceId': os.urandom(16).hex(),