Skip to main content
GitHubMaven

Overview

The Moonshot AI Java Client provides a comprehensive Java implementation for the Moonshot AI API. It is based on the Spring AI project’s Moonshot integration and has been extracted to be used as a standalone library. Moonshot AI provides powerful Chinese language models with varying context windows to suit different use cases.

Features

Chat Models

Comprehensive implementation supporting moonshot-v1-8k, moonshot-v1-32k, and moonshot-v1-128k

Flexible Configuration

Extensive customization options including temperature, max tokens, and top-p sampling

Streaming Responses

Support for token-by-token streaming for interactive applications

Function Calling

Register custom Java functions that Moonshot models can intelligently invoke

Robust Error Handling

Built-in retry mechanism with configurable exponential backoff

Observability

Integration with Micrometer for metrics collection and performance monitoring

Quick Start

Add Dependency

<dependency>
    <groupId>org.springframework.ai.moonshot</groupId>
    <artifactId>moonshot-core</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</dependency>

Basic Usage

// Create the Moonshot API client
MoonshotApi moonshotApi = new MoonshotApi("your-api-key");

// Create the chat model
MoonshotChatModel chatModel = new MoonshotChatModel(moonshotApi);

// Create a prompt
UserMessage userMessage = new UserMessage("Tell me a joke about programming");
Prompt prompt = new Prompt(List.of(userMessage));

// Get the response
ChatResponse response = chatModel.call(prompt);
String content = response.getResult().getOutput().getContent();
System.out.println(content);

Project Structure

This is a multi-module Maven project:
  • moonshot-parent - Parent POM with dependency management
  • moonshot-core - Core implementation of the Moonshot AI client
  • docs - Documentation module built with Antora

Requirements

  • Java 17 or higher
  • Maven 3.6.3 or higher

Resources

GitHub Repository

View source code and contribute

Documentation

Full documentation (will be published to GitHub Pages)

License

This project is licensed under the Apache License 2.0.