summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Ails.py
diff options
context:
space:
mode:
authorAndPim4912 <52836885+AndPim4912@users.noreply.github.com>2023-10-23 14:10:28 +0200
committerGitHub <noreply@github.com>2023-10-23 14:10:28 +0200
commit8d7ad98fcb314453c01f6dcd4bfe59016efd78ce (patch)
tree4d39804e1aa1724560e1688f0b6d4c124b9771c7 /g4f/Provider/Ails.py
parentRefactor API initialization to accept a list of ignored providers. (diff)
parentDebug config in api (diff)
downloadgpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.gz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.bz2
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.lz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.xz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.zst
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.zip
Diffstat (limited to 'g4f/Provider/Ails.py')
-rw-r--r--g4f/Provider/Ails.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/g4f/Provider/Ails.py b/g4f/Provider/Ails.py
index 4d072646..fae3e62a 100644
--- a/g4f/Provider/Ails.py
+++ b/g4f/Provider/Ails.py
@@ -44,8 +44,8 @@ class Ails(AsyncGeneratorProvider):
"from-url": "https://ai.ls/?chat=1"
}
async with ClientSession(
- headers=headers
- ) as session:
+ headers=headers
+ ) as session:
timestamp = _format_timestamp(int(time.time() * 1000))
json_data = {
"model": "gpt-3.5-turbo",
@@ -57,10 +57,10 @@ class Ails(AsyncGeneratorProvider):
"s": _hash({"t": timestamp, "m": messages[-1]["content"]}),
}
async with session.post(
- "https://api.caipacity.com/v1/chat/completions",
- proxy=proxy,
- json=json_data
- ) as response:
+ "https://api.caipacity.com/v1/chat/completions",
+ proxy=proxy,
+ json=json_data
+ ) as response:
response.raise_for_status()
start = "data: "
async for line in response.content:
@@ -68,10 +68,9 @@ class Ails(AsyncGeneratorProvider):
if line.startswith(start) and line != "data: [DONE]":
line = line[len(start):-1]
line = json.loads(line)
- token = line["choices"][0]["delta"].get("content")
- if token:
+ if token := line["choices"][0]["delta"].get("content"):
if "ai.ls" in token or "ai.ci" in token:
- raise Exception("Response Error: " + token)
+ raise Exception(f"Response Error: {token}")
yield token
@@ -89,12 +88,7 @@ class Ails(AsyncGeneratorProvider):
def _hash(json_data: dict[str, str]) -> SHA256:
- base_string: str = "%s:%s:%s:%s" % (
- json_data["t"],
- json_data["m"],
- "WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf",
- len(json_data["m"]),
- )
+ base_string: str = f'{json_data["t"]}:{json_data["m"]}:WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf:{len(json_data["m"])}'
return SHA256(hashlib.sha256(base_string.encode()).hexdigest())