OpenAI API
Access ChatGPT, DALL-E, Whisper, and GPT models directly from your Delphi applications with full streaming support.
Access ChatGPT, DALL-E, Whisper, and GPT models directly from your Delphi applications with full streaming support.
Integrate AI-powered text generation, image creation, speech-to-text, and embeddings into your Delphi applications.
The sgcWebSockets OpenAI component provides native Delphi access to the full OpenAI API. Use GPT models for chat completions with streaming, generate images with DALL-E, transcribe audio with Whisper, and create vector embeddings for semantic search.
Send a chat completion request with streaming.
uses
sgcAI_OpenAI;
var
OpenAI: TsgcAI_OpenAI;
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenAI := TsgcAI_OpenAI.Create(nil);
OpenAI.ApiKey := 'sk-your-api-key';
OpenAI.OnChatCompletionStream := OnStream;
end;
procedure TForm1.SendChat;
begin
OpenAI.ChatCompletions.Model := 'gpt-4o';
OpenAI.ChatCompletions.AddMessageUser('Explain WebSockets in one paragraph.');
OpenAI.ChatCompletions.Stream := True;
OpenAI.CreateChatCompletions;
end;
procedure TForm1.OnStream(Sender: TObject;
aText: string);
begin
// Append streamed tokens to the memo
Memo1.Text := Memo1.Text + aText;
end;
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.