A lightweight Go library for interacting with the Perplexity AI API, focusing on the chat completion endpoint.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-01-23 12:40:59 -07:00
.github fix: update GitHub Actions workflow to use correct path for gh-action-badge 2025-01-22 20:48:05 +01:00
.vscode initial version 2024-06-30 13:32:25 +02:00
cmd add test cases for GetCitations 2025-01-23 12:40:59 -07:00
go.mod chore(deps): bump github.com/go-playground/validator/v10 (#14) 2025-01-16 21:06:32 +01:00
go.sum chore(deps): bump github.com/go-playground/validator/v10 (#14) 2025-01-16 21:06:32 +01:00
LICENSE Initial commit 2024-06-28 11:45:40 +02:00
perplexity.go refactor: update models and default models #18 (#19) 2025-01-22 20:52:45 +01:00
perplexity_msg.go feat: implement Messages object for Perplexity API with user and assistant message handling #16 (#17) 2025-01-19 21:26:08 +01:00
perplexity_msg_test.go feat: implement Messages object for Perplexity API with user and assistant message handling #16 (#17) 2025-01-19 21:26:08 +01:00
perplexity_request.go refactor: update models and default models #18 (#19) 2025-01-22 20:52:45 +01:00
perplexity_request_test.go refactor: update models and default models #18 (#19) 2025-01-22 20:52:45 +01:00
perplexity_response.go remove temporary empty string return in the String function 2025-01-22 20:39:51 -07:00
perplexity_response_test.go add test cases for GetCitations 2025-01-23 12:40:59 -07:00
perplexity_test.go refactor: update models and default models #18 (#19) 2025-01-22 20:52:45 +01:00
README.md fix: update coverage badge syntax in README 2025-01-16 20:59:33 +01:00

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.