mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
Implemented SaveObject, LLMModel class & OllamaProvider
This commit is contained in:
48
packages/genai/lib/llm_saveobject.dart
Normal file
48
packages/genai/lib/llm_saveobject.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'llm_config.dart';
|
||||
import 'providers/common.dart';
|
||||
import 'providers/providers.dart';
|
||||
|
||||
class LLMSaveObject {
|
||||
String endpoint;
|
||||
String credential;
|
||||
LLMProvider provider;
|
||||
LLMModel selectedLLM;
|
||||
Map<String, LLMModelConfiguration> configMap;
|
||||
|
||||
LLMSaveObject({
|
||||
required this.endpoint,
|
||||
required this.credential,
|
||||
required this.configMap,
|
||||
required this.selectedLLM,
|
||||
required this.provider,
|
||||
});
|
||||
|
||||
Map toJSON() {
|
||||
Map cmap = {};
|
||||
for (final e in configMap.entries) {
|
||||
cmap[e.key] = e.value.toJson();
|
||||
}
|
||||
return {
|
||||
'endpoint': endpoint,
|
||||
'credential': credential,
|
||||
'config_map': cmap,
|
||||
'selected_llm': selectedLLM.identifier,
|
||||
'provider': provider.name,
|
||||
};
|
||||
}
|
||||
|
||||
static LLMSaveObject fromJSON(Map json) {
|
||||
Map<String, LLMModelConfiguration> cmap = {};
|
||||
for (final k in json['config_map'].keys) {
|
||||
cmap[k] = LLMModelConfiguration.fromJson(json['config_map'][k]);
|
||||
}
|
||||
final provider = LLMProvider.fromName(json['provider']);
|
||||
return LLMSaveObject(
|
||||
endpoint: json['endpoint'],
|
||||
credential: json['credential'],
|
||||
configMap: cmap,
|
||||
selectedLLM: provider.getLLMByIdentifier(json['selected_llm']),
|
||||
provider: provider,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user