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
| Provider | Model Examples | Features |
|---|---|---|
| OpenAI | GPT-4, GPT-3.5 | World-leading LLM |
| Azure OpenAI | GPT-4 | Enterprise deployment |
| Claude | Claude 3 | Long-text understanding |
| Gemini | Gemini Pro | Multimodal capabilities |
| Ollama | Llama, Mistral | Local deployment |
Domestic Providers
| Provider | Model Examples | Features |
|---|---|---|
| Qwen (Alibaba) | Tongyi Qianwen | Chinese-optimized |
| Qianfan (Baidu) | ERNIE Bot | Chinese-optimized |
| Zhipu AI | ChatGLM | Chinese-optimized |
| DeepSeek | DeepSeek-V2 | High cost-effectiveness |
| Spark (iFlytek) | Spark | Chinese-optimized |
| Yi (01.AI) | Yi-Large | Long text |
| Douyin (ByteDance) | Doubao | Chinese-optimized |
| Gitee AI | Various models | Open-source models |
| Silicon | Various models | Open-source models |
| MiMo | MiMo | Chinese-optimized |
Model Types
CHAT - Text Chat
Used for multi-turn conversations, Q&A, content generation, and similar scenarios.
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.
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.
ImageModel model = modelStoreFactory.createImageModel(provider, modelName);
byte[] image = model.generate("A cute cat");WEB_SEARCH - Web Search
Used for real-time web search scenarios.
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:
public interface ModelBuildHandler {
ChatModel buildChatModel(LLMModelConfig config);
EmbeddingModel buildEmbeddingModel(LLMModelConfig config);
// ...
}Factory Pattern
Model instances are created uniformly through ModelStoreFactory:
@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:
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
// 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
// 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
// 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
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: EMBEDDINGOllama Local Configuration
llm:
providers:
ollama:
base-url: http://localhost:11434
models:
- name: llama3
type: CHAT
- name: nomic-embed-text
type: EMBEDDING