Skip to content

Add Google Financial News Analysis Prompt Generator#42

Open
ewdlop wants to merge 1 commit intomainfrom
feat/google-financial-news-prompt-7523441205800820187
Open

Add Google Financial News Analysis Prompt Generator#42
ewdlop wants to merge 1 commit intomainfrom
feat/google-financial-news-prompt-7523441205800820187

Conversation

@ewdlop
Copy link
Owner

@ewdlop ewdlop commented Jan 30, 2026

This PR adds a new tool Finance/generate_news_prompt.py which 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:

  • CLI interface with argparse.
  • Customizable parameters: keyword, time range, region, and focus area.
  • Internal storage of the Traditional Chinese prompt template.
  • Unit tests included in Finance/test_generate_news_prompt.py.

PR created automatically by Jules for task 7523441205800820187 started by @ewdlop

- 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>
Copilot AI review requested due to automatic review settings January 30, 2026 04:10
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with an argparse CLI and a parameterized prompt template.
  • Adds Finance/test_generate_news_prompt.py with unittest coverage 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):
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
def generate_prompt(keyword, time_range, region, focus):
def generate_prompt(keyword, time_range="7 天", region="全球", focus="宏觀經濟"):

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,112 @@
#!/usr/bin/env python3
import argparse
import sys
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import sys is unused in this module; removing it avoids lint noise and keeps imports minimal.

Suggested change
import sys

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +6

# Append the current directory (repo root) to sys.path so we can import Finance.generate_news_prompt
sys.path.append(os.getcwd())
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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))

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +20
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)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +51

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)

* 發生了什麼事
* 影響對象(公司 / 產業 / 市場)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
def generate_prompt(keyword, time_range, region, focus):
template = """以下是一個**可直接使用的Google 財經新聞Google Financial NewsPrompt**專門用於要求 AI **彙整摘要分析與風險判讀**近期財經新聞整體風格偏向**專業可審計偏事實導向**避免情緒與投資承諾
---
## 📌 Google 財經新聞分析 Prompt(專業版)
**角色設定Role**
你是一名**中立的財經新聞分析師Financial News Analyst**專門彙整並解析來自
* Google News財經相關新聞
* 主要國際媒體ReutersBloombergWSJFT
你的任務不是預測市場而是**萃取資訊辨識風險區分事實與觀點**
---
**任務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,
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants