OpenAI GPT-4, DALL-E, Whisper
将 OpenAI GPT-4、DALL-E 和 Whisper API 集成到 Delphi 应用程序中。支持对话完成、图像生成和语音转文字。
将 OpenAI GPT-4、DALL-E 和 Whisper API 集成到 Delphi 应用程序中。支持对话完成、图像生成和语音转文字。
OpenAI REST 客户端 — 对话完成、响应、图像、音频(TTS / Whisper)、嵌入、文件、微调、审核、助手和线程。
TsgcHTTP_API_OpenAI
OpenAI REST API over HTTPS
Windows, macOS, Linux, iOS, Android
Enterprise(AI 附加模块)
在 OpenAIOptions 中设置 ApiKey,然后调用类型化的 Create*() 方法或单行辅助方法(如 _CreateChatCompletion)。
uses
sgcHTTP_API_OpenAI;
var
OpenAI: TsgcHTTP_API_OpenAI;
begin
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'sk-...';
// One-shot chat completion (returns the raw JSON body)
Memo1.Lines.Text := OpenAI._CreateChatCompletion(
'gpt-4o-mini', 'Hello, world.');
// Other one-liners ship out of the box:
OpenAI._CreateEmbeddings('text-embedding-3-small', 'sgcWebSockets rocks');
OpenAI._CreateImage('a delphi-blue rubber duck');
OpenAI._CreateModeration('be nice');
// Streaming: build a typed Request, set Stream := True, hook OnHTTPAPISSE
OpenAI.OnHTTPAPISSE := HandleSSE;
end;
procedure TForm1.HandleSSE(Sender: TObject;
const aEvent, aData: string;
var Cancel: Boolean);
begin
Memo1.Lines.Add(aData);
end;
using esegece.sgcWebSockets;
var openai = new TsgcHTTPAPI_OpenAI();
openai.OpenAIOptions.ApiKey = "sk-...";
// One-shot chat completion (raw JSON body)
Console.WriteLine(openai._CreateChatCompletion("gpt-4o-mini", "Hello, world."));
// Streamed responses surface through OnHTTPAPISSE
openai.OnHTTPAPISSE += (s, ev, data, c) => Console.Write(data);
5 个发布属性、78 个方法、2 个事件 — 来自组件参考。
Published properties: CircuitBreaker.
Published properties: ReadTimeout, TLSOptions.
Published properties: OpenAIOptions.
Published properties: Version.
Methods: CreateChatCompletion, CreateCompletion, CreateEdit.
Methods: CreateResponse, RetrieveResponse, DeleteResponse.
本组件所实现协议的权威参考来源。