providers/xai/xai library
Modular xAI Provider
This library provides a modular implementation of the xAI provider following the same architecture pattern as the OpenAI provider.
Key Features:
- Grok models with real-time search capabilities
- Reasoning and thinking support
- Modular architecture for easy maintenance
- Support for structured outputs
- Search parameters for web and news sources
Usage:
import 'package:llm_dart/providers/xai/xai.dart';
final provider = XAIProvider(XAIConfig(
apiKey: 'your-api-key',
model: 'grok-3',
));
// Use chat capability
final response = await provider.chat(messages);
// Use search with Grok
final searchConfig = XAIConfig(
apiKey: 'your-api-key',
model: 'grok-3',
searchParameters: SearchParameters(
mode: 'auto',
sources: [SearchSource(sourceType: 'web')],
),
);
final searchProvider = XAIProvider(searchConfig);
final searchResponse = await searchProvider.chat([
ChatMessage.user('What are the latest developments in AI?')
]);
Classes
- SearchParameters
- Search parameters for LLM providers that support search functionality
- SearchSource
- Search source configuration for search parameters
- XAIChat
- xAI Chat capability implementation
- XAIChatResponse
- xAI chat response implementation
- XAIClient
- Core xAI HTTP client shared across all capability modules
- XAIConfig
- xAI provider configuration
- XAIEmbedding
- xAI Embedding capability implementation
- XAIEmbeddingData
- Embedding data from xAI API
- XAIEmbeddingResponse
- Embedding response from xAI API
- XAIProvider
- xAI Provider implementation
Functions
-
createGrokVisionProvider(
{required String apiKey, String model = 'grok-vision-beta', double? temperature, int? maxTokens, String? systemPrompt}) → XAIProvider - Create an xAI provider for Grok Vision
-
createXAILiveSearchProvider(
{required String apiKey, String model = 'grok-3', double? temperature, int? maxTokens, String? systemPrompt, int? maxSearchResults, List< String> ? excludedWebsites}) → XAIProvider - Create an xAI provider with Live Search enabled
-
createXAIProvider(
{required String apiKey, String model = 'grok-3', String baseUrl = 'https://api.x.ai/v1/', double? temperature, int? maxTokens, String? systemPrompt, SearchParameters? searchParameters, bool? liveSearch}) → XAIProvider - Create an xAI provider with default settings
-
createXAISearchProvider(
{required String apiKey, String model = 'grok-3', double? temperature, int? maxTokens, String? systemPrompt, String searchMode = 'auto', List< SearchSource> ? sources, int? maxSearchResults, String? fromDate, String? toDate}) → XAIProvider - Create an xAI provider with search capabilities