diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-08-22 16:36:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-22 16:36:10 +0200 |
commit | 704408202b83f763f0b25c57989027b10d7ebf71 (patch) | |
tree | 4535edae946f9cf4f2d82519054e0e64199c3968 /g4f/Provider | |
parent | ~ | Merge pull request #830 (diff) | |
parent | fix Equing response error with no stream (diff) | |
download | gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar.gz gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar.bz2 gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar.lz gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar.xz gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.tar.zst gpt4free-704408202b83f763f0b25c57989027b10d7ebf71.zip |
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/Acytoo.py | 7 | ||||
-rw-r--r-- | g4f/Provider/Aichat.py | 6 | ||||
-rw-r--r-- | g4f/Provider/Equing.py | 3 | ||||
-rw-r--r-- | g4f/Provider/H2o.py | 2 |
4 files changed, 13 insertions, 5 deletions
diff --git a/g4f/Provider/Acytoo.py b/g4f/Provider/Acytoo.py index 32c67c0c..2edd9efd 100644 --- a/g4f/Provider/Acytoo.py +++ b/g4f/Provider/Acytoo.py @@ -19,11 +19,12 @@ class Acytoo(BaseProvider): **kwargs: Any, ) -> CreateResult: headers = _create_header() - payload = _create_payload(messages) + payload = _create_payload(messages, kwargs.get('temperature', 0.5)) url = "https://chat.acytoo.com/api/completions" response = requests.post(url=url, headers=headers, json=payload) response.raise_for_status() + response.encoding = "utf-8" yield response.text @@ -34,7 +35,7 @@ def _create_header(): } -def _create_payload(messages: list[dict[str, str]]): +def _create_payload(messages: list[dict[str, str]], temperature): payload_messages = [ message | {"createdAt": int(time.time()) * 1000} for message in messages ] @@ -42,6 +43,6 @@ def _create_payload(messages: list[dict[str, str]]): "key": "", "model": "gpt-3.5-turbo", "messages": payload_messages, - "temperature": 1, + "temperature": temperature, "password": "", } diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py index 6992d071..a1d90db7 100644 --- a/g4f/Provider/Aichat.py +++ b/g4f/Provider/Aichat.py @@ -40,9 +40,9 @@ class Aichat(BaseProvider): json_data = { "message": base, - "temperature": 1, + "temperature": kwargs.get('temperature', 0.5), "presence_penalty": 0, - "top_p": 1, + "top_p": kwargs.get('top_p', 1), "frequency_penalty": 0, } @@ -52,4 +52,6 @@ class Aichat(BaseProvider): json=json_data, ) response.raise_for_status() + if not response.json()['response']: + raise Exception("Error Response: " + response.json()) yield response.json()["message"] diff --git a/g4f/Provider/Equing.py b/g4f/Provider/Equing.py index bcf6cff9..90c865d9 100644 --- a/g4f/Provider/Equing.py +++ b/g4f/Provider/Equing.py @@ -53,6 +53,9 @@ class Equing(ABC): response = requests.post('https://next.eqing.tech/api/openai/v1/chat/completions', headers=headers, json=json_data, stream=stream) + if not stream: + yield response.json()["choices"][0]["message"]["content"] + return for line in response.iter_content(chunk_size=1024): if line: diff --git a/g4f/Provider/H2o.py b/g4f/Provider/H2o.py index c2492e59..f9b799bb 100644 --- a/g4f/Provider/H2o.py +++ b/g4f/Provider/H2o.py @@ -75,6 +75,8 @@ class H2o(BaseProvider): headers=headers, json=data, ) + response.raise_for_status() + response.encoding = "utf-8" generated_text = response.text.replace("\n", "").split("data:") generated_text = json.loads(generated_text[-1]) |