A new package that processes news headlines or short text inputs related to geopolitical and defense topics, such as reports on military capabilities or international competition. It uses an LLM to ge
Project description
geopolitex-analyzer
geopolitex-analyzer is a lightweight Python package that turns short news headlines or text snippets about geopolitics, defense, and international competition into structured, LLM‑generated summaries. The output always follows a predefined pattern (subject, comparative context, implications) and is validated with robust regex matching to guarantee consistency and accuracy.
Features
- One‑line summarisation for geopolitical and defense‑related texts.
- Pattern‑based validation using
llmatchto ensure the LLM output conforms to the expected format. - Pluggable LLM backend – defaults to
ChatLLM7but works with any LangChain‑compatible chat model (OpenAI, Anthropic, Google, etc.). - Simple API: just pass the raw text and get a list of structured strings back.
Installation
pip install geopolitex_analyzer
Quick Start
from geopolitex_analyzer import geopolitex_analyzer
# Simple usage with the default ChatLLM7 (requires an API key)
summary = geopolitex_analyzer(
user_input="China launches a new hypersonic missile system, threatening regional stability."
)
print(summary)
# -> ['Subject: China...', 'Comparative Context: ...', 'Implications: ...']
Using a custom LangChain LLM
You can provide any LangChain chat model that implements BaseChatModel. This is useful if you prefer OpenAI, Anthropic, Google Gemini, etc.
OpenAI example
from langchain_openai import ChatOpenAI
from geopolitex_analyzer import geopolitex_analyzer
my_llm = ChatOpenAI(model="gpt-4o-mini")
summary = geopolitex_analyzer(
user_input="Russia expands its naval presence in the Arctic.",
llm=my_llm,
)
print(summary)
Anthropic example
from langchain_anthropic import ChatAnthropic
from geopolitex_analyzer import geopolitex_analyzer
my_llm = ChatAnthropic(model="claude-3-haiku-20240307")
summary = geopolitex_analyzer(
user_input="India announces a new defense budget focusing on AI‑driven weaponry.",
llm=my_llm,
)
print(summary)
Google Gemini example
from langchain_google_genai import ChatGoogleGenerativeAI
from geopolitex_analyzer import geopolitex_analyzer
my_llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash")
summary = geopolitex_analyzer(
user_input="EU sanctions target new Russian aerospace firms.",
llm=my_llm,
)
print(summary)
Supplying an API key for the default LLM7 backend
If you rely on the built‑in ChatLLM7 model, provide an API key either via the LLM7_API_KEY environment variable or directly:
from geopolitex_analyzer import geopolitex_analyzer
summary = geopolitex_analyzer(
user_input="Turkey acquires advanced drone technology from South Korea.",
api_key="your_llm7_api_key_here",
)
print(summary)
A free API key can be obtained by registering at https://token.llm7.io/. The free tier’s rate limits are sufficient for most typical use cases.
Function Reference
geopolitex_analyzer(
user_input: str,
api_key: Optional[str] = None,
llm: Optional[BaseChatModel] = None,
) -> List[str]
| Parameter | Type | Description |
|---|---|---|
user_input |
str |
Raw headline or short text describing a geopolitical/defense topic. |
api_key |
Optional[str] |
API key for the default ChatLLM7. If omitted, the function looks for the LLM7_API_KEY env var. |
llm |
Optional[BaseChatModel] |
Any LangChain chat model. If provided, it overrides the default ChatLLM7. |
Return value: A list of strings that match the defined output pattern (e.g., subject, comparative context, implications). If the LLM response does not satisfy the pattern, a RuntimeError is raised.
Dependencies
llmatch_messages– pattern‑matching helper used to enforce output format.langchain-core– core interfaces for LLMs (BaseChatModel, message types).langchain-llm7– wrapper for the LLM7 service (automatically installed).geopolitex-analyzer’s ownprompts.py(contains the system / human prompts and the regex pattern).
Contributing & Support
- Bug reports & feature requests: https://github.com/chigwell/geopolitex_analyzer/issues
- Pull requests: Contributions are welcome—please follow the standard GitHub workflow.
Author
Eugene Evstafev
Email: hi@euegne.plus
GitHub: chigwell
License
MIT License – see the LICENSE file in the repository for details.
Happy analysing!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geopolitex_analyzer-2025.12.21165107.tar.gz.
File metadata
- Download URL: geopolitex_analyzer-2025.12.21165107.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
913b0080cf2abdb754a3c29beab3b7453baafb49ae0367405766160ffe1e2c1d
|
|
| MD5 |
66cdbe4e9953e95d5e6713ba6e28f982
|
|
| BLAKE2b-256 |
e0c73169e18daea6439a16a266ad30f603e4e303d0b7405213f576e10db8a84a
|
File details
Details for the file geopolitex_analyzer-2025.12.21165107-py3-none-any.whl.
File metadata
- Download URL: geopolitex_analyzer-2025.12.21165107-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcca2964dd7fb3db1cfec692577a92f6204f4b8b837adebc1f803040da1fd639
|
|
| MD5 |
ab5dca134824bbef39fe19523c6db767
|
|
| BLAKE2b-256 |
449ce3d4ef89e6b838a6da8ecca6d727853ad773dd00089eb22db18e11dcf3d1
|