go-openai  by sashabaranov

Go client for OpenAI API

created 5 years ago
10,208 stars

Top 5.0% on sourcepulse

GitHubView on GitHub
Project Summary

This Go library provides an unofficial client for the OpenAI API, targeting Go developers who need to integrate with services like ChatGPT, GPT-4, DALL-E, and Whisper. It simplifies API interactions, enabling programmatic access to advanced AI models for text generation, image creation, and speech-to-text transcription.

How It Works

The library offers a Go-idiomatic interface to OpenAI's REST API. It abstracts away the complexities of HTTP requests, JSON serialization, and response parsing. Key features include support for streaming responses, function calling with JSON schema generation, and structured output parsing, allowing developers to build sophisticated AI-powered applications efficiently.

Quick Start & Requirements

  • Install using: go get github.com/sashabaranov/go-openai
  • Requires Go version 1.18 or greater.
  • An OpenAI API key is necessary.

Highlighted Details

  • Supports latest models including GPT-4o, GPT-4, GPT-3.5 Turbo, DALL-E 3, and Whisper.
  • Includes examples for chat completions, streaming, image generation, audio transcription, fine-tuning, and function calling.
  • Provides utilities for generating JSON schemas for function calling and parsing structured outputs.
  • Offers configuration options for Azure OpenAI endpoints and proxy support.

Maintenance & Community

  • Maintained by sashabaranov.
  • Contributions are welcomed following contributing guidelines.

Licensing & Compatibility

  • The library is provided under an unspecified license. Compatibility for commercial use or closed-source linking is not explicitly stated.

Limitations & Caveats

  • The library is unofficial.
  • The README notes that temperature: 0 might not guarantee deterministic outputs due to API behavior and token count limitations; workarounds involving seed and system_fingerprint are suggested.
  • The library does not include a token counting feature.
Feedback? Help us improve.