NocAI class Null safety
The main NocLLM AI client for Dart & Flutter.
A lightweight, asynchronous client to interact with Large Language Models from both Cloud (OpenAI, Gemini, Groq, Sumopod) and Local APIs (LM Studio, Ollama).
Features
- SSE Streaming: Real-time token-by-token streaming via
stream() - Auto Provider Detection: Automatically detects Gemini Native from URL
- Dynamic Connection: Supports both HTTP (local) and HTTPS (cloud)
- Multi-Provider: Single API for OpenAI, Gemini, Groq, Sumopod, and local models
Usage
final ai = NocAI(
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://api.openai.com/v1',
model: 'gpt-3.5-turbo',
);
// Streaming
await for (final chunk in ai.stream('Hello!')) {
stdout.write(chunk);
}
// Non-streaming
final response = await ai.chat('Hello!');
print(response);
Constructors
- NocAI({required String apiKey, required String baseUrl, required String model, double? temperature, int? maxTokens, String? systemPrompt, Client? httpClient})
- Creates a NocAI client with a simple constructor matching C++ NocLLM.
- NocAI.fromConfig(NocAIConfig config, {Client? httpClient})
- Creates a NocAI client from an existing NocAIConfig.
Properties
- config → NocAIConfig
-
Gets the current configuration.
read-only
-
conversationHistory
→ List<
Map< String, String> > -
Gets the current conversation history.
read-only
- hashCode → int
-
The hash code for this object.
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
cancelStream(
) → void - Cancels any active streaming request.
-
chat(
String prompt, {bool addToHistory = true}) → Future< String> -
Sends a prompt and returns the complete response as a single
String. -
chatSync(
String prompt, {bool addToHistory = true}) → Future< String> - Sends a prompt without streaming and returns the full response.
-
clearHistory(
) → void - Clears the conversation history.
-
dispose(
) → void - Releases resources. Call when done with this client.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
stream(
String prompt, {bool addToHistory = true}) → Stream< String> - Sends a prompt and returns a Stream of text chunks (SSE streaming).
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited