Reference

Embeddings

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

Generate Embeddings

To generate embeddings, you can use the following code examples. Depending on your preference or requirements, select the appropriate method for your application. This functionality accepts text and image inputs, and supports batching multiple inputs. The Go REST API only supports images that are input as a base64 encoded string, whereas the python client supports image files, image urls, and images encoded in a base64 string.

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.embeddings.create(
12 model="bridgetower-large-itm-mlm-itc",
13 input=[
14 {
15 "text": "Tell me a joke.",
16 "image": "https://farm4.staticflickr.com/3300/3497460990_11dfb95dd1_z.jpg"
17 }
18 ]
19)
20
21print(json.dumps(
22 response,
23 sort_keys=True,
24 indent=4,
25 separators=(',', ': ')
26))

The output will look something like this.

1{
2 "id":"emb-oM1AChyqjQKqT6XKiUqY0bnqIUikK",
3 "object":"embedding_batch",
4 "created":1717780716,
5 "model":"bridgetower-large-itm-mlm-itc",
6 "data":[
7 {
8 "status":"error: could not call model, contact support",
9 "index":0,
10 "object":"embedding",
11 "embedding":[
12
13 ]
14 }
15 ]
16}

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.