Skip to content

A lightweight Go library for interacting with the Perplexity AI API, focusing on the chat completion endpoint.

License

Notifications You must be signed in to change notification settings

sgaunet/perplexity-go

Repository files navigation

Go Report Card coverage

Perplexity API Go Client

A lightweight Go library for interacting with the Perplexity AI API, focusing on the chat completion endpoint.

Features

Simple and easy-to-use interface for making chat completion requests
Supports all Perplexity models, including online LLMs
Handles authentication and API key management
Provides convenient methods for common operations

Installation

To install the library, use go get:

go get github.com/sgaunet/perplexity-go/v2

Usage

Here's a quick example of how to use the library:

package main

import (
  "fmt"
  "os"

  "github.com/sgaunet/perplexity-go/v2"
)

func main() {
client := perplexity.NewClient(os.Getenv("PPLX_API_KEY"))
  msg := []perplexity.Message{
    {
      Role:    "user",
      Content: "Wat's the capital of France?",
    },
  }
  req := perplexity.NewCompletionRequest(perplexity.WithMessages(msg), perplexity.WithReturnImages(true))
  err := req.Validate()
  if err != nil {
    fmt.Printf("Error: %v\n", err)
    os.Exit(1)
  }

  res, err := client.SendCompletionRequest(req)
  if err != nil {
    fmt.Printf("Error: %v\n", err)
    os.Exit(1)
  }

  fmt.Println(res.GetLastContent())
}

Documentation

For detailed documentation and more examples, please refer to the GoDoc page.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lightweight Go library for interacting with the Perplexity AI API, focusing on the chat completion endpoint.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages