gpt-go  by hanyuancheung

Go SDK for interacting with OpenAI's GPT models

created 2 years ago
364 stars

Top 78.4% on sourcepulse

GitHubView on GitHub
Project Summary

This Go client library provides a convenient way for developers to interact with OpenAI's ChatGPT, GPT-4, and GPT-3 APIs. It simplifies making requests for text completion, chat completions (including streaming), image generation, and document search, enabling seamless integration of powerful AI models into Go applications.

How It Works

The library acts as a direct wrapper around the OpenAI API, abstracting away the complexities of HTTP requests, JSON serialization, and error handling. It utilizes Go's standard library for networking and JSON processing, offering a clean and idiomatic interface for developers. The NewClient function initializes the client with an API key, and various methods like ChatCompletionStream, CompletionWithEngine, and Image map directly to OpenAI's respective API endpoints.

Quick Start & Requirements

  • Install: git clone https://github.com/hanyuancheung/gpt-go.git
  • Run: export API_KEY={YOUR_API_KEY} then make chatgpt-example and ./chatgpt
  • Prerequisites: Go toolchain, OpenAI API Key.
  • Documentation: https://pkg.go.dev/github.com/hanyuancheung/gpt-go

Highlighted Details

  • Supports GPT-4 and GPT-3 APIs via Chat Completions.
  • Includes streaming support for chat completions.
  • Implements API calls for text completion, image generation (DALL-E 2), and document search.
  • Provides example usage for various functionalities.

Maintenance & Community

  • Community contributions are welcome via GitHub issues and pull requests.
  • Code must be formatted with gofmt.

Licensing & Compatibility

  • MIT License.
  • Permissive license suitable for commercial and closed-source applications.

Limitations & Caveats

The project primarily focuses on wrapping the OpenAI API and does not include higher-level abstractions or state management for complex conversational flows. Users are responsible for managing API keys and understanding OpenAI's usage policies.

Feedback? Help us improve.