summaryrefslogtreecommitdiffstats
path: root/forefront/typing.py
diff options
context:
space:
mode:
authornoptuno <repollo.marrero@gmail.com>2023-04-28 12:33:51 +0200
committernoptuno <repollo.marrero@gmail.com>2023-04-28 12:33:51 +0200
commit396d7e11b2623cf05c3b0fd4ff9b6cce667835fd (patch)
tree4d7f4531e082deba4fb6bac7e5b221d887e066d9 /forefront/typing.py
parentRemove ignored files from repository (diff)
parentMerge pull request #241 from ethanx40/main (diff)
downloadgpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.gz
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.bz2
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.lz
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.xz
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.zst
gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.zip
Diffstat (limited to 'forefront/typing.py')
-rw-r--r--forefront/typing.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/forefront/typing.py b/forefront/typing.py
new file mode 100644
index 00000000..a11ac49f
--- /dev/null
+++ b/forefront/typing.py
@@ -0,0 +1,36 @@
+class ForeFrontResponse:
+ class Completion:
+ class Choices:
+ def __init__(self, choice: dict) -> None:
+ self.text = choice['text']
+ self.content = self.text.encode()
+ self.index = choice['index']
+ self.logprobs = choice['logprobs']
+ self.finish_reason = choice['finish_reason']
+
+ def __repr__(self) -> str:
+ return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>'''
+
+ def __init__(self, choices: dict) -> None:
+ self.choices = [self.Choices(choice) for choice in choices]
+
+ class Usage:
+ def __init__(self, usage_dict: dict) -> None:
+ self.prompt_tokens = usage_dict['prompt_tokens']
+ self.completion_tokens = usage_dict['completion_tokens']
+ self.total_tokens = usage_dict['total_tokens']
+
+ def __repr__(self):
+ return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
+
+ def __init__(self, response_dict: dict) -> None:
+ self.response_dict = response_dict
+ self.id = response_dict['id']
+ self.object = response_dict['object']
+ self.created = response_dict['created']
+ self.model = response_dict['model']
+ self.completion = self.Completion(response_dict['choices'])
+ self.usage = self.Usage(response_dict['usage'])
+
+ def json(self) -> dict:
+ return self.response_dict