OpenAI ChatBot Component — sgcAI | eSeGeCe

OpenAI ChatBot

TsgcAIOpenAIChatBot wires the whole voice loop into one component. It records the microphone, transcribes the audio with Whisper, sends the transcript to Chat Completions, optionally augments it with context from a vector store, and speaks the answer back.

TsgcAIOpenAIChatBot

A voice front-end over OpenAI Whisper and Chat Completions. Link an audio recorder, a text-to-speech component and, if you want retrieval augmented answers, an embeddings component, then call Start.

Component class

TsgcAIOpenAIChatBot

Purpose

Voice chatbot, end to end

Family

Chat & agents

Platforms

Win32 and Win64

sgcAI is self-contained. This component ships inside sgcAI together with the sgcWebSockets Core runtime it is built on, so there is no base license to buy.

A speaking assistant in one form

Drop a recorder, a text-to-speech component and the chatbot on a form, set the API key, call Start.

uses
  sgcAI, sgcAI_OpenAI_Audio_ChatBot,
  sgcAI_AudioRecorder_MCI, sgcAI_TextToSpeech_System;

var
  oBot: TsgcAIOpenAIChatBot;
begin
  oBot := TsgcAIOpenAIChatBot.Create(nil);
  oBot.OpenAIOptions.ApiKey := 'sk-...';
  oBot.AudioRecorder := sgcAudioRecorderMCI1;
  oBot.TextToSpeech  := sgcTextToSpeechSystem1;

  oBot.ChatBotOptions.Transcription.Model    := 'whisper-1';
  oBot.ChatBotOptions.Transcription.Language := 'en';
  oBot.ChatBotOptions.ChatCompletion.Model   := 'gpt-4o';

  oBot.OnTranscription  := BotTranscription;
  oBot.OnChatCompletion := BotChatCompletion;

  oBot.Start;   // Stop ends the session

  // A turn can also be pushed from code, no microphone involved.
  oBot.ChatAsUser('Summarise the last order in one line.');
end;

procedure TForm1.BotTranscription(Sender: TObject;
  var Text: string; var Accept: Boolean);
begin
  // Inspect or rewrite what Whisper heard, or drop the turn.
  Accept := Trim(Text) <> '';
end;
// includes: sgcAI.hpp, sgcAI_OpenAI_Audio_ChatBot.hpp

TsgcAIOpenAIChatBot *oBot = new TsgcAIOpenAIChatBot(NULL);
oBot->OpenAIOptions->ApiKey = "sk-...";
oBot->AudioRecorder = sgcAudioRecorderMCI1;
oBot->TextToSpeech  = sgcTextToSpeechSystem1;

oBot->ChatBotOptions->ChatCompletion->Model = "gpt-4o";
oBot->OnChatCompletion = BotChatCompletion;

oBot->Start();

// Push a turn without speaking.
oBot->ChatAsUser("Summarise the last order in one line.");

Key properties & methods

The members you reach for most often.

AudioRecorder supplies the microphone input, TextToSpeech speaks the answer, and Embeddings optionally supplies retrieved context from a vector store before the model is called.

ChatBotOptions

Transcription.Model and Transcription.Language configure the Whisper call. ChatCompletion.Enabled and ChatCompletion.Model configure the model that answers.

OpenAIOptions

API key, endpoint, HTTP, retry and logging settings for every call the component makes, including the Azure OpenAI variant.

Session

Start begins capture and Stop ends it. With the recorder in automatic mode the component restarts capture once the answer has finished playing, so the conversation keeps going hands free.

Programmatic turns

ChatAsUser injects a user message, ChatAsSystem injects a system message and can optionally speak it, and GetEmbedding looks up context for an arbitrary prompt.

Events

OnTranscription lets you edit or reject what Whisper heard before it reaches the model. OnChatCompletion reports the role and content of the answer. OnAudioStart and OnAudioStop track capture.

Specifications & references

Authoritative sources for the services and protocols this component uses.

Keep exploring

Online HelpFull API reference and usage guide for the sgcAI components.
All sgcAI ComponentsBrowse the full feature matrix of all 15 components.
Download Free TrialBuild a speaking assistant against your own OpenAI key.
PricingSingle, Team and Site licenses, full source code, no base product required.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and have a conversation with your application.