diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-05 15:26:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-05 15:26:08 +0200 |
commit | ae9702ecf05562f47fdcdc005a2a36124c6cc567 (patch) | |
tree | 5015b50c0e9f679aa2682d2064418d5473de9637 /g4f/Provider | |
parent | Merge pull request #875 from Lin-jun-xiang/annotations (diff) | |
parent | Join the messages (diff) | |
download | gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar.gz gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar.bz2 gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar.lz gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar.xz gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.tar.zst gpt4free-ae9702ecf05562f47fdcdc005a2a36124c6cc567.zip |
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/AItianhu.py | 6 | ||||
-rw-r--r-- | g4f/Provider/AiService.py | 6 | ||||
-rw-r--r-- | g4f/Provider/Aichat.py | 6 | ||||
-rw-r--r-- | g4f/Provider/Bing.py | 5 | ||||
-rw-r--r-- | g4f/Provider/ChatgptAi.py | 6 | ||||
-rw-r--r-- | g4f/Provider/Theb.py | 6 | ||||
-rw-r--r-- | g4f/Provider/V50.py | 8 |
7 files changed, 14 insertions, 29 deletions
diff --git a/g4f/Provider/AItianhu.py b/g4f/Provider/AItianhu.py index 4458c14f..0982d3c6 100644 --- a/g4f/Provider/AItianhu.py +++ b/g4f/Provider/AItianhu.py @@ -19,10 +19,8 @@ class AItianhu(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - base = "" - for message in messages: - base += "%s: %s\n" % (message["role"], message["content"]) - base += "assistant:" + base = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + base += "\nassistant: " headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" diff --git a/g4f/Provider/AiService.py b/g4f/Provider/AiService.py index f4de2836..2b5a6e7d 100644 --- a/g4f/Provider/AiService.py +++ b/g4f/Provider/AiService.py @@ -18,10 +18,8 @@ class AiService(BaseProvider): stream: bool, **kwargs: Any, ) -> CreateResult: - base = "" - for message in messages: - base += "%s: %s\n" % (message["role"], message["content"]) - base += "assistant:" + base = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + base += "\nassistant: " headers = { "accept": "*/*", diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py index 2b228314..59640533 100644 --- a/g4f/Provider/Aichat.py +++ b/g4f/Provider/Aichat.py @@ -17,10 +17,8 @@ class Aichat(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - base = "" - for message in messages: - base += "%s: %s\n" % (message["role"], message["content"]) - base += "assistant:" + chat = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + chat += "\nassistant: " headers = { "authority": "chat-gpt.org", diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index 57dfcec9..cec82108 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -48,10 +48,7 @@ class Bing(AsyncGeneratorProvider): return stream_generate(prompt, context, cookies_dict) def create_context(messages: list[dict[str, str]]): - context = "" - - for message in messages: - context += "[%s](#message)\n%s\n\n" % (message["role"], message["content"]) + context = "".join(f"[{message['role']}](#message)\n{message['content']}\n\n" for message in messages) return context diff --git a/g4f/Provider/ChatgptAi.py b/g4f/Provider/ChatgptAi.py index 55b9b942..7613ccf1 100644 --- a/g4f/Provider/ChatgptAi.py +++ b/g4f/Provider/ChatgptAi.py @@ -19,10 +19,8 @@ class ChatgptAi(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - chat = "" - for message in messages: - chat += "%s: %s\n" % (message["role"], message["content"]) - chat += "assistant: " + chat = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + chat += "\nassistant: " response = requests.get("https://chatgpt.ai/") nonce, post_id, _, bot_id = re.findall( diff --git a/g4f/Provider/Theb.py b/g4f/Provider/Theb.py index c37cc4b7..72fce3ac 100644 --- a/g4f/Provider/Theb.py +++ b/g4f/Provider/Theb.py @@ -22,10 +22,8 @@ class Theb(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - conversation = '' - for message in messages: - conversation += '%s: %s\n' % (message['role'], message['content']) - conversation += 'assistant: ' + conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + conversation += "\nassistant: " auth = kwargs.get("auth", { "bearer_token":"free", diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 4e02d4b7..81a95ba8 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -21,11 +21,9 @@ class V50(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - conversation = '' - for message in messages: - conversation += '%s: %s\n' % (message['role'], message['content']) - - conversation += 'assistant: ' + conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + conversation += "\nassistant: " + payload = { "prompt" : conversation, "options" : {}, |