Add Google Financial News Analysis Prompt Generator#42
Conversation
- Add `Finance/generate_news_prompt.py`: A CLI tool to generate a structured financial news analysis prompt based on user inputs (keyword, time range, region, focus). - Add `Finance/test_generate_news_prompt.py`: Unit tests to verify the prompt generation logic and argument substitution. - The prompt is designed for neutral, fact-oriented financial analysis. Co-authored-by: ewdlop <25368970+ewdlop@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
Adds a new Python CLI tool that generates a standardized “Google Financial News Analysis” prompt (Traditional Chinese), along with unit tests validating key rendered sections.
Changes:
- Introduces
Finance/generate_news_prompt.pywith anargparseCLI and a parameterized prompt template. - Adds
Finance/test_generate_news_prompt.pywithunittestcoverage for prompt rendering and structure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| Finance/generate_news_prompt.py | Implements the prompt generator function and CLI entrypoint for rendering the standardized prompt. |
| Finance/test_generate_news_prompt.py | Adds unit tests asserting correct parameter interpolation and presence of key template sections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import argparse | ||
| import sys | ||
|
|
||
| def generate_prompt(keyword, time_range, region, focus): |
There was a problem hiding this comment.
generate_prompt requires time_range, region, and focus, but the CLI provides defaults for these and the tests imply defaults exist. Consider giving generate_prompt matching default parameter values (e.g., "7 天"/"全球"/"宏觀經濟") so the function can be called with just keyword, or update the tests/CLI contract to consistently treat these as required inputs.
| def generate_prompt(keyword, time_range, region, focus): | |
| def generate_prompt(keyword, time_range="7 天", region="全球", focus="宏觀經濟"): |
| @@ -0,0 +1,112 @@ | |||
| #!/usr/bin/env python3 | |||
| import argparse | |||
| import sys | |||
There was a problem hiding this comment.
import sys is unused in this module; removing it avoids lint noise and keeps imports minimal.
| import sys |
|
|
||
| # Append the current directory (repo root) to sys.path so we can import Finance.generate_news_prompt | ||
| sys.path.append(os.getcwd()) |
There was a problem hiding this comment.
Modifying sys.path using os.getcwd() is brittle because the working directory may not be the repo root when the tests run (and it can mask import issues). Prefer deriving the repo root from __file__ (e.g., via pathlib.Path(__file__).resolve()), or avoid sys.path manipulation by making Finance an importable package and running tests from the repo root.
| # Append the current directory (repo root) to sys.path so we can import Finance.generate_news_prompt | |
| sys.path.append(os.getcwd()) | |
| from pathlib import Path | |
| # Append the repository root (parent of the Finance package) to sys.path so we can import Finance.generate_news_prompt | |
| REPO_ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.append(str(REPO_ROOT)) |
| def test_default_values(self): | ||
| # Test with just keyword, defaults should be used | ||
| keyword = "NVDA" | ||
| prompt = generate_prompt(keyword, "7 天", "全球", "宏觀經濟") | ||
|
|
||
| self.assertIn(f"* 查詢關鍵字:`{keyword}`", prompt) | ||
| self.assertIn("* 時間範圍:`7 天`", prompt) | ||
| self.assertIn("* 地區(可選):`全球`", prompt) | ||
| self.assertIn("* 關注面向:`宏觀經濟`", prompt) |
There was a problem hiding this comment.
test_default_values says it tests defaults, but it passes explicit values for time_range, region, and focus, so it won’t catch regressions in defaulting behavior. Either call generate_prompt(keyword) (if defaults are added to generate_prompt) or test the CLI/argparse defaults by invoking main()/the script with only keyword and asserting the rendered defaults in the output.
|
|
||
| def generate_prompt(keyword, time_range, region, focus): | ||
| template = """以下是一個**可直接使用的「Google 財經新聞(Google Financial News)Prompt」**,專門用於要求 AI **彙整、摘要、分析與風險判讀**近期財經新聞。整體風格偏向**專業、可審計、偏事實導向**,避免情緒與投資承諾。 | ||
|
|
||
| --- | ||
|
|
||
| ## 📌 Google 財經新聞分析 Prompt(專業版) | ||
|
|
||
| **角色設定(Role)** | ||
| 你是一名**中立的財經新聞分析師(Financial News Analyst)**,專門彙整並解析來自 | ||
|
|
||
| * Google News(財經相關新聞) | ||
| * 主要國際媒體(Reuters、Bloomberg、WSJ、FT 等) | ||
|
|
||
| 你的任務不是預測市場,而是**萃取資訊、辨識風險、區分事實與觀點**。 | ||
|
|
||
| --- | ||
|
|
||
| **任務(Task)** | ||
| 請根據近期的 Google 財經新聞,針對指定主題進行**結構化摘要與風險解讀**。 | ||
|
|
||
| > 📥【輸入參數】 | ||
| > | ||
| > * 查詢關鍵字:`{keyword}` | ||
| > * 時間範圍:`{time_range}` | ||
| > * 地區(可選):`{region}` | ||
| > * 關注面向:`{focus}` | ||
|
|
||
| --- | ||
|
|
||
| ## 📊 輸出結構(必須遵守) | ||
|
|
||
| ### 1️⃣ 新聞總覽(News Overview) | ||
|
|
||
| * 主要新聞事件(不超過 5 則) | ||
| * 每則以 **一句話摘要** | ||
| * 標註新聞性質: | ||
|
|
||
| * 事實報導(Fact) | ||
| * 市場解讀(Market Interpretation) | ||
| * 意見 / 評論(Opinion) | ||
|
|
||
| --- | ||
|
|
||
| ### 2️⃣ 關鍵資訊整理(Key Facts) | ||
|
|
||
| * 發生了什麼事 | ||
| * 影響對象(公司 / 產業 / 市場) |
There was a problem hiding this comment.
The prompt template here appears to duplicate the existing Finance/financial_news_prompt.md content (with placeholders replaced). To avoid the two drifting out of sync, consider making one the single source of truth (e.g., load the markdown template file and substitute parameters, or generate the .md from this module).
| def generate_prompt(keyword, time_range, region, focus): | |
| template = """以下是一個**可直接使用的「Google 財經新聞(Google Financial News)Prompt」**,專門用於要求 AI **彙整、摘要、分析與風險判讀**近期財經新聞。整體風格偏向**專業、可審計、偏事實導向**,避免情緒與投資承諾。 | |
| --- | |
| ## 📌 Google 財經新聞分析 Prompt(專業版) | |
| **角色設定(Role)** | |
| 你是一名**中立的財經新聞分析師(Financial News Analyst)**,專門彙整並解析來自 | |
| * Google News(財經相關新聞) | |
| * 主要國際媒體(Reuters、Bloomberg、WSJ、FT 等) | |
| 你的任務不是預測市場,而是**萃取資訊、辨識風險、區分事實與觀點**。 | |
| --- | |
| **任務(Task)** | |
| 請根據近期的 Google 財經新聞,針對指定主題進行**結構化摘要與風險解讀**。 | |
| > 📥【輸入參數】 | |
| > | |
| > * 查詢關鍵字:`{keyword}` | |
| > * 時間範圍:`{time_range}` | |
| > * 地區(可選):`{region}` | |
| > * 關注面向:`{focus}` | |
| --- | |
| ## 📊 輸出結構(必須遵守) | |
| ### 1️⃣ 新聞總覽(News Overview) | |
| * 主要新聞事件(不超過 5 則) | |
| * 每則以 **一句話摘要** | |
| * 標註新聞性質: | |
| * 事實報導(Fact) | |
| * 市場解讀(Market Interpretation) | |
| * 意見 / 評論(Opinion) | |
| --- | |
| ### 2️⃣ 關鍵資訊整理(Key Facts) | |
| * 發生了什麼事 | |
| * 影響對象(公司 / 產業 / 市場) | |
| from pathlib import Path | |
| def generate_prompt(keyword, time_range, region, focus): | |
| """ | |
| Generate a financial news analysis prompt by filling in parameters | |
| into the canonical markdown template `financial_news_prompt.md`. | |
| """ | |
| template_path = Path(__file__).with_name("financial_news_prompt.md") | |
| try: | |
| template = template_path.read_text(encoding="utf-8") | |
| except OSError: | |
| # Fallback to an empty template if the file cannot be read. | |
| template = "" | |
| return template.format( | |
| keyword=keyword, | |
| time_range=time_range, | |
| region=region, | |
| focus=focus, | |
| ) |
This PR adds a new tool
Finance/generate_news_prompt.pywhich generates a standardized "Google Financial News Analysis" prompt. This prompt is intended to be used with an AI to analyze financial news with a professional, risk-aware, and neutral tone.Key features:
argparse.Finance/test_generate_news_prompt.py.PR created automatically by Jules for task 7523441205800820187 started by @ewdlop