Anthropic Claude AI
将 Anthropic Claude AI 模型集成到 Delphi 应用程序中。支持 Claude 3.5 Sonnet、Haiku 和 Opus 的对话完成功能。
将 Anthropic Claude AI 模型集成到 Delphi 应用程序中。支持 Claude 3.5 Sonnet、Haiku 和 Opus 的对话完成功能。
用于 Claude 消息、文件、批处理和令牌计数的 Anthropic REST API 客户端。
TsgcHTTP_API_Anthropic
Anthropic REST API over HTTPS
Windows, macOS, Linux, iOS, Android
Enterprise(AI 附加模块)
在 AnthropicOptions 中设置 API 密鑰,然后调用类型化辅助方法(如 _CreateMessage),或构建 TsgcAnthropicClass_Request_Messages 并调用 CreateMessage。
uses
sgcHTTP_API_Anthropic;
var
Anthropic: TsgcHTTP_API_Anthropic;
begin
Anthropic := TsgcHTTP_API_Anthropic.Create(nil);
Anthropic.AnthropicOptions.ApiKey := 'sk-ant-...';
Anthropic.AnthropicOptions.AnthropicVersion := '2023-06-01';
// Simple one-shot message
Memo1.Lines.Text := Anthropic._CreateMessage(
'claude-3-5-sonnet-latest',
'What are the benefits of WebSockets?',
4096);
// Streaming — handle OnHTTPAPISSE per delta
Anthropic.OnHTTPAPISSE := HandleSSE;
Anthropic._CreateMessageStream(
'claude-3-5-sonnet-latest',
'Summarise RFC 6455',
1024);
end;
procedure TForm1.HandleSSE(Sender: TObject;
const aEvent, aData: string;
var Cancel: Boolean);
begin
Memo1.Lines.Add(aEvent + ': ' + aData);
end;
// uses: sgcHTTP_API_Anthropic
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(this);
Anthropic->AnthropicOptions->ApiKey = "sk-ant-...";
Anthropic->AnthropicOptions->AnthropicVersion = "2023-06-01";
// Simple one-shot message
Memo1->Lines->Text = Anthropic->_CreateMessage(
"claude-3-5-sonnet-latest",
"What are the benefits of WebSockets?",
4096);
// Streaming — OnHTTPAPISSE fires per delta
Anthropic->OnHTTPAPISSE = HandleSSE;
Anthropic->_CreateMessageStream(
"claude-3-5-sonnet-latest",
"Summarise RFC 6455",
1024);
using esegece.sgcWebSockets;
var anthropic = new TsgcHTTPAPI_Anthropic();
anthropic.AnthropicOptions.ApiKey = "sk-ant-...";
anthropic.AnthropicOptions.AnthropicVersion = "2023-06-01";
// Simple one-shot message
Console.WriteLine(anthropic._CreateMessage(
"claude-3-5-sonnet-latest",
"What are the benefits of WebSockets?",
4096));
// Streaming via Server-Sent Events
anthropic.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
anthropic._CreateMessageStream(
"claude-3-5-sonnet-latest",
"Summarise RFC 6455",
1024);
5 个属性、7 个公共方法和 2 个事件。针对消息、文件和批处理的类型化请求/响应类。
CreateMessage 发送类型化的 TsgcAnthropicClass_Request_Messages 并返回解析后的响应。_CreateMessage、_CreateMessageWithSystem、_CreateMessageStream 和 _CreateMessageWithThinking 是 JSON 字符串快捷方式。
辅助方法 _CreateVisionMessage(图像 base64)、_CreateDocumentMessage(PDF base64)和 _CreateMessageWithWebSearch 封装了多模态和 Claude 服务端工具。
构建 TsgcAnthropicClass_Request_Tool 条目,将函数调用工具暴露给 Claude。_CreateMessageJSON 应用内联 JSON 模式以获得结构化输出。
UploadFile、ListFiles、DeleteFile 以及辅助方法 _GetFile、_DownloadFile 通过 Anthropic Files 端点管理附件。
ListBatches、CancelBatch 以及辅助方法 _GetBatch、_GetBatchResults 驱动消息批处理工作流,用于大批量离线处理。
CircuitBreaker 在 API 不健康时断路请求;ReadTimeout 和 TLSOptions 调整 HTTPS 层;OnHTTPAPIException 显示错误;OnHTTPAPISSE 流式传输服务端事件。
本组件所实现协议的权威参考来源。