Added modal labs example to documentation (#556)

This commit is contained in:
Andriy Mulyar
2023-05-13 11:10:18 -04:00
committed by GitHub
parent 9be43f4dc9
commit 438529c222
4 changed files with 40 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
# GPT4All API
# GPT4All Python API
The `GPT4All` provides a universal API to call all GPT4All models and
introduces additional helpful functionality such as downloading models.

View File

@@ -0,0 +1,35 @@
# GPT4All with Modal Labs
You can easily query any GPT4All model on [Modal Labs](https://modal.com/) infrastructure!
## Example
```python
import modal
def download_model():
import gpt4all
#you can use any model from https://gpt4all.io/models/models.json
return gpt4all.GPT4All("ggml-gpt4all-j-v1.3-groovy.bin")
image=modal.Image.debian_slim().pip_install("gpt4all").run_function(download_model)
stub = modal.Stub("gpt4all", image=image)
@stub.cls(keep_warm=1)
class GPT4All:
def __enter__(self):
print("Downloading model")
self.gptj = download_model()
print("Loaded model")
def generate(self):
messages = [{"role": "user", "content": "Name 3 colors"}]
completion = self.gptj.chat_completion(messages)
print(f"Completion: {completion}")
@stub.local_entrypoint()
def main():
model = GPT4All()
for i in range(10):
model.generate()
```

View File

@@ -1,4 +1,4 @@
# GPT4All
# GPT4All with Python
In this package, we introduce Python bindings built around GPT4All's C/C++ model backends.