github.com/predictionguard/go-client

Go SDK for accessing PredictionGuard APIs


License
Apache-2.0
Install
go get github.com/predictionguard/go-client

Documentation

Prediction Guard Go Client

CircleCI Go Report Card go.mod Go version

Copyright 2024 Prediction Guard bill@predictionguard.com

Description

This Module provides functionality developed to simplify interfacing with Prediction Guard API in Go.

Requirements

To access the API, contact us here to get an enterprise access token. You will need this access token to continue.

Usage

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/predictionguard/go-client"
)

func main() {
	if err := run(); err != nil {
		log.Fatalln(err)
	}
}

func run() error {
	host := "https://api.predictionguard.com"
	apiKey := os.Getenv("PGKEY")

	logger := func(ctx context.Context, msg string, v ...any) {
		s := fmt.Sprintf("msg: %s", msg)
		for i := 0; i < len(v); i = i + 2 {
			s = s + fmt.Sprintf(", %s: %v", v[i], v[i+1])
		}
		log.Println(s)
	}

	cln := client.New(logger, host, apiKey)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	prompt := "A short poem may be a stylistic choice or it may be that you have said what you intended to say in a more concise way."

	resp, err := cln.Injection(ctx, prompt)
	if err != nil {
		return fmt.Errorf("ERROR: %w", err)
	}

	fmt.Println(resp.Checks[0].Probability)

	return nil
}

Take a look at the examples directory for more examples.

Docs

You can find the Prediction Guard API docs on the Prediction Guard website.

API Docs

API Reference

Go Docs

Getting started

Once you have your api key you can use the makefile to run curl commands for the different api endpoints. For example, make curl-injection will connect to the injection endpoint and return the injection response. The makefile also allows you to run the different examples such as make go-injection to run the Go injection example.

Licensing

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2024 Prediction Guard