Mistral AI
将 Mistral AI 模型集成到 Delphi、C++ Builder 和 .NET 应用程序中。通过 Mistral REST API 实现对话完成、视觉、流式传输和嵌入。
将 Mistral AI 模型集成到 Delphi、C++ Builder 和 .NET 应用程序中。通过 Mistral REST API 实现对话完成、视觉、流式传输和嵌入。
用于对话完成、视觉、流式传输、嵌入和模型列举的 Mistral REST API 客户端。
TsgcHTTP_API_Mistral
Mistral REST API over HTTPS
Windows, macOS, Linux, iOS, Android
Enterprise(AI 附加模块)
在 MistralOptions 中设置 API 密钥,然后调用类型化辅助方法(如 _CreateMessage),或构建 TsgcMistralClass_Request_ChatCompletion 并调用 CreateMessage。
uses
sgcHTTP_API_Mistral;
var
Mistral: TsgcHTTP_API_Mistral;
begin
Mistral := TsgcHTTP_API_Mistral.Create(nil);
Mistral.MistralOptions.ApiKey := 'YOUR_API_KEY';
// Simple one-shot message
Memo1.Lines.Text := Mistral._CreateMessage(
'mistral-large-latest',
'What are the benefits of WebSockets?',
4096);
// Streaming — handle OnHTTPAPISSE per delta
Mistral.OnHTTPAPISSE := HandleSSE;
Mistral._CreateMessageStream(
'mistral-large-latest',
'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_Mistral
TsgcHTTP_API_Mistral *Mistral = new TsgcHTTP_API_Mistral(this);
Mistral->MistralOptions->ApiKey = "YOUR_API_KEY";
// Simple one-shot message
Memo1->Lines->Text = Mistral->_CreateMessage(
"mistral-large-latest",
"What are the benefits of WebSockets?",
4096);
// Streaming — OnHTTPAPISSE fires per delta
Mistral->OnHTTPAPISSE = HandleSSE;
Mistral->_CreateMessageStream(
"mistral-large-latest",
"Summarise RFC 6455");
using esegece.sgcWebSockets;
var mistral = new TsgcHTTPAPI_Mistral();
mistral.MistralOptions.ApiKey = "YOUR_API_KEY";
// Simple one-shot message
Console.WriteLine(mistral._CreateMessage(
"mistral-large-latest",
"What are the benefits of WebSockets?",
4096));
// Streaming via Server-Sent Events
mistral.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
mistral._CreateMessageStream(
"mistral-large-latest",
"Summarise RFC 6455");
针对对话完成和嵌入的类型化请求/响应类,外加 JSON 字符串快捷方式、视觉、流式传输和可靠性控制。
CreateMessage 发送类型化的 TsgcMistralClass_Request_ChatCompletion 并返回解析后的响应。_CreateMessage、_CreateMessageWithSystem 和 _CreateMessageStream 是 JSON 字符串快捷方式,_CreateMessageJSON 启用 JSON 模式以输出有效的 JSON。
_CreateVisionMessage 发送 base64 编码的图像和文本提示。媒体类型接受 image/jpeg、image/png、image/gif 和 image/webp,使模型能够理解图片。
_GetModels 列出所有可用的 Mistral 模型,使您能够在运行时发现并选择正确的模型,而无需硬编码标识符。
_CreateEmbeddings 使用诸如 mistral-embed 的模型返回输入文本的向量表示,可用于语义搜索、聚类和其他机器学习任务。
CircuitBreaker 在 API 不健康时断路请求;ReadTimeout 和 TLSOptions 调整 HTTPS 层;OnHTTPAPIException 显示故障;OnHTTPAPISSE 流式传输服务端事件。
本组件所实现协议的权威参考来源。