Conversation
This script generates a standardized 'Google Financial News Analysis' prompt based on user inputs (keyword, time range, region, focus). It is self-contained and includes the prompt template. Also added Finance/test_generate_news_prompt.py to verify the script's functionality. 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 small CLI-driven Python utility to generate a structured “Google Financial News” analysis prompt, along with a basic unit test module to validate prompt generation.
Changes:
- Added
Finance/generate_news_prompt.pyto generate and print a parameterized financial-news analysis prompt viaargparse. - Added
Finance/test_generate_news_prompt.pywithunittestcoverage for key prompt sections and parameter interpolation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Finance/generate_news_prompt.py | New prompt generator script with CLI args for keyword/time range/region/focus. |
| Finance/test_generate_news_prompt.py | New unit tests validating generated prompt content and parameter substitution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,111 @@ | |||
| import argparse | |||
| import sys | |||
There was a problem hiding this comment.
sys is imported but never used in this module. Please remove the unused import to avoid lint/test failures in stricter environments.
| import sys |
|
|
||
| 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 content here appears to be a near-verbatim duplicate of Finance/financial_news_prompt.md (e.g., that file lines 1–90). Keeping two sources of truth makes future edits error-prone. Consider loading the template from the existing markdown file (and only substituting the 4 parameters), or otherwise consolidating so the prompt text is defined in exactly one place.
| 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 loading the template from | |
| 'financial_news_prompt.md' and substituting the provided parameters. | |
| """ | |
| template_path = Path(__file__).with_name("financial_news_prompt.md") | |
| template = template_path.read_text(encoding="utf-8") | |
| return template.format( | |
| keyword=keyword, | |
| time_range=time_range, | |
| region=region, | |
| focus=focus, | |
| ) |
| import sys | ||
| import os | ||
|
|
||
| # Add the directory containing the script to sys.path | ||
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| from generate_news_prompt import generate_prompt | ||
|
|
There was a problem hiding this comment.
The test mutates sys.path at import time to make generate_news_prompt importable. This can cause test-order dependent behavior and accidental imports if another module with the same name exists on the path. Prefer making Finance/ a proper package (add __init__.py) and importing via from Finance.generate_news_prompt import generate_prompt, or use a local relative import strategy that doesn't modify global sys.path.
| import sys | |
| import os | |
| # Add the directory containing the script to sys.path | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| from generate_news_prompt import generate_prompt | |
| import os | |
| import importlib.util | |
| import pathlib | |
| # Load generate_news_prompt from the same directory without modifying sys.path | |
| _module_name = "generate_news_prompt" | |
| _module_path = pathlib.Path(os.path.abspath(__file__)).with_name(f"{_module_name}.py") | |
| _spec = importlib.util.spec_from_file_location(_module_name, _module_path) | |
| _module = importlib.util.module_from_spec(_spec) | |
| assert _spec is not None and _spec.loader is not None | |
| _spec.loader.exec_module(_module) | |
| generate_prompt = _module.generate_prompt |
| def test_generate_prompt_defaults(self): | ||
| # Test with just the keyword, mimicking default args for others |
There was a problem hiding this comment.
test_generate_prompt_defaults (and its inline comment) says it tests defaults / "just the keyword", but it currently passes all four arguments explicitly. Either rename/update the comment to match what’s being tested, or adjust generate_prompt to provide defaults and call it with only the keyword to actually exercise default behavior.
| def test_generate_prompt_defaults(self): | |
| # Test with just the keyword, mimicking default args for others | |
| def test_generate_prompt_basic(self): | |
| # Test with a standard set of arguments |
Implemented a Python script
Finance/generate_news_prompt.pythat generates a structured prompt for Google Financial News analysis. The script accepts command-line arguments for keyword, time range, region, and focus area.Added a corresponding unit test file
Finance/test_generate_news_prompt.pyto ensure the correct generation of the prompt.Cleaned up
__pycache__to ensure a clean commit.PR created automatically by Jules for task 8982088012019191763 started by @ewdlop