GroqChat class

Constructors

GroqChat(String _model, String _apiKey, GroqChatSettings _settings)
GroqChat constructor model the model id apiKey the api key settings the chat settings
GroqChat.fromJson(Map<String, dynamic> json, dynamic Function(Map<String, dynamic>) functionNameToFunction(String))
Creates a GroqChat instance from a JSON object.

Properties

allMessages List<GroqConversationItem>
Returns a list of all messages in the conversation It is a list of GroqConversationItem objects and switches from request to response Example:
no setter
allMessagesContent List<String>
Returns a list of all messages content in the conversation It is a list of strings and switches from request to response Example:
no setter
hashCode int
The hash code for this object.
no setterinherited
latestResponse GroqResponse?
Returns the latest response in the conversation
no setter
latestUsage GroqUsage?
Returns the latest resource usage in the conversation
no setter
messages List<ChatEvent>
Returns a list of all messages in the conversation It is a list of ChatEvents, which can either be requests or responses
no setter
model String
Returns the model id
no setter
rateLimitInfo GroqRateLimitInformation?
Returns the rate limit information
no setter
registeredTools List<GroqToolItem>
Returns the registered tools in the chat Example:
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
settings GroqChatSettings
Returns the current chat settings
no setter
stream Stream<ChatEvent>
Returns the chat as a stream Example:
no setter
totalTokens int
Returns the total tokens used in the conversation
no setter
userMessageContents List<String>
Returns a List of Strings of all messages between the user and the model Assistant messages and tool use messages are not included Example:
no setter

Methods

addMessageWithoutSending(String prompt, {GroqMessageRole role = GroqMessageRole.assistant}) → void
Adds a new message to the chat without sending it to the model or expecting a response. This is useful for assistant messages or passive instructions to the model. prompt the message content role the message role, usually assistant Example:
dispose() → void
Closes the stream
getToolCallable(GroqToolCall toolCall) Function
Validates and returns the registered tool function with the given arguments. toolCall the tool call usually returned from the GroqMessage object. returns the callable function, if the tool is registered. Throws an exception if the tool is not found.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerTool(GroqToolItem tool) → void
Registers a tool to the chat, which always can be called by the model. tool the tool to register Example:
registerTools(List<GroqToolItem> tools) → void
Registers multiple tools to the chat tools the tools to register
sendMessage(String prompt, {GroqMessageRole role = GroqMessageRole.user, String? username, bool expectJSON = false}) Future<(GroqResponse, GroqUsage)>
Sends a new request message to the chat prompt the message content role the message role DO NOT USE assistant, it is reserved for the AI username the username of the message sender (optional) expectJSON whether to expect a JSON response or not. You need to explain the JSON structure in the prompt for this feature Returns a tuple of the response and the resource usage Example:
setTools(List<GroqToolItem> tools) → void
Clears all registered tools from the chat and registers the new tools Example:
switchModel(String modelId) → void
Switches the model of the current conversation dynamically modelId the new model id It is also possible to switch the model during the conversation Example:
switchSettings(GroqChatSettings settings) → void
Switches the settings of the current conversation dynamically settings the new chat settings It is also possible to switch the settings during the conversation Example:
toJson() Map<String, dynamic>
Converts the GroqChat object into a JSON-compatible Map<String, dynamic>.
toString() String
A string representation of this object.
inherited
unregisterTool(String toolName) → void
Unregisters a tool from the chat toolName the name of the tool to unregister Example:

Operators

operator ==(Object other) bool
The equality operator.
inherited