-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_significant.py
More file actions
83 lines (62 loc) · 2.2 KB
/
Copy pathcheck_significant.py
File metadata and controls
83 lines (62 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# inceptionlabs.ai
"""
Check latest tweets markdown for significant war developments
using the Inception Labs Mercury API.
Significant = US casualties, US plane shot down, US ship hit/sunk,
major terrorist attack in Europe or the USA, US troops in Iran,
or Iran surrenders.
Returns a brief description if found, empty string if not.
"""
import glob
import os
import requests
import sys
from dotenv import load_dotenv
load_dotenv()
def get_latest_markdown():
"""Get the most recent markdown file from the output directory."""
files = glob.glob(os.path.join("markdown_output", "tweets_*.md"))
if not files:
print("No markdown files found in markdown_output/")
sys.exit(1)
return max(files, key=os.path.getmtime)
def check_significant(markdown_content):
"""Send markdown to Inception Labs API to check for significant developments."""
prompt_path = os.path.join(os.path.dirname(__file__), "prompts", "prompt.txt")
with open(prompt_path, "r", encoding="utf-8") as f:
prompt_template = f.read()
prompt = prompt_template.format(tweets=markdown_content)
api_key = os.environ.get("INCEPTION_API_KEY")
if not api_key:
print("Error: INCEPTION_API_KEY environment variable not set.")
sys.exit(1)
response = requests.post(
"https://api.inceptionlabs.ai/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
},
json={
"model": "mercury-2",
"messages": [{"role": "user", "content": prompt}],
"max_tokens": 200,
},
)
if response.status_code != 200:
print(f"API error {response.status_code}: {response.text}")
sys.exit(1)
data = response.json()
return data["choices"][0]["message"]["content"].strip()
def main():
md_path = get_latest_markdown()
print(f"Checking: {md_path}")
with open(md_path, "r", encoding="utf-8") as f:
content = f.read()
result = check_significant(content)
if result:
print(f"SIGNIFICANT: {result}")
else:
print("No significant developments detected.")
return result
if __name__ == "__main__":
main()