mirror of
https://github.com/kyledickey/perplexity-go.git
synced 2026-10-31 12:35:33 +00:00
A lightweight Go library for interacting with the Perplexity AI API, focusing on the chat completion endpoint.
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github | ||
| .vscode | ||
| cmd | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| perplexity.go | ||
| perplexity_msg.go | ||
| perplexity_msg_test.go | ||
| perplexity_request.go | ||
| perplexity_request_test.go | ||
| perplexity_response.go | ||
| perplexity_response_test.go | ||
| perplexity_test.go | ||
| README.md | ||
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.