createXAILiveSearchProvider function

XAIProvider createXAILiveSearchProvider({
  1. required String apiKey,
  2. String model = 'grok-3',
  3. double? temperature,
  4. int? maxTokens,
  5. String? systemPrompt,
  6. int? maxSearchResults,
  7. List<String>? excludedWebsites,
})

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);
}