mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
faet: add env var support for dashbot
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:apidash/providers/providers.dart';
|
import 'package:apidash/providers/providers.dart';
|
||||||
import 'package:apidash/models/models.dart';
|
import 'package:apidash/models/models.dart';
|
||||||
import 'package:apidash/utils/file_utils.dart';
|
import 'package:apidash/utils/file_utils.dart';
|
||||||
|
import 'package:apidash/utils/utils.dart';
|
||||||
import '../../../core/model/chat_attachment.dart';
|
import '../../../core/model/chat_attachment.dart';
|
||||||
import '../../../core/services/curl_import_service.dart';
|
import '../../../core/services/curl_import_service.dart';
|
||||||
import '../../../core/services/openapi_import_service.dart';
|
import '../../../core/services/openapi_import_service.dart';
|
||||||
@@ -96,11 +97,19 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final promptBuilder = _ref.read(promptBuilderProvider);
|
final promptBuilder = _ref.read(promptBuilderProvider);
|
||||||
|
// Prepare a substituted copy of current request for prompt context
|
||||||
|
final currentReq = _currentRequest;
|
||||||
|
final substitutedReq = (currentReq?.httpRequestModel != null)
|
||||||
|
? currentReq!.copyWith(
|
||||||
|
httpRequestModel:
|
||||||
|
_getSubstitutedHttpRequestModel(currentReq.httpRequestModel!),
|
||||||
|
)
|
||||||
|
: currentReq;
|
||||||
String systemPrompt;
|
String systemPrompt;
|
||||||
if (type == ChatMessageType.generateCode) {
|
if (type == ChatMessageType.generateCode) {
|
||||||
final detectedLang = promptBuilder.detectLanguage(text);
|
final detectedLang = promptBuilder.detectLanguage(text);
|
||||||
systemPrompt = promptBuilder.buildSystemPrompt(
|
systemPrompt = promptBuilder.buildSystemPrompt(
|
||||||
_currentRequest,
|
substitutedReq,
|
||||||
type,
|
type,
|
||||||
overrideLanguage: detectedLang,
|
overrideLanguage: detectedLang,
|
||||||
history: currentMessages,
|
history: currentMessages,
|
||||||
@@ -160,7 +169,7 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
systemPrompt = promptBuilder.buildSystemPrompt(
|
systemPrompt = promptBuilder.buildSystemPrompt(
|
||||||
_currentRequest,
|
substitutedReq,
|
||||||
type,
|
type,
|
||||||
history: currentMessages,
|
history: currentMessages,
|
||||||
);
|
);
|
||||||
@@ -544,8 +553,9 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic>? _currentRequestContext() {
|
Map<String, dynamic>? _currentRequestContext() {
|
||||||
final rq = _currentRequest?.httpRequestModel;
|
final originalRq = _currentRequest?.httpRequestModel;
|
||||||
if (rq == null) return null;
|
if (originalRq == null) return null;
|
||||||
|
final rq = _getSubstitutedHttpRequestModel(originalRq);
|
||||||
final headers = <String, String>{};
|
final headers = <String, String>{};
|
||||||
for (final h in rq.headers ?? const []) {
|
for (final h in rq.headers ?? const []) {
|
||||||
final k = (h.name).toString();
|
final k = (h.name).toString();
|
||||||
@@ -826,6 +836,17 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
ensure: (b) => _ensureBaseUrlEnv(b),
|
ensure: (b) => _ensureBaseUrlEnv(b),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpRequestModel _getSubstitutedHttpRequestModel(
|
||||||
|
HttpRequestModel httpRequestModel) {
|
||||||
|
final envMap = _ref.read(availableEnvironmentVariablesStateProvider);
|
||||||
|
final activeEnvId = _ref.read(activeEnvironmentIdStateProvider);
|
||||||
|
return substituteHttpRequestModel(
|
||||||
|
httpRequestModel,
|
||||||
|
envMap,
|
||||||
|
activeEnvId,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final chatViewmodelProvider = StateNotifierProvider<ChatViewmodel, ChatState>((
|
final chatViewmodelProvider = StateNotifierProvider<ChatViewmodel, ChatState>((
|
||||||
|
|||||||
Reference in New Issue
Block a user