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

XFEstudio/gpt4free

Update Bing.py

Added support the async function Will implement proper cookie retrieval later but Bing is working for now

87c7db73
Luneye <73485421+Luneye@users.noreply.github.com>
提交于

代码差异

1 个文件 +45 -53
Modified g4f/Provider/Bing.py +45 -53
@@ -1,16 +1,11 @@
1 import asyncio
2 import json
3 import os
4 import random
1 import asyncio, json, os, random, aiohttp
5 2
6 import aiohttp
7 import asyncio
8 3 from aiohttp import ClientSession
9 4
10 5 from ..typing import Any, AsyncGenerator, CreateResult, Union
11 from .base_provider import BaseProvider
6 from .base_provider import AsyncGeneratorProvider, get_cookies
12 7
13 class Bing(BaseProvider):
8 class Bing(AsyncGeneratorProvider):
14 9 url = "https://bing.com/chat"
15 10 supports_gpt_4 = True
16 11 working=True
@@ -20,53 +15,50 @@ class Bing(BaseProvider):
20 15 def create_completion(
21 16 model: str,
22 17 messages: list[dict[str, str]],
23 stream: bool,
24 **kwargs: Any
25 ) -> CreateResult:
26 yield from run(create(messages, **kwargs))
27
28 def create(
29 messages: list[dict[str, str]],
30 cookies: dict = {}
31 ):
32 if len(messages) < 2:
33 prompt = messages[0]["content"]
34 context = None
35
36 else:
37 prompt = messages[-1]["content"]
38 context = convert(messages[:-1])
39
40 if not cookies:
41 cookies = {
42 'MUID': '',
43 'BCP': '',
44 'MUIDB': '',
45 'USRLOC': '',
46 'SRCHD': 'AF=hpcodx',
47 'MMCASM': '',
48 '_UR': '',
49 'ANON': '',
50 'NAP': '',
51 'ABDEF': '',
52 'PPLState': '1',
53 'KievRPSSecAuth': '',
54 '_U': '',
55 'SUID': '',
56 '_EDGE_S': '',
57 'WLS': '',
58 '_HPVN': '',
59 '_SS': '',
60 '_clck': '',
61 'SRCHUSR': '',
62 '_RwBf': '',
63 'SRCHHPGUSR': '',
64 'ipv6': '',
65 }
18 cookies: dict = None,
19 **kwargs
20 ) -> AsyncGenerator:
21
22 if len(messages) < 2:
23 prompt = messages[0]["content"]
24 context = None
25
26 else:
27 prompt = messages[-1]["content"]
28 context = create_context(messages[:-1])
29 if cookies is None:
30 #TODO: Will implement proper cookie retrieval later and use a try-except mechanism in 'stream_generate' instead of defaulting the cookie value like this
31 #cookies = get_cookies(".bing.com")
32 cookies =
33 {
34 'MUID': '',
35 'BCP': '',
36 'MUIDB': '',
37 'USRLOC': '',
38 'SRCHD': 'AF=hpcodx',
39 'MMCASM': '',
40 '_UR': '',
41 'ANON': '',
42 'NAP': '',
43 'ABDEF': '',
44 'PPLState': '1',
45 'KievRPSSecAuth': '',
46 '_U': '',
47 'SUID': '',
48 '_EDGE_S': '',
49 'WLS': '',
50 '_HPVN': '',
51 '_SS': '',
52 '_clck': '',
53 'SRCHUSR': '',
54 '_RwBf': '',
55 'SRCHHPGUSR': '',
56 'ipv6': '',
57 }
66 58
67 return stream_generate(prompt, context, cookies)
59 return stream_generate(prompt, context, cookies)
68 60
69 def convert(messages: list[dict[str, str]]):
61 def create_context(messages: list[dict[str, str]]):
70 62 context = ""
71 63
72 64 for message in messages: