Gemini快速查询Skill gemini-query

这个技能用于通过命令行快速向 Gemini AI 模型发送查询,自动解析 JSON 响应,并展示 AI 生成的答案、令牌使用统计和错误信息。适用于 AI 应用开发、测试和自动化任务。关键词:Gemini AI, 命令行查询, JSON 解析, AI 统计, 自动化

AI应用 0 次安装 0 次浏览 更新于 3/11/2026

名称:gemini-查询 描述:向 Gemini CLI 发送一个快速的无头查询,并显示带有统计信息的响应 参数提示:<prompt> 允许工具:Bash

Gemini 查询命令

执行一个快速的无头查询到 Gemini CLI 并显示响应。

用法

/google-ecosystem:gemini-query <prompt>

示例

  • /google-ecosystem:gemini-query 法国的首都是什么?
  • /google-ecosystem:gemini-query 解释 JavaScript 中的 async/await
  • /google-ecosystem:gemini-query 审查这个错误:TypeError: Cannot read property 'x' of undefined

执行

使用 Gemini CLI 的无头模式运行查询:

result=$(gemini "$ARGUMENTS" --output-format json 2>&1)

输出

解析并呈现响应:

  1. 响应:来自 .response 的主要 AI 生成内容
  2. 统计:令牌使用量、使用的模型、来自 .stats 的延迟
  3. 错误:任何来自 .error 的错误消息

响应提取

# 提取响应
response=$(echo "$result" | jq -r '.response // "No response"')

# 提取统计
tokens=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.total) | add // 0')
cached=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.cached) | add // 0')
models=$(echo "$result" | jq -r '.stats.models | keys | join(", ") | if . == "" then "unknown" else . end')
latency=$(echo "$result" | jq '.stats.models | to_entries | map(.value.api.totalLatencyMs) | add // 0')

# 检查错误
error=$(echo "$result" | jq -r '.error.message // empty')

格式化输出

以清洁格式呈现结果:

## Gemini 响应

{response}

---
**统计**:{tokens} 个令牌({cached} 缓存) | 模型:{models} | 延迟:{latency}ms

如果有错误:

## 错误

**类型**:{error_type}
**消息**:{error_message}

注释

  • 使用 --output-format json 进行结构化解析
  • 显示响应和使用统计
  • 优雅地处理错误并提供有帮助的消息