summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorading2210 <ading2019@gmail.com>2023-05-18 09:21:18 +0200
committerading2210 <ading2019@gmail.com>2023-05-18 09:21:18 +0200
commit0a59e65c6a8860635d55ba72252c96a4712e5fab (patch)
tree190554f93762c998ec8112a1c5a7a0f857555b10
parentadd deepai wrapper (diff)
downloadgpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar.gz
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar.bz2
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar.lz
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar.xz
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.tar.zst
gpt4free-0a59e65c6a8860635d55ba72252c96a4712e5fab.zip
Diffstat (limited to '')
-rw-r--r--README.md2
-rw-r--r--gpt4free/__init__.py23
2 files changed, 24 insertions, 1 deletions
diff --git a/README.md b/README.md
index c6d79bad..0adc9e69 100644
--- a/README.md
+++ b/README.md
@@ -195,7 +195,7 @@ docker-compose up --build -d
This program is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
-Most code, with the exception of `quora/api.py` (by [ading2210](https://github.com/ading2210)), has been written by me, [xtekky](https://github.com/xtekky).
+Most code, with the exception of `quora/api.py` and `deepai/__init__.py` (by [ading2210](https://github.com/ading2210)), has been written by me, [xtekky](https://github.com/xtekky).
### Copyright Notice: <a name="copyright"></a>
diff --git a/gpt4free/__init__.py b/gpt4free/__init__.py
index 739cf763..2dc6f5f3 100644
--- a/gpt4free/__init__.py
+++ b/gpt4free/__init__.py
@@ -5,6 +5,7 @@ from gpt4free import quora
from gpt4free import theb
from gpt4free import usesless
from gpt4free import you
+from gpt4free import deepai
class Provider(Enum):
@@ -69,3 +70,25 @@ class Completion:
@staticmethod
def __deepai_service(prompt: str, **kwargs):
return ''.join(deepai.Completion.create(prompt=prompt))
+
+class ChatCompletion:
+ """This class is used to execute a chat completion for a specified provider"""
+
+ @staticmethod
+ def create(provider: Provider, messages: list, **kwargs) -> str:
+ """
+ Invokes the given provider with given chat messages and addition arguments and returns the string response
+
+ :param provider: an enum representing the provider to use while invoking
+ :param messages: a list of chat messages, see the OpenAI docs for how to format this (https://platform.openai.com/docs/guides/chat/introduction)
+ :param kwargs: Additional keyword arguments to pass to the provider while invoking
+ :return: A string representing the response from the provider
+ """
+ if provider == Provider.DeepAI:
+ return ChatCompletion.__deepai_service(messages, **kwargs)
+ else:
+ raise Exception('Provider not exist, Please try again')
+
+ @staticmethod
+ def __deepai_service(messages: list, **kwargs):
+ return ''.join(deepai.ChatCompletion.create(messages=messages)) \ No newline at end of file