AI Classes

Sources: source/classes/topenai.prg, source/classes/tdeepseek.prg, source/classes/tgemini.prg, source/classes/tollama.prg

FiveWin provides a unified set of AI/LLM classes that integrate with popular cloud AI providers and local models. All classes follow the same basic pattern: instantiate with an API key (or model name for local), send a prompt, and extract the response. They use Harbour's hb_curl library for HTTPS communication with the respective API endpoints.

For the complete AI documentation including all class members and extended examples, see TOpenAI / TChatGPT — that page documents every AI class with full reference tables, code samples, and a comparison guide.

Common Pattern

All AI classes share this basic workflow:

// 1. Create instance with API key (or model name for local)
oAI := TSomeAI():New( cApiKey )

// 2. Send a prompt
oAI:Send( "Your question here" )

// 3. Extract the response text
cAnswer := oAI:GetValue()

// 4. Clean up
oAI:End()

Class Reference

TOpenAI

Fuente: source/classes/topenai.prg

OpenAI ChatGPT integration. Supports text, vision (image analysis), and streaming responses.

DATADefaultDescription
cKeyOPENAI_API_KEY envOpenAI API key
cModelgpt-4o-miniModel name (e.g. gpt-4o, gpt-4o-mini)
nTemperature0.5Sampling temperature (0.0 to 2.0)
cResponseRaw JSON response from API
MethodParametersDescription
New()cKey, cModelConstructor. Reads env var if cKey empty.
Send()cPromptSend text prompt, return raw JSON
SendStream()cPrompt, bCallbackStreaming response via callback
SendImage()cImageFile, cPromptVision: analyze a local image
SendImageURL()cImageUrl, cPromptVision: analyze image from URL
GetValue()Extract text from JSON response

TDeepSeek

Fuente: source/classes/tdeepseek.prg

DeepSeek AI integration. Known for strong coding and reasoning capabilities.

DATADefaultDescription
cKeyDEEPSEEK_API_KEY envDeepSeek API key
cModeldeepseek-chatModel: deepseek-chat or deepseek-reasoner
MethodParametersDescription
New()cKey, cModelConstructor
Send()cPromptSend prompt, return raw JSON
GetValue()Extract text from JSON response
local oAI := TDeepSeek():New( "sk-deepseek-key" )
oAI:Send( "Write a Harbour function for binary search" )
MsgInfo( oAI:GetValue() )
oAI:End()

TGemini

Fuente: source/classes/tgemini.prg

Google Gemini integration. Supports text, images, file uploads, and streaming.

DATADefaultDescription
cKeyGEMINI_API_KEY envGoogle API key
cModelgemini-2.0-flashModel name
nTemperature0Response creativity (0-2)
MethodParametersDescription
New()cKey, cModelConstructor
Send()uContent, cPrompt, bCallbackSend text, image file, or array of files with prompt
UploadFile()cFileName, lDeleteAfterUpload file to Gemini for analysis
GetValue()Extract text from JSON response
local oAI := TGemini():New( "google-api-key" )

// Text prompt
oAI:Send( "Explain quantum computing in simple terms" )
MsgInfo( oAI:GetValue() )

// Image analysis
oAI:Send( "C:\photos\chart.png", "Describe this chart" )
MsgInfo( oAI:GetValue() )

oAI:End()

TOLlama (Local AI)

Fuente: source/classes/tollama.prg

Local LLM integration via Ollama. No API key needed — runs models on your own machine. Default model: deepseek-r1:14b.

DATADefaultDescription
cModeldeepseek-r1:14bOllama model name
cUrlhttp://localhost:11434/api/chatOllama server endpoint
MethodParametersDescription
New()cModelConstructor. Default model: deepseek-r1:14b.
Send()cPromptSend prompt, return raw JSON
SendStream()cPrompt, bCallbackStreaming response via callback
SendImage()cImageFile, cPromptVision for multimodal models (e.g. llava)
GetValue()Extract message content from JSON
// Local AI - no API key needed
local oAI := TOLlama():New( "llama3" )
oAI:Send( "What is FiveWin?" )
MsgInfo( oAI:GetValue() )

// Streaming response
oAI:SendStream( "Write a poem", {|c| QOut(c)} )

// Image analysis (vision model)
oAI:SendImage( "photo.jpg", "What do you see?" )

oAI:End()

API Key Configuration

Each cloud AI class reads its API key from a specific environment variable when no key is passed to New():

ClassEnvironment VariableBase URL
TOpenAIOPENAI_API_KEYhttps://api.openai.com/v1
TDeepSeekDEEPSEEK_API_KEYhttps://api.deepseek.com
TGeminiGEMINI_API_KEYhttps://generativelanguage.googleapis.com
TOLlamaNot needed (local)http://localhost:11434

Tips

Ver También