名称: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)
输出
解析并呈现响应:
- 响应:来自
.response的主要 AI 生成内容 - 统计:令牌使用量、使用的模型、来自
.stats的延迟 - 错误:任何来自
.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进行结构化解析 - 显示响应和使用统计
- 优雅地处理错误并提供有帮助的消息