Skip to content

Non-official Go client library for the Perplexity AI

License

Notifications You must be signed in to change notification settings

painhardcore/perplexity-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

perplexity-go

perplexity-go is a non-official Go client library for the Perplexity AI chat completion API. It provides an easy-to-use interface for interacting with the Perplexity API and generating chat completions using various language models.

Warning

Experimental package, API would probably break.

Features

  • Simple and intuitive API for chat completions
  • Support for multiple language models
  • Customizable request parameters
  • Asynchronous requests with context cancellation

Not supported yet

  • Streaming
  • Images
  • Citations

Installation

To install perplexity-go, use go get:

go get -u github.com/painhardcore/perplexity-go

Example Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/painhardcore/perplexity-go"
)

func main() {
	apiKey := "pplx-xxx" // Replace with your actual API key
	model := perplexity.ModelLlama3SonarSmall32kChat

	// You can omit the opts parameter to use the default 30-second timeout
	opts := &perplexity.ClientOptions{
		RequestTimeoutInSeconds: 100,
    }
	client := perplexity.NewClient(apiKey, model, opts)

	request := perplexity.ChatCompletionRequest{
		Messages: []perplexity.Message{
			{Role: perplexity.RoleSystem, Content: "Be rude to me, but respect me"},
			{Role: perplexity.RoleUser, Content: "Tell me how to be a good dev and solve all tickets in my sprints"},
		},
		MaxTokens:   100,
		Temperature: 0.2,
		TopP:        0.9,
	}

	ctx := context.Background()
	response, err := client.ChatCompletions(ctx, request)
	if err != nil {
		log.Fatalf("Error: %s", err)
	}

	text, err := response.GetCompleteSingleMessage()
	if err != nil {
		fmt.Printf("err: %s,\nfull response %+v\n", err, response)
	}
	fmt.Println(text)
}

Contributing

Contributions to perplexity-go are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you'd like to contribute code, please fork the repository and submit a pull request.

About

Non-official Go client library for the Perplexity AI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages