summaryrefslogtreecommitdiffstats
path: root/g4f/__init__.py
diff options
context:
space:
mode:
authorabc <98614666+xtekky@users.noreply.github.com>2023-09-23 12:16:19 +0200
committerabc <98614666+xtekky@users.noreply.github.com>2023-09-23 12:16:19 +0200
commit6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb (patch)
treed57ab49f5f168cf602b31c4508b3f2e232d09aeb /g4f/__init__.py
parent~ (diff)
downloadgpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar.gz
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar.bz2
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar.lz
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar.xz
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.tar.zst
gpt4free-6c2e3cc53cdb769f80d7fbb4df418cd4ab8aaabb.zip
Diffstat (limited to '')
-rw-r--r--g4f/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/g4f/__init__.py b/g4f/__init__.py
index f3a887f6..c0f70d8a 100644
--- a/g4f/__init__.py
+++ b/g4f/__init__.py
@@ -68,3 +68,30 @@ class ChatCompletion:
raise Exception(f"Provider: {provider.__name__} doesn't support create_async")
return await provider.create_async(model.name, messages, **kwargs)
+
+class Completion:
+ @staticmethod
+ def create(
+ model : Union[models.Model, str],
+ prompt : str,
+ provider : Union[type[BaseProvider], None] = None,
+ stream : bool = False, **kwargs) -> Union[CreateResult, str]:
+
+ allowed_models = [
+ 'code-davinci-002',
+ 'text-ada-001',
+ 'text-babbage-001',
+ 'text-curie-001',
+ 'text-davinci-002',
+ 'text-davinci-003'
+ ]
+
+ if model not in allowed_models:
+ raise Exception(f'ValueError: Can\'t use {model} with Completion.create()')
+
+ model, provider = get_model_and_provider(model, provider, stream)
+
+ result = provider.create_completion(model.name,
+ [{"role": "user", "content": prompt}], stream, **kwargs)
+
+ return result if stream else ''.join(result) \ No newline at end of file