Skip to content

Commit eb95d6a

Browse files
committed
feat: Implement URL context tool for Google AI and apply theme-aware image filters to UI elements.
1 parent 74f3821 commit eb95d6a

17 files changed

Lines changed: 300 additions & 331 deletions

create_menu_view.py

Lines changed: 0 additions & 219 deletions
This file was deleted.

lib/api/ai/googleai/aistudio.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class GoogleAIStudio {
159159
hasGoogleSearch = true;
160160
} else if (tool.name == '__code_execution__') {
161161
hasCodeExecution = true;
162+
} else if (tool.name == '__url_context__') {
163+
// Dynamic Retrieval or Search can handle URL context
164+
hasGoogleSearch = true;
162165
} else {
163166
functionDeclarations.add({
164167
'name': tool.name,
@@ -168,16 +171,22 @@ class GoogleAIStudio {
168171
}
169172
}
170173

174+
final isGemini2 = request.model.contains('2.0');
175+
171176
if (hasGoogleSearch) {
172-
toolsList.add({'googleSearch': {}});
177+
if (isGemini2) {
178+
toolsList.add({'google_search': {}});
179+
} else {
180+
toolsList.add({'google_search_retrieval': {}});
181+
}
173182
}
174183

175184
if (hasCodeExecution) {
176-
toolsList.add({'codeExecution': {}});
185+
toolsList.add({'code_execution': {}});
177186
}
178187

179188
if (functionDeclarations.isNotEmpty) {
180-
toolsList.add({'functionDeclarations': functionDeclarations});
189+
toolsList.add({'function_declarations': functionDeclarations});
181190
}
182191

183192
body['tools'] = toolsList;

lib/api/ai/googleai/vertexai.dart

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:http/http.dart' as http;
44
import '../base.dart';
55
import '../../../core/models/ai/provider.dart';
66

7-
87
/// Google Vertex AI service sử dụng REST API
98
/// Chỉ chia sẻ AIModel và DTO models, không chia sẻ các đối tượng nội bộ với providers khác
109
class GoogleVertexAI {
@@ -173,17 +172,40 @@ class GoogleVertexAI {
173172

174173
// Thêm tools nếu có
175174
if (request.tools.isNotEmpty) {
176-
body['tools'] = [
177-
{
178-
'functionDeclarations': request.tools.map((tool) {
179-
return {
180-
'name': tool.name,
181-
if (tool.description != null) 'description': tool.description,
182-
'parameters': tool.parameters,
183-
};
184-
}).toList(),
185-
},
186-
];
175+
final toolsList = <Map<String, dynamic>>[];
176+
final functionDeclarations = <Map<String, dynamic>>[];
177+
bool hasGoogleSearch = false;
178+
bool hasCodeExecution = false;
179+
180+
for (final tool in request.tools) {
181+
if (tool.name == '__google_search__') {
182+
hasGoogleSearch = true;
183+
} else if (tool.name == '__code_execution__') {
184+
hasCodeExecution = true;
185+
} else if (tool.name == '__url_context__') {
186+
hasGoogleSearch = true;
187+
} else {
188+
functionDeclarations.add({
189+
'name': tool.name,
190+
if (tool.description != null) 'description': tool.description,
191+
'parameters': tool.parameters,
192+
});
193+
}
194+
}
195+
196+
if (hasGoogleSearch) {
197+
toolsList.add({'google_search_retrieval': {}});
198+
}
199+
200+
if (hasCodeExecution) {
201+
toolsList.add({'code_execution': {}});
202+
}
203+
204+
if (functionDeclarations.isNotEmpty) {
205+
toolsList.add({'function_declarations': functionDeclarations});
206+
}
207+
208+
body['tools'] = toolsList;
187209
}
188210

189211
return body;

lib/core/models/ai/model.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ class AIModel {
5454
final lowerName = name.toLowerCase();
5555
BuiltInTools? builtInTools;
5656
if (lowerName.contains('gemini')) {
57+
final isProOrFlash =
58+
lowerName.contains('pro') ||
59+
lowerName.contains('flash') ||
60+
lowerName.contains('2.0');
5761
builtInTools = BuiltInTools(
5862
urlContext: true,
59-
googleSearch: false,
60-
codeExecution: false,
63+
googleSearch: isProOrFlash,
64+
codeExecution: isProOrFlash,
6165
);
6266
}
6367

lib/features/ai/ui/views/edit_profile_screen.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import '../../../settings/ui/widgets/settings_card.dart';
99
import '../../controllers/edit_profile_controller.dart';
1010
import '../widgets/view_profile_dialog.dart';
1111

12+
/// Helper để tạo theme-aware image cho edit profile screen
13+
Widget _buildThemeAwareImageForProfile(BuildContext context, Widget child) {
14+
final isDark = Theme.of(context).brightness == Brightness.dark;
15+
16+
return ColorFiltered(
17+
colorFilter: ColorFilter.mode(
18+
isDark
19+
? Colors.white.withValues(alpha: 0.1)
20+
: Colors.black.withValues(alpha: 0.1),
21+
BlendMode.overlay,
22+
),
23+
child: child,
24+
);
25+
}
26+
1227
class AddProfileScreen extends StatefulWidget {
1328
final AIProfile? profile;
1429

@@ -98,11 +113,7 @@ class _AddProfileScreenState extends State<AddProfileScreen>
98113
bottom: true,
99114
child: TabBarView(
100115
controller: _tabController,
101-
children: [
102-
_buildGeneralTab(),
103-
_buildRequestTab(),
104-
_buildToolsTab(),
105-
],
116+
children: [_buildGeneralTab(), _buildRequestTab(), _buildToolsTab()],
106117
),
107118
),
108119
);
@@ -129,11 +140,14 @@ class _AddProfileScreenState extends State<AddProfileScreen>
129140
context,
130141
).colorScheme.surfaceContainerHighest,
131142
child: _viewModel.avatarController.text.isNotEmpty
132-
? Image.file(
133-
File(_viewModel.avatarController.text),
134-
width: 50,
135-
height: 50,
136-
fit: BoxFit.cover,
143+
? _buildThemeAwareImageForProfile(
144+
context,
145+
Image.file(
146+
File(_viewModel.avatarController.text),
147+
width: 50,
148+
height: 50,
149+
fit: BoxFit.cover,
150+
),
137151
)
138152
: Icon(
139153
Icons.person,

0 commit comments

Comments
 (0)