mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 19:39:25 +08:00
Reorganized the genai package by removing legacy LLM-related files and introducing a new modular interface under the 'interface' directory. Added provider-specific model classes, centralized constants, and updated the example to use the new API and data structures. Updated exports in genai.dart and improved dependency management.
73 lines
1.8 KiB
Dart
73 lines
1.8 KiB
Dart
import 'package:better_networking/better_networking.dart';
|
|
import '../../models/models.dart';
|
|
import '../consts.dart';
|
|
|
|
class GeminiModel extends ModelProvider {
|
|
static final instance = GeminiModel();
|
|
|
|
@override
|
|
ModelRequestData get defaultRequestData => kDefaultModelRequestData.copyWith(
|
|
url: kGeminiUrl,
|
|
modelConfigs: [
|
|
kDefaultModelConfigTemperature,
|
|
kDefaultGeminiModelConfigTopP,
|
|
kDefaultGeminiModelConfigMaxTokens,
|
|
],
|
|
);
|
|
|
|
@override
|
|
HttpRequestModel? createRequest(ModelRequestData? requestData) {
|
|
if (requestData == null) {
|
|
return null;
|
|
}
|
|
List<NameValueModel> params = [];
|
|
String endpoint = "${requestData.url}/${requestData.model}:";
|
|
if (requestData.stream ?? false) {
|
|
endpoint += 'streamGenerateContent';
|
|
params.add(const NameValueModel(name: "alt", value: "sse"));
|
|
} else {
|
|
endpoint += 'generateContent';
|
|
}
|
|
|
|
return HttpRequestModel(
|
|
method: HTTPVerb.post,
|
|
url: endpoint,
|
|
authModel: AuthModel(
|
|
type: APIAuthType.apiKey,
|
|
apikey: AuthApiKeyModel(
|
|
key: requestData.apiKey,
|
|
location: 'query',
|
|
name: 'key',
|
|
),
|
|
),
|
|
body: kJsonEncoder.convert({
|
|
"contents": [
|
|
{
|
|
"role": "user",
|
|
"parts": [
|
|
{"text": requestData.userPrompt},
|
|
],
|
|
},
|
|
],
|
|
"systemInstruction": {
|
|
"role": "system",
|
|
"parts": [
|
|
{"text": requestData.systemPrompt},
|
|
],
|
|
},
|
|
"generationConfig": requestData.getModelConfigMap(),
|
|
}),
|
|
);
|
|
}
|
|
|
|
@override
|
|
String? outputFormatter(Map x) {
|
|
return x['candidates']?[0]?['content']?['parts']?[0]?['text'];
|
|
}
|
|
|
|
@override
|
|
String? streamOutputFormatter(Map x) {
|
|
return x['candidates']?[0]?['content']?['parts']?[0]?['text'];
|
|
}
|
|
}
|