diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-01 15:08:23 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-01 15:08:23 +0200 |
commit | 493c37a81ecc34247189f7339632518268524655 (patch) | |
tree | 2d647b02b5c16ed5d0c2643112f4b7c31d1c62e3 /ora/__init__.py | |
parent | important note + new site (ora.sh) (diff) | |
download | gpt4free-493c37a81ecc34247189f7339632518268524655.tar gpt4free-493c37a81ecc34247189f7339632518268524655.tar.gz gpt4free-493c37a81ecc34247189f7339632518268524655.tar.bz2 gpt4free-493c37a81ecc34247189f7339632518268524655.tar.lz gpt4free-493c37a81ecc34247189f7339632518268524655.tar.xz gpt4free-493c37a81ecc34247189f7339632518268524655.tar.zst gpt4free-493c37a81ecc34247189f7339632518268524655.zip |
Diffstat (limited to 'ora/__init__.py')
-rw-r--r-- | ora/__init__.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ora/__init__.py b/ora/__init__.py new file mode 100644 index 00000000..546e0940 --- /dev/null +++ b/ora/__init__.py @@ -0,0 +1,36 @@ +from ora.model import CompletionModel +from ora.typing import OraResponse +from requests import post +from time import time + +class Completion: + def create( + model : CompletionModel, + prompt: str, + conversationId: str or None = None) -> OraResponse: + + extra = { + 'conversationId': conversationId} if conversationId else {} + + response = post('https://ora.sh/api/conversation', json = extra | { + 'chatbotId': model.id, + 'input' : prompt, + 'userId' : model.createdBy}).json() + + return OraResponse({ + 'id' : response['conversationId'], + 'object' : 'text_completion', + 'created': int(time()), + 'model' : model.slug, + 'choices': [{ + 'text' : response['response'], + 'index' : 0, + 'logprobs' : None, + 'finish_reason' : 'stop' + }], + 'usage': { + 'prompt_tokens' : len(prompt), + 'completion_tokens' : len(response['response']), + 'total_tokens' : len(prompt) + len(response['response']) + } + })
\ No newline at end of file |