createXAILiveSearchProvider function
Create an xAI provider with Live Search enabled
This is a convenience function that enables Live Search with default web search settings. Live Search allows Grok models to access real-time information from the web.
Example:
final provider = createXAILiveSearchProvider(
apiKey: 'your-api-key',
model: 'grok-3',
maxSearchResults: 5,
);
final response = await provider.chat([
ChatMessage.user('What are the latest developments in AI?')
]);
Implementation
XAIProvider createXAILiveSearchProvider({
required String apiKey,
String model = 'grok-3',
double? temperature,
int? maxTokens,
String? systemPrompt,
int? maxSearchResults,
List<String>? excludedWebsites,
}) {
final config = XAIConfig(
apiKey: apiKey,
model: model,
temperature: temperature,
maxTokens: maxTokens,
systemPrompt: systemPrompt,
liveSearch: true,
searchParameters: SearchParameters.webSearch(
maxResults: maxSearchResults,
excludedWebsites: excludedWebsites,
),
);
return XAIProvider(config);
}