Ollama 本地 LLM
从您的 Delphi、C++ Builder 和 .NET 应用程序在本地运行开源大语言模型。推理保持私密、离线和本地化,在您自己的硬件上执行,无需云端 API。
从您的 Delphi、C++ Builder 和 .NET 应用程序在本地运行开源大语言模型。推理保持私密、离线和本地化,在您自己的硬件上执行,无需云端 API。
用于本地对话完成、嵌入和模型管理的 Ollama REST API 客户端。
TsgcHTTP_API_Ollama
Ollama REST API over HTTP
Windows, macOS, Linux, iOS, Android
Enterprise(AI 附加模块)
Ollama 在本地运行,无需 API 密钥。将 OllamaOptions.BaseUrl 设置为您的本地服务器(默认 http://localhost:11434/api),然后调用 _CreateMessage,或构建 TsgcOllamaClass_Request_ChatCompletion 并调用 CreateMessage。
uses
sgcHTTP_API_Ollama;
var
Ollama: TsgcHTTP_API_Ollama;
begin
Ollama := TsgcHTTP_API_Ollama.Create(nil);
// Local server, no API key needed
Ollama.OllamaOptions.BaseUrl := 'http://localhost:11434/api';
// Simple one-shot message
Memo1.Lines.Text := Ollama._CreateMessage(
'llama3',
'What are the benefits of WebSockets?');
// Streaming — handle OnHTTPAPISSE per chunk
Ollama.OnHTTPAPISSE := HandleSSE;
Ollama._CreateMessageStream(
'llama3',
'Summarise RFC 6455');
end;
procedure TForm1.HandleSSE(Sender: TObject;
const aEvent, aData: string;
var Cancel: Boolean);
begin
Memo1.Lines.Add(aEvent + ': ' + aData);
end;
// uses: sgcHTTP_API_Ollama
TsgcHTTP_API_Ollama *Ollama = new TsgcHTTP_API_Ollama(this);
// Local server, no API key needed
Ollama->OllamaOptions->BaseUrl = "http://localhost:11434/api";
// Simple one-shot message
Memo1->Lines->Text = Ollama->_CreateMessage(
"llama3",
"What are the benefits of WebSockets?");
// Streaming — OnHTTPAPISSE fires per chunk
Ollama->OnHTTPAPISSE = HandleSSE;
Ollama->_CreateMessageStream(
"llama3",
"Summarise RFC 6455");
using esegece.sgcWebSockets;
var ollama = new TsgcHTTPAPI_Ollama();
// Local server, no API key needed
ollama.OllamaOptions.BaseUrl = "http://localhost:11434/api";
// Simple one-shot message
Console.WriteLine(ollama._CreateMessage(
"llama3",
"What are the benefits of WebSockets?"));
// Streaming via Server-Sent Events
ollama.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
ollama._CreateMessageStream(
"llama3",
"Summarise RFC 6455");
针对对话完成和嵌入的类型化请求/响应类,外加模型管理和基于 Server-Sent Events 的流式传输。
CreateMessage 发送类型化的 TsgcOllamaClass_Request_ChatCompletion 并返回解析后的响应。_CreateMessage、_CreateMessageWithSystem 和 _CreateMessageStream 是字符串快捷方式,流式增量通过 OnHTTPAPISSE 交付。
CreateEmbeddings 使用本地拉取的嵌入模型(如 nomic-embed-text 或 mxbai-embed-large)将输入文本转换为密集向量,返回 TsgcOllamaClass_Response_Embeddings。
管理您机器上的模型:_GetModels 和 _GetTags 列出可用模型,_ShowModel 读取模型详情,_PullModel 从 Ollama 库下载,_DeleteModel 移除本地模型。
每个请求都指向本地 Ollama 服务器(默认 http://localhost:11434/api),因此没有数据离开您的网络,也无需 API 密钥。在需要时,可将 OllamaOptions.BaseUrl 指向远程或容器化实例。
CircuitBreaker 在服务器不健康时断路请求;ReadTimeout 和 TLSOptions 调整 HTTP/HTTPS 层;OnHTTPAPIException 显示故障;OnHTTPAPISSE 流式传输服务端事件。
本组件所实现协议的权威参考来源。