返回提交历史
Modified
README.md
+1
-1
Modified
gpt4free/__init__.py
+23
-0
XFEstudio/gpt4free
add gpt4free.ChatCompletion class
0a59e65c
代码差异
2 个文件
+24
-1
@@ -195,7 +195,7 @@ docker-compose up --build -d
195
195
196
196
This program is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
197
197
198
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).
198
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).
199
199
200
200
### Copyright Notice: <a name="copyright"></a>
201
201
@@ -5,6 +5,7 @@ from gpt4free import quora
5
5
from gpt4free import theb
6
6
from gpt4free import usesless
7
7
from gpt4free import you
8
from gpt4free import deepai
8
9
9
10
10
11
class Provider(Enum):
@@ -69,3 +70,25 @@ class Completion:
69
70
@staticmethod
70
71
def __deepai_service(prompt: str, **kwargs):
71
72
return ''.join(deepai.Completion.create(prompt=prompt))
73
74
class ChatCompletion:
75
"""This class is used to execute a chat completion for a specified provider"""
76
77
@staticmethod
78
def create(provider: Provider, messages: list, **kwargs) -> str:
79
"""
80
Invokes the given provider with given chat messages and addition arguments and returns the string response
81
82
:param provider: an enum representing the provider to use while invoking
83
:param messages: a list of chat messages, see the OpenAI docs for how to format this (https://platform.openai.com/docs/guides/chat/introduction)
84
:param kwargs: Additional keyword arguments to pass to the provider while invoking
85
:return: A string representing the response from the provider
86
"""
87
if provider == Provider.DeepAI:
88
return ChatCompletion.__deepai_service(messages, **kwargs)
89
else:
90
raise Exception('Provider not exist, Please try again')
91
92
@staticmethod
93
def __deepai_service(messages: list, **kwargs):
94
return ''.join(deepai.ChatCompletion.create(messages=messages))