返回提交历史
Modified
g4f/__init__.py
+4
-62
XFEstudio/gpt4free
fix(g4f/__init__.py): ensure consistent parameter usage
156bb650
代码差异
1 个文件
+4
-62
@@ -23,30 +23,6 @@ class ChatCompletion:
23
23
ignore_stream: bool = False,
24
24
patch_provider: callable = None,
25
25
**kwargs) -> Union[CreateResult, str]:
26
"""
27
Creates a chat completion using the specified model, provider, and messages.
28
29
Args:
30
model (Union[Model, str]): The model to use, either as an object or a string identifier.
31
messages (Messages): The messages for which the completion is to be created.
32
provider (Union[ProviderType, str, None], optional): The provider to use, either as an object, a string identifier, or None.
33
stream (bool, optional): Indicates if the operation should be performed as a stream.
34
auth (Union[str, None], optional): Authentication token or credentials, if required.
35
ignored (list[str], optional): List of provider names to be ignored.
36
ignore_working (bool, optional): If True, ignores the working status of the provider.
37
ignore_stream (bool, optional): If True, ignores the stream and authentication requirement checks.
38
patch_provider (callable, optional): Function to modify the provider.
39
**kwargs: Additional keyword arguments.
40
41
Returns:
42
Union[CreateResult, str]: The result of the chat completion operation.
43
44
Raises:
45
AuthenticationRequiredError: If authentication is required but not provided.
46
ProviderNotFoundError, ModelNotFoundError: If the specified provider or model is not found.
47
ProviderNotWorkingError: If the provider is not operational.
48
StreamNotSupportedError: If streaming is requested but not supported by the provider.
49
"""
50
26
model, provider = get_model_and_provider(
51
27
model, provider, stream,
52
28
ignored, ignore_working,
@@ -64,7 +40,8 @@ class ChatCompletion:
64
40
if patch_provider:
65
41
provider = patch_provider(provider)
66
42
67
result = provider.create_completion(model, messages, stream, **kwargs)
43
result = provider.create_completion(model, messages, stream=stream, **kwargs)
44
68
45
return result if stream else ''.join([str(chunk) for chunk in result])
69
46
70
47
@staticmethod
@@ -76,24 +53,6 @@ class ChatCompletion:
76
53
ignore_working: bool = False,
77
54
patch_provider: callable = None,
78
55
**kwargs) -> Union[AsyncResult, str]:
79
"""
80
Asynchronously creates a completion using the specified model and provider.
81
82
Args:
83
model (Union[Model, str]): The model to use, either as an object or a string identifier.
84
messages (Messages): Messages to be processed.
85
provider (Union[ProviderType, str, None]): The provider to use, either as an object, a string identifier, or None.
86
stream (bool): Indicates if the operation should be performed as a stream.
87
ignored (list[str], optional): List of provider names to be ignored.
88
patch_provider (callable, optional): Function to modify the provider.
89
**kwargs: Additional keyword arguments.
90
91
Returns:
92
Union[AsyncResult, str]: The result of the asynchronous chat completion operation.
93
94
Raises:
95
StreamNotSupportedError: If streaming is requested but not supported by the provider.
96
"""
97
56
model, provider = get_model_and_provider(model, provider, False, ignored, ignore_working)
98
57
99
58
if stream:
@@ -113,23 +72,6 @@ class Completion:
113
72
provider : Union[ProviderType, None] = None,
114
73
stream : bool = False,
115
74
ignored : list[str] = None, **kwargs) -> Union[CreateResult, str]:
116
"""
117
Creates a completion based on the provided model, prompt, and provider.
118
119
Args:
120
model (Union[Model, str]): The model to use, either as an object or a string identifier.
121
prompt (str): The prompt text for which the completion is to be created.
122
provider (Union[ProviderType, None], optional): The provider to use, either as an object or None.
123
stream (bool, optional): Indicates if the operation should be performed as a stream.
124
ignored (list[str], optional): List of provider names to be ignored.
125
**kwargs: Additional keyword arguments.
126
127
Returns:
128
Union[CreateResult, str]: The result of the completion operation.
129
130
Raises:
131
ModelNotAllowedError: If the specified model is not allowed for use with this method.
132
"""
133
75
allowed_models = [
134
76
'code-davinci-002',
135
77
'text-ada-001',
@@ -143,6 +85,6 @@ class Completion:
143
85
144
86
model, provider = get_model_and_provider(model, provider, stream, ignored)
145
87
146
result = provider.create_completion(model, [{"role": "user", "content": prompt}], stream, **kwargs)
88
result = provider.create_completion(model, [{"role": "user", "content": prompt}], stream=stream, **kwargs)
147
89
148
return result if stream else ''.join(result)
90
return result if stream else ''.join(result)