OpenAICompatibleChatModel class
A ChatModel for any OpenAI-compatible chat-completions server.
- Implemented types
Constructors
-
OpenAICompatibleChatModel({required Uri baseUrl, required String model, String? apiKey, int? maxTokens, String maxTokensField = 'max_tokens', Map<
String, Object?> extraBody = const {}, Map<String, String> headers = const {}, Duration timeout = const Duration(minutes: 10), int maxRetries = 2, HttpClient? httpClient}) - Creates a client.
- OpenAICompatibleChatModel.gemini({required String apiKey, required String model, int? maxTokens})
-
Google Gemini through its OpenAI-compatible endpoint.
factory
- OpenAICompatibleChatModel.ollama({required String model, Uri? host, int? maxTokens})
-
A local Ollama server.
factory
- OpenAICompatibleChatModel.openAI({required String apiKey, required String model, int? maxTokens})
-
OpenAI's API.
factory
Properties
- apiKey → String?
-
Bearer token;
nullfor local servers that need none.final - baseUrl → Uri
-
API root, e.g.
https://api.openai.com/v1orhttp://localhost:11434/v1.final -
extraBody
→ Map<
String, Object?> -
Extra body fields (e.g.
temperature,reasoning_effort).final - hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
Extra headers.
final
- maxTokens → int?
-
Output limit, or
nullfor the server default.final - maxTokensField → String
-
Name of the output-limit field (
max_tokens, ormax_completion_tokensfor OpenAI reasoning models).final - model → String
-
Model identifier sent to the provider.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → void -
Releases network resources.
override
-
complete(
List< ChatMessage> messages, {String? system, int? maxTokens}) → Future<ChatResponse> -
Generates a complete response to
messages.override -
completeWithTools(
List< ChatMessage> messages, {String? system, int? maxTokens, List<Tool> tools = const []}) → Future<ChatResponse> -
Like ChatModel.complete, but the model may answer with
ChatResponse.toolCalls instead of (or as well as) text.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stream(
List< ChatMessage> messages, {String? system, int? maxTokens}) → Stream<String> -
Streams the response to
messagesas text deltas.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited