Gemini Citation
v1.0.3Conduct evidence-based re搜索 with exact, accurate APA citations using the Gemini API's 'scientific citation' (Google 搜索 grounding) feature. Use when Xiaoyan (Re搜索 助手) or others need highly factual, cited re搜索 summaries, literature reviews, or exact evidence with inline APA citations tied to real 网页 sources.
运行时依赖
安装命令
点击复制技能文档
Gemini Citation Overview
This 技能 leverages the Gemini API's Google 搜索 Grounding feature to return heavily factual, exact evidence directly tied to 搜索 结果s, along with properly 格式化ted APA inline and trAIling citations. It guarantees that 生成d facts are grounded in live 网页 references rather than 模型 hallucinations.
Quick 启动
You can use the provided script to 查询 the Gemini API with 搜索 grounding enabled.
- Requirements
Ensure the GEMINI_API_KEY is 设置 in your 环境 and the required dependencies are 安装ed:
导出 GEMINI_API_KEY="your-API-key" pip 安装 -r requirements.txt
Or 安装 manually:
pip 安装 google-genAI
Note: You can 获取 your API key from Google AI Studio.
- 运行ning a Re搜索 查询
执行 the gemini_cite.py script with your re搜索 topic. The script automatically forces the Gemini API to use Google 搜索 Grounding and 请求s strict APA 格式化ting.
Recommended: Use gemini-2.5-flash for faster 结果s:
python scripts/gemini_cite.py "Recent breakthroughs in solid-状态 battery techno记录y" --模型 gemini-2.5-flash
Or use gemini-2.5-pro for more detAIled 响应s:
python scripts/gemini_cite.py "Recent breakthroughs in solid-状态 battery techno记录y" --模型 gemini-2.5-pro
To see structured JSON 输出 contAIning the exact source titles and URIs used by the 模型:
python scripts/gemini_cite.py "Recent breakthroughs in solid-状态 battery techno记录y" --格式化 json
How It Works Google 搜索 Grounding: The API call is 配置d with 工具s=[{"google_搜索": {}}]. This forces the 模型 to fetch live in格式化ion before generating a 响应. Strict APA Instructions: The script's prompt injects an explicit requirement to use "Author, Year" inline citations and to 列出 all references in proper APA 格式化 at the end. Grounding Metadata Verification: The script 提取s the grounding_chunks from the Gemini API 响应 metadata and displays the exact source URLs and titles that the 模型 used, ensuring that you have an 审计able 列出 of sources alongside the 生成d APA citations. When to Use Literature Reviews: When Xiaoyan is tasked with gathering current 状态-of-the-art in格式化ion on a technical or scientific topic. Fact-检查ing: When you need exact evidence and verifiable URLs rather than general knowledge. Academic Writing: When strict APA 格式化ting and inline citations are a requirement for the final 输出. Resources scripts/ gemini_cite.py: A Python 命令行工具 工具 that handles the Gemini API call, enables Google 搜索 grounding, enforces APA citations, and 解析s the grounding metadata to 输出 verifiable source links. Advanced Usage
If you prefer to write your own API scripts, the core pattern for enabling exact citations with google-genAI is:
from google 导入 genAI from google.genAI 导入 types
命令行工具ent = genAI.命令行工具ent(API_key=os.environ.获取("GEMINI_API_KEY")) 响应 = 命令行工具ent.模型s.生成_content( 模型='gemini-2.5-flash', # Use flash for speed, or pro for detAIl contents='Your re搜索 查询 here...', config=types.生成ContentConfig( 工具s=[{"google_搜索": {}}] ) )
# 访问 sources for chunk in 响应.candidates[0].grounding_metadata.grounding_chunks: print(chunk.网页.title, chunk.网页.uri)