openai-scala-client  by cequence-io

Unified Scala client for OpenAI and leading LLM providers

Created 3 years ago
255 stars

Top 99.2% on SourcePulse

GitHubView on GitHub
Project Summary

cequence-io/openai-scala-client

This Scala library provides a comprehensive, asynchronous client for interacting with OpenAI's API and a wide array of other major Large Language Model (LLM) providers. It aims to offer a unified, provider-neutral interface for developers to integrate LLM capabilities into their Scala applications, abstracting away provider-specific complexities and offering advanced features like typed streaming and batch processing.

How It Works

The core of the library is the OpenAIService, which acts as a facade over various LLM providers through adapters. It supports a broad range of LLM operations, including chat completions, image generation, embeddings, batch processing, and voice routines. A key innovation is its provider-neutral typed stream of ChatChunk events, enabling consistent handling of responses across different LLMs. The library includes its own WS client (defaulting to Play WS) and supports dependency injection via scala-guice.

Quick Start & Requirements

  • Installation: Add the following dependency to your build.sbt:
    "io.cequence" %% "openai-scala-client" % "1.3.0"
    
    For streaming support, use "io.cequence" %% "openai-scala-client-stream" % "1.3.0". For a single dependency including all provider clients, use "io.cequence" %% "openai-scala-all" % "1.3.0".
  • Prerequisites: Scala 2.12, 2.13, or 3. API keys and potentially organization IDs are required for most providers (e.g., OPENAI_SCALA_CLIENT_API_KEY). Some providers may require additional client libraries.
  • Configuration: API keys can be set via environment variables (OPENAI_SCALA_CLIENT_API_KEY) or configuration files (openai-scala-client.conf).
  • Examples: A comprehensive set of examples is available in the openai-scala-client-examples project.

Highlighted Details

  • Extensive Provider Support: Integrates with OpenAI, Azure OpenAI, Anthropic (including Bedrock and Managed Agents), Google Gemini/Vertex AI, Groq, Perplexity, TypeSafe AI (Jev), Mistral, Ollama, and many others.
  • Unified API: Offers a consistent interface (OpenAIService) for diverse LLM functionalities, including chat completions, image APIs, batch processing, and vision capabilities with provider-uniform attachments.
  • Typed Streaming: Provides a provider-neutral, sealed hierarchy of ChatChunk events for handling streamed LLM responses consistently.
  • Advanced Tooling: Supports function calling, JSON schema output, MCP (Multi-modal Conversational Processing), and custom skills across various providers.
  • Batch Processing: Offers asynchronous batch processing for cost efficiency and improved throughput on supported providers.
  • Responses API: A unified interface for advanced LLM interactions, including tool use (file search, web search, function calls) and image inputs.

Maintenance & Community

This project is community-maintained, created and primarily developed by Peter Banda. Development has been supported by Cequence.io. For announcements and LLM provider news, follow @0xbnd on X. Contact is available via openai-scala-client@cequence.io.

Licensing & Compatibility

The library is published under the permissive MIT License, allowing for commercial use and integration into closed-source projects.

Limitations & Caveats

Several OpenAI API endpoints and models are deprecated or have announced shutdown dates (e.g., Completions API models, Assistants API). The library reflects these changes, with some features marked as deprecated within the client itself. Provider-specific limitations may apply, such as differences in tool support or batch processing capabilities. The streaming API currently has an Akka dependency, though future abstraction is planned.

Health Check
Last Commit

18 hours ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
1
Star History
0 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.