This repository is a C++17 multi-model chat access project that includes:
ai_chat_SDK: a unified C++ SDK for cloud LLMs and local Ollama modelsAIChatServer: an HTTP chat service built on top of the SDKChatServer/build/www: a browser-based frontend page served by the backend
It can be used either as a C++ SDK integration baseline or as a runnable chat service with HTTP APIs and a built-in frontend.
chat-sdk-access-ai-large-model/
├── AIModelAccess/
│ ├── sdk/
│ ├── ChatServer/
│ └── test/
├── docs/
│ └── diagrams/
├── README.md
└── README.en.md
The following diagram is generated from docs/diagrams/class-architecture.puml and shows the relationship between ChatSDK, session management, model management, and providers.
- Unified access to multiple LLM providers
- Session creation, lookup, listing, and deletion
- Message persistence
- Full-response mode via
sendMessage - Streaming-response mode via
sendMessageIncremental - SQLite-based local storage
- DeepSeek:
deepseek-chat - OpenRouter (OpenAI):
openai/gpt-4o-mini - OpenRouter (Gemini):
google/gemini-2.0-flash-001 - Local Ollama models, such as
gemma3:270m
GET /api/sessionsGET /api/modelsPOST /api/sessionGET /api/session/{id}/historyPOST /api/messagePOST /api/message/asyncDELETE /api/session/{id}- Static frontend hosting
- CMake >= 3.10
- A C++17 compiler
OpenSSLjsoncppfmtspdlogsqlite3gflagsforChatServergtestfortest
git clone https://gitee.com/zhibite-edu/ai-model-acess-tech.git
# or
git clone https://github.com/PinkMagicFly/Ai_Chat_SDK.git
cd chat-sdk-access-ai-large-modelIf you are using your own mirror or fork, replace the URL accordingly.
cd AIModelAccess/sdk
mkdir -p build
cd build
cmake ..
make -jTo install:
sudo make installDefault install paths:
- Static library:
/usr/local/lib - Headers:
/usr/local/include/ai_chat_SDK
cd AIModelAccess/ChatServer
mkdir -p build
cd build
cmake ..
make -jDefault output:
AIModelAccess/ChatServer/build/AIChatServer
export deepseek_apikey="your_deepseek_key"
export openrouter_apikey="your_openrouter_key"If you use local models:
ollama serve
ollama pull gemma3:270mIt is recommended to start the server from AIModelAccess/ChatServer/build:
cd AIModelAccess/ChatServer/build
./AIChatServerThe current static directory is configured as:
_chatServer->set_base_dir("./www");So the current working directory must contain ./www, otherwise the frontend root path will not be served correctly.
Default access URLs:
http://127.0.0.1:8807/http://127.0.0.1:8807/index.html
AIChatServer supports four levels of configuration priority:
- Command line flags
--config_fileconfig.confin the executable directory- Defaults / environment variables
Example config.conf:
--host=0.0.0.0
--port=8807
--log_level=INFO
--temperature=0.7
--max_tokens=2048
--ollama_model_name=gemma3:270m
--ollama_model_desc=Gemma 3 local model
--ollama_endpoint=http://localhost:11434Help and version:
./AIChatServer --help
./AIChatServer --versionHeader:
#include <ai_chat_SDK/ChatSDK.h>Current ChatSDK methods:
bool initializeSDK(const std::vector<std::shared_ptr<Config>>& configs)std::string createSession(const std::string& modelName)Session getSession(const std::string& sessionId)std::vector<std::string> getSessionLists() constbool deleteSession(const std::string& sessionId)std::vector<LLMInfo> getAvailableModels() conststd::string sendMessage(const std::string& sessionId, const std::string& message)std::string sendMessageIncremental(const std::string& sessionId, const std::string& message, callback)
Related data structures are defined in:
AIModelAccess/sdk/include/common.h
Including:
MessageConfigAPIConfigOllamaConfigLLMInfoSession
#include <iostream>
#include <memory>
#include <vector>
#include <cstdlib>
#include <ai_chat_SDK/ChatSDK.h>
int main() {
ai_chat_sdk::ChatSDK sdk;
auto deepseek = std::make_shared<ai_chat_sdk::APIConfig>();
deepseek->_modelName = "deepseek-chat";
deepseek->_apiKey = std::getenv("deepseek_apikey");
deepseek->_temperature = 0.7f;
deepseek->_max_tokens = 2048;
std::vector<std::shared_ptr<ai_chat_sdk::Config>> configs = {deepseek};
if (!sdk.initializeSDK(configs)) {
std::cerr << "initializeSDK failed" << std::endl;
return 1;
}
auto sessionId = sdk.createSession("deepseek-chat");
if (sessionId.empty()) {
std::cerr << "createSession failed" << std::endl;
return 1;
}
auto callback = [](const std::string& chunk, bool done) {
std::cout << chunk;
if (done) {
std::cout << "\n[done]" << std::endl;
}
};
auto full = sdk.sendMessageIncremental(sessionId, "Hello, please introduce yourself.", callback);
std::cout << "\nFull response: " << full << std::endl;
return 0;
}POST /api/session
Content-Type: application/json{
"model": "deepseek-chat"
}GET /api/sessionsGET /api/modelsGET /api/session/{session_id}/historyDELETE /api/session/{session_id}POST /api/message
Content-Type: application/json{
"session_id": "session_xxx",
"message": "Hello"
}POST /api/message/async
Content-Type: application/json{
"session_id": "session_xxx",
"message": "Hello"
}The streaming response is sent in SSE-style chunks, for example:
data: "first chunk"
data: "second chunk"
data: [DONE]
curl -s http://127.0.0.1:8807/api/modelscurl -s http://127.0.0.1:8807/api/session \
-H 'Content-Type: application/json' \
-d '{"model":"deepseek-chat"}'curl -s http://127.0.0.1:8807/api/sessionscurl -N http://127.0.0.1:8807/api/message/async \
-H 'Content-Type: application/json' \
-d '{"session_id":"session_xxx","message":"Please introduce yourself"}'Integration-style tests and usage examples are located in:
AIModelAccess/test/testLLM.cpp
Build them with:
cd AIModelAccess/test
mkdir -p build
cd build
cmake ..
make -j
./AIModelAccessTestBefore running tests, make sure:
- required environment variables are set
- target model services are reachable
- Ollama is running if local models are used
- Prefer environment variables for API keys; do not hardcode secrets
- For production use, consider adding auth, rate limiting, monitoring, and deployment automation
- If you only need embedding into your own application, you can use the SDK without starting
ChatServer
See LICENSE in the repository root.