Reference

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="Neural-Chat-7B",
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 "id":"cmpl-IkUw9KPuwrwzseWiOYXCi1TP3I447",
3 "object":"text_completion",
4 "created":1717780588,
5 "choices":[
6 {
7 "text":"\n\nA man walks into a bar and says to the bartender, \"If I show you something really weird, will you give me a free drink?\" The bartender, being intrigued, says, \"Sure, I'll give it a look.\" The man reaches into his pocket and pulls out a tiny horse. The bartender is astonished and gives the man a free drink. The man then puts the horse back into his pocket.\n\nThe next day, the same man walks back into the bar and says to the bartender, \"If I show you something even weirder than yesterday and you give me a free drink, will you do it again?\" The bartender, somewhat reluctantly, says, \"Okay, I guess you can show it to me.\" The man reaches into his pocket, pulls out the same tiny horse, and opens the door to reveal the entire bar inside the horse.\n\nThe bartender faints.",
8 "index":0,
9 "status":"success",
10 "model":"Neural-Chat-7B"
11 }
12 ]
13}

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.