OpenAIProvider class
OpenAI Provider implementation
This provider uses a modular architecture inspired by async-openai. Instead of a monolithic class, capabilities are implemented in separate modules and composed together in this main provider class.
Benefits of this approach:
- Single Responsibility: Each module handles one capability
- Easier Testing: Modules can be tested independently
- Better Maintainability: Changes to one capability don't affect others
- Cleaner Code: Smaller, focused classes instead of one giant class
- Reusability: Modules can be reused across different provider implementations
Constructors
- OpenAIProvider.new(OpenAIConfig config)
Properties
- client → OpenAIClient
-
Get the underlying client for advanced usage
no setter
- config → OpenAIConfig
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- providerName → String
-
no setter
- responses → OpenAIResponses?
-
Get the Responses API module (only available when useResponsesAPI is enabled)
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedCapabilities
→ Set<
LLMCapability> -
Set of capabilities this provider supports
no setteroverride
-
supportedFeatures
→ Set<
AudioFeature> -
Get all audio features supported by this provider
no setteroverride
- supportsImageEditing → bool
-
Check if the provider supports image editing
no setteroverride
- supportsImageVariations → bool
-
Check if the provider supports image variations
no setteroverride
Methods
-
chat(
List< ChatMessage> messages) → Future<ChatResponse> -
Sends a chat request to the provider with a sequence of messages.
override
-
chatStream(
List< ChatMessage> messages, {List<Tool> ? tools}) → Stream<ChatStreamEvent> -
Sends a streaming chat request to the provider
override
-
chatWithTools(
List< ChatMessage> messages, List<Tool> ? tools) → Future<ChatResponse> -
Sends a chat request to the provider with a sequence of messages and tools.
override
-
checkModel(
) → Future< ({String? error, bool valid})> - Check if a model is valid and accessible
-
complete(
CompletionRequest request) → Future< CompletionResponse> -
Sends a completion request to generate text
override
-
createAssistant(
CreateAssistantRequest request) → Future< Assistant> -
Create an assistant
override
-
createVariation(
ImageVariationRequest request) → Future< ImageGenerationResponse> -
Create variations of an existing image
override
-
deleteAssistant(
String assistantId) → Future< DeleteAssistantResponse> -
Delete an assistant
override
-
deleteFile(
String fileId) → Future< FileDeleteResponse> -
Delete a file
override
-
editImage(
ImageEditRequest request) → Future< ImageGenerationResponse> -
Edit an existing image based on a prompt
override
-
embed(
List< String> input) → Future<List< List< >double> > -
Generate embeddings for the given input texts
override
-
generateImage(
{required String prompt, String? model, String? negativePrompt, String? imageSize, int? batchSize, String? seed, int? numInferenceSteps, double? guidanceScale, bool? promptEnhancement}) → Future< List< String> > -
Simple image generation (convenience method)
override
-
generateImages(
ImageGenerationRequest request) → Future< ImageGenerationResponse> -
Generate images from text prompts
override
-
generateSuggestions(
List< ChatMessage> messages) → Future<List< String> > - Generate suggestions for follow-up questions
-
getEmbeddingDimensions(
) → Future< int> - Get embedding dimensions for the configured model
-
getFileContent(
String fileId) → Future< List< int> > -
Get file content
override
-
getSupportedAudioFormats(
) → List< String> -
Get supported input/output audio formats
override
-
getSupportedFormats(
) → List< String> -
Get supported response formats for this provider
override
-
getSupportedLanguages(
) → Future< List< LanguageInfo> > -
Get supported languages for transcription and translation
override
-
getSupportedSizes(
) → List< String> -
Get supported image sizes for this provider
override
-
getVoices(
) → Future< List< VoiceInfo> > -
Get available voices for this provider
override
-
listAssistants(
[ListAssistantsQuery? query]) → Future< ListAssistantsResponse> -
List assistants
override
-
listFiles(
[FileListQuery? query]) → Future< FileListResponse> -
List files
override
-
memoryContents(
) → Future< List< ChatMessage> ?> -
Get current memory contents if provider supports memory
override
-
models(
) → Future< List< AIModel> > -
Get available models from the provider
override
-
moderate(
ModerationRequest request) → Future< ModerationResponse> -
Moderate content for policy violations
override
-
modifyAssistant(
String assistantId, ModifyAssistantRequest request) → Future< Assistant> -
Modify an assistant
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
retrieveAssistant(
String assistantId) → Future< Assistant> -
Retrieve an assistant
override
-
retrieveFile(
String fileId) → Future< FileObject> -
Retrieve file metadata
override
-
speech(
String text) → Future< List< int> > -
Simple text-to-speech conversion (convenience method)
override
-
speechStream(
String text) → Stream< List< int> > -
Simple streaming text-to-speech conversion (convenience method)
override
-
speechToText(
STTRequest request) → Future< STTResponse> -
Convert speech to text with full configuration support
override
-
startRealtimeSession(
RealtimeAudioConfig config) → Future< RealtimeAudioSession> -
Create and start a real-time audio session
override
-
summarizeHistory(
List< ChatMessage> messages) → Future<String> -
Summarizes a conversation history into a concise 2-3 sentence summary
override
-
supports(
LLMCapability capability) → bool -
Check if this provider supports a specific capability
override
-
textToSpeech(
TTSRequest request) → Future< TTSResponse> -
Convert text to speech with full configuration support
override
-
textToSpeechStream(
TTSRequest request) → Stream< AudioStreamEvent> -
Convert text to speech with streaming output
override
-
toString(
) → String -
A string representation of this object.
override
-
transcribe(
List< int> audio) → Future<String> -
Simple audio transcription (convenience method)
override
-
transcribeFile(
String filePath) → Future< String> -
Simple file transcription (convenience method)
override
-
translate(
List< int> audio) → Future<String> -
Simple audio translation (convenience method)
override
-
translateAudio(
AudioTranslationRequest request) → Future< STTResponse> -
Translate audio to English text
override
-
translateFile(
String filePath) → Future< String> -
Simple file translation (convenience method)
override
-
uploadFile(
FileUploadRequest request) → Future< FileObject> -
Upload a file
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited