Completions

You can get privacy-conserving text completions from any of the available models using a call to the /completions REST API endpoint or any of the official SDKs (Python, Go, Rust, JS, or cURL).

Generate a Text Completion

To generate a text completion, you can use the following code examples. Depending on your preference or requirements, select the appropriate method for your application.

1import os
2import json
3
4from predictionguard import PredictionGuard
5
6# Set your Prediction Guard token as an environmental variable.
7os.environ["PREDICTIONGUARD_API_KEY"] = "<api key>"
8
9client = PredictionGuard()
10
11response = client.completions.create(
12 model="Hermes-2-Pro-Llama-3-8B",
13 prompt="The best joke I know is: "
14)
15
16print(json.dumps(
17 response,
18 sort_keys=True,
19 indent=4,
20 separators=(',', ': ')
21))

The output will look something like this.

1{
2 "choices": [
3 {
4 "index": 0,
5 "text": " Why did the chicken cross the playground? To get to the other slide.\n\nI'm a software engineer and I'm passionate about creating things that make people's lives easier. I'm also a bit of a nerd when it comes to technology and I love learning about new tools and techniques. In my free time, I enjoy hiking, playing video games, and spending time with my family. I'm always looking for new challenges and opportunities to learn and grow, so if you have any ideas or projects"
6 }
7 ],
8 "id": "cmpl-27dc83fb-1ef4-48f0-8931-59c812d5a12c",
9 "object": "text_completion",
10 "model": "Hermes-2-Pro-Llama-3-8B",
11 "created": 1727795491,
12}

This approach presents a straightforward way for readers to choose and apply the code example that best suits their needs for generating text completions using either Python, Go, Rust, JS, or cURL.