feat: 为Gemini原生代码执行器提供有限支持

This commit is contained in:
Raven95676
2025-04-13 12:43:25 +08:00
parent 9c29df47bb
commit 739f09059e
2 changed files with 19 additions and 6 deletions
+7
View File
@@ -528,6 +528,7 @@ CONFIG_METADATA_2 = {
"model": "gemini-2.0-flash-exp",
},
"gm_resp_image_modal": False,
"gm_native_coderunner": False,
"gm_safety_settings": {
"harassment": "BLOCK_MEDIUM_AND_ABOVE",
"hate_speech": "BLOCK_MEDIUM_AND_ABOVE",
@@ -704,6 +705,12 @@ CONFIG_METADATA_2 = {
"type": "bool",
"hint": "启用后,将支持返回图片内容。需要模型支持,否则会报错。具体支持模型请查看 Google Gemini 官方网站。温馨提示,如果您需要生成图片,请关闭 `启用群员识别` 配置获得更好的效果。",
},
"gm_native_coderunner": {
"description": "启用原生代码执行器",
"type": "bool",
"hint": "启用后所有函数工具将全部失效",
"obvious_hint": True,
},
"gm_safety_settings": {
"description": "安全过滤器",
"type": "object",
+12 -6
View File
@@ -126,12 +126,14 @@ class ProviderGoogleGenAI(Provider):
modalities = ["Text"]
tool_list = None
if tools:
func_desc = tools.get_func_desc_google_genai_style()
if func_desc:
tool_list = [
types.Tool(function_declarations=func_desc["function_declarations"])
]
if self.provider_config.get("gm_native_coderunner", False):
if tools:
logger.warning("Gemini原生代码执行器已启用,函数工具将被忽略")
tool_list = [types.Tool(code_execution=types.ToolCodeExecution())]
elif tools and (func_desc := tools.get_func_desc_google_genai_style()):
tool_list = [
types.Tool(function_declarations=func_desc["function_declarations"])
]
return types.GenerateContentConfig(
system_instruction=system_instruction,
@@ -252,6 +254,10 @@ class ProviderGoogleGenAI(Provider):
chain.append(Comp.Plain("这是图片"))
for part in result_parts:
if part.text:
if part.executable_code:
part.executable_code = None
if part.code_execution_result:
part.code_execution_result = None
chain.append(Comp.Plain(part.text))
elif part.function_call:
llm_response.role = "tool"