Skip to content

Multi-Model LLM Integration ​

NiteMoon AI Platform connects to 15+ mainstream large language models through a unified abstraction layer, supporting text chat, embedding generation, image generation, web search, and other model types, allowing users to leverage various LLM capabilities without worrying about underlying implementation details.

Key Features ​

  • 15+ LLM providers: Covering mainstream large models both domestically and internationally
  • 4 model types: CHAT, EMBEDDING, TEXT_IMAGE, WEB_SEARCH
  • Strategy pattern abstraction: Unified interface with dynamic switching
  • Dynamic model configuration: Database-driven configuration with no restart required

Supported LLM Providers ​

International Providers ​

ProviderModel ExamplesFeatures
OpenAIGPT-4, GPT-3.5World-leading LLM
Azure OpenAIGPT-4Enterprise deployment
ClaudeClaude 3Long-text understanding
GeminiGemini ProMultimodal capabilities
OllamaLlama, MistralLocal deployment

Domestic Providers ​

ProviderModel ExamplesFeatures
Qwen (Alibaba)Tongyi QianwenChinese-optimized
Qianfan (Baidu)ERNIE BotChinese-optimized
Zhipu AIChatGLMChinese-optimized
DeepSeekDeepSeek-V2High cost-effectiveness
Spark (iFlytek)SparkChinese-optimized
Yi (01.AI)Yi-LargeLong text
Douyin (ByteDance)DoubaoChinese-optimized
Gitee AIVarious modelsOpen-source models
SiliconVarious modelsOpen-source models
MiMoMiMoChinese-optimized

Model Types ​

CHAT - Text Chat ​

Used for multi-turn conversations, Q&A, content generation, and similar scenarios.

java
ChatModel model = modelStoreFactory.createChatModel(provider, modelName);
String response = model.generate("Hello, please introduce yourself");

EMBEDDING - Embedding Generation ​

Used for text vectorization, supporting RAG knowledge base, semantic search, and similar scenarios.

java
EmbeddingModel model = modelStoreFactory.createEmbeddingModel(provider, modelName);
float[] embedding = model.embed("This is a test text");

TEXT_IMAGE - Image Generation ​

Used for text-to-image generation scenarios.

java
ImageModel model = modelStoreFactory.createImageModel(provider, modelName);
byte[] image = model.generate("A cute cat");

Used for real-time web search scenarios.

java
WebSearchModel model = modelStoreFactory.createWebSearchModel(provider, modelName);
List<SearchResult> results = model.search("Today's weather");

Technical Implementation ​

Strategy Pattern ​

Each LLM provider has a corresponding ModelBuildHandler implementation:

java
public interface ModelBuildHandler {
    ChatModel buildChatModel(LLMModelConfig config);
    EmbeddingModel buildEmbeddingModel(LLMModelConfig config);
    // ...
}

Factory Pattern ​

Model instances are created uniformly through ModelStoreFactory:

java
@Component
public class ModelStoreFactory {
    public ChatModel createChatModel(String provider, String modelName) {
        ModelBuildHandler handler = getHandler(provider);
        LLMModelConfig config = loadConfig(modelName);
        return handler.buildChatModel(config);
    }
}

Dynamic Configuration ​

Model configurations are stored in the database and support dynamic updates:

sql
CREATE TABLE llm_model (
    id BIGINT PRIMARY KEY,
    provider VARCHAR(50),
    model_name VARCHAR(100),
    api_key VARCHAR(500),
    api_endpoint VARCHAR(500),
    config JSON
);

Use Cases ​

Intelligent Conversation ​

java
// Create chat model
ChatModel model = modelStoreFactory.createChatModel("openai", "gpt-4");

// Multi-turn conversation
ChatMemory memory = new MessageWindowChatMemory(10);
ChatAssistant assistant = AiServices.builder(ChatAssistant.class)
    .chatModel(model)
    .chatMemory(memory)
    .build();

String response = assistant.chat("Hello");

RAG Knowledge Base ​

java
// Create embedding model
EmbeddingModel embeddingModel = modelStoreFactory.createEmbeddingModel("openai", "text-embedding-3-small");

// Text vectorization
float[] embedding = embeddingModel.embed("This is a test text");

Content Generation ​

java
// Create image model
ImageModel imageModel = modelStoreFactory.createImageModel("openai", "dall-e-3");

// Generate image
byte[] image = imageModel.generate("A cute cat sitting on the moon");

Configuration Examples ​

OpenAI Configuration ​

yaml
llm:
  providers:
    openai:
      api-key: ${OPENAI_API_KEY}
      base-url: https://api.openai.com/v1
      models:
        - name: gpt-4
          type: CHAT
        - name: text-embedding-3-small
          type: EMBEDDING

Ollama Local Configuration ​

yaml
llm:
  providers:
    ollama:
      base-url: http://localhost:11434
      models:
        - name: llama3
          type: CHAT
        - name: nomic-embed-text
          type: EMBEDDING

Copyright © 2023-2026 nitemoon.cn All Rights Reserved