Skip to content

Commit 988dc3d

Browse files
DevDesai444sanchitmonga22
authored andcommitted
Add Flutter LLM configuration validation model
1 parent b81095e commit 988dc3d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:runanywhere/core/protocols/component/component_configuration.dart';
2+
import 'package:runanywhere/core/types/model_types.dart';
3+
import 'package:runanywhere/foundation/error_types/sdk_error.dart';
4+
5+
/// Configuration for the LLM component.
6+
///
7+
/// Mirrors the validation contract used by the Swift and Kotlin SDKs so
8+
/// invalid parameters fail in Dart before crossing the FFI boundary.
9+
class LLMConfiguration implements ComponentConfiguration {
10+
final String? modelId;
11+
final InferenceFramework? preferredFramework;
12+
final int contextLength;
13+
final double temperature;
14+
final int maxTokens;
15+
final String? systemPrompt;
16+
final bool streamingEnabled;
17+
18+
const LLMConfiguration({
19+
this.modelId,
20+
this.preferredFramework,
21+
this.contextLength = 2048,
22+
this.temperature = 0.7,
23+
this.maxTokens = 100,
24+
this.systemPrompt,
25+
this.streamingEnabled = true,
26+
});
27+
28+
@override
29+
void validate() {
30+
if (contextLength <= 0 || contextLength > 32768) {
31+
throw SDKError.validationFailed(
32+
'Context length must be between 1 and 32768',
33+
);
34+
}
35+
36+
if (!temperature.isFinite || temperature < 0 || temperature > 2.0) {
37+
throw SDKError.validationFailed(
38+
'Temperature must be between 0 and 2.0',
39+
);
40+
}
41+
42+
if (maxTokens <= 0 || maxTokens > contextLength) {
43+
throw SDKError.validationFailed(
44+
'Max tokens must be between 1 and context length',
45+
);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)