feat: enrich summaries with contacts and Obsidian links
This commit is contained in:
46
larkx/cli.py
46
larkx/cli.py
@ -337,7 +337,34 @@ def cmd_summarize(args):
|
||||
output_config = (
|
||||
{} if args.output else load_output_config(getattr(args, 'config', None))
|
||||
)
|
||||
rows = Storage().get_received_messages(
|
||||
storage = Storage()
|
||||
if not args.no_fetch:
|
||||
from .history import sync_all_chats_for_day
|
||||
|
||||
try:
|
||||
fetch_stats = sync_all_chats_for_day(
|
||||
LarkClient(LarkAuth()),
|
||||
storage,
|
||||
target_day,
|
||||
tz,
|
||||
batch_size=50,
|
||||
chat_ids=args.chat,
|
||||
)
|
||||
except Exception as e:
|
||||
raise SummaryError(
|
||||
f'飞书历史数据同步失败({type(e).__name__});'
|
||||
'可使用 --no-fetch 明确只读本地库。'
|
||||
) from e
|
||||
if fetch_stats['failed']:
|
||||
raise SummaryError(
|
||||
f"有 {fetch_stats['failed']} 个会话同步失败,已停止后续总结;"
|
||||
'可修复后重试,或使用 --no-fetch 明确只读本地库。'
|
||||
)
|
||||
print(
|
||||
f"数据同步完成: 日期内消息 {fetch_stats['matched']} 条,"
|
||||
f"写入/补全 {fetch_stats['saved']} 条,失败会话 0 个"
|
||||
)
|
||||
rows = storage.get_received_messages(
|
||||
int(start.timestamp()), int(end.timestamp()), chat_ids=args.chat
|
||||
)
|
||||
if args.dry_run:
|
||||
@ -355,8 +382,21 @@ def cmd_summarize(args):
|
||||
f'({target_day.isoformat()},收到消息 {len(rows)} 条,未发送给模型)'
|
||||
)
|
||||
return 0
|
||||
contacts = None
|
||||
if rows and not args.no_contacts:
|
||||
from .contacts import ContactsError, fetch_contacts
|
||||
|
||||
try:
|
||||
contacts = fetch_contacts(LarkClient(LarkAuth()), rows)
|
||||
except ContactsError as e:
|
||||
raise SummaryError(str(e)) from e
|
||||
content = summarize_messages(
|
||||
client, rows, target_day, tz, max_chars=args.max_chars
|
||||
client,
|
||||
rows,
|
||||
target_day,
|
||||
tz,
|
||||
max_chars=args.max_chars,
|
||||
contacts=contacts,
|
||||
)
|
||||
output_path = (
|
||||
args.output
|
||||
@ -564,6 +604,8 @@ def main():
|
||||
p.add_argument('--base-url', help='Magpie OpenAI 兼容地址;默认 http://127.0.0.1:3425/v1')
|
||||
p.add_argument('--timeout', type=int, default=180, help='单次 Magpie 请求超时秒数,默认 180')
|
||||
p.add_argument('--max-chars', type=int, default=80000, help='每个对话内每块消息最大字符数,默认 80000')
|
||||
p.add_argument('--no-contacts', action='store_true', help='不联网获取相关会话通讯录,也不补全人名')
|
||||
p.add_argument('--no-fetch', action='store_true', help='不同步飞书历史消息,只读取本地已入库记录')
|
||||
p.add_argument('--config', help='YAML 配置路径;默认读取当前目录 larksniffer.yaml(如存在)')
|
||||
p.add_argument('-o', '--output', help='输出路径,优先级高于 YAML;dry-run 为 JSON,否则为 Markdown')
|
||||
mode = p.add_mutually_exclusive_group()
|
||||
|
||||
Reference in New Issue
Block a user