flonat-research 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/domain-reviewer.md +336 -0
- package/.claude/agents/fixer.md +226 -0
- package/.claude/agents/paper-critic.md +370 -0
- package/.claude/agents/peer-reviewer.md +289 -0
- package/.claude/agents/proposal-reviewer.md +215 -0
- package/.claude/agents/referee2-reviewer.md +367 -0
- package/.claude/agents/references/journal-referee-profiles.md +354 -0
- package/.claude/agents/references/paper-critic/council-personas.md +77 -0
- package/.claude/agents/references/paper-critic/council-prompts.md +198 -0
- package/.claude/agents/references/peer-reviewer/report-template.md +199 -0
- package/.claude/agents/references/peer-reviewer/sa-prompts.md +260 -0
- package/.claude/agents/references/peer-reviewer/security-scan.md +188 -0
- package/.claude/agents/references/proposal-reviewer/report-template.md +144 -0
- package/.claude/agents/references/proposal-reviewer/sa-prompts.md +149 -0
- package/.claude/agents/references/referee-config.md +114 -0
- package/.claude/agents/references/referee2-reviewer/audit-checklists.md +287 -0
- package/.claude/agents/references/referee2-reviewer/report-template.md +334 -0
- package/.claude/rules/design-before-results.md +52 -0
- package/.claude/rules/ignore-agents-md.md +17 -0
- package/.claude/rules/ignore-gemini-md.md +17 -0
- package/.claude/rules/lean-claude-md.md +45 -0
- package/.claude/rules/learn-tags.md +99 -0
- package/.claude/rules/overleaf-separation.md +67 -0
- package/.claude/rules/plan-first.md +175 -0
- package/.claude/rules/read-docs-first.md +50 -0
- package/.claude/rules/scope-discipline.md +28 -0
- package/.claude/settings.json +125 -0
- package/.context/current-focus.md +33 -0
- package/.context/preferences/priorities.md +36 -0
- package/.context/preferences/task-naming.md +28 -0
- package/.context/profile.md +29 -0
- package/.context/projects/_index.md +41 -0
- package/.context/projects/papers/nudge-exp.md +22 -0
- package/.context/projects/papers/uncertainty.md +31 -0
- package/.context/resources/claude-scientific-writer-review.md +48 -0
- package/.context/resources/cunningham-multi-analyst-agents.md +104 -0
- package/.context/resources/cunningham-multilang-code-audit.md +62 -0
- package/.context/resources/google-ai-co-scientist-review.md +72 -0
- package/.context/resources/karpathy-llm-council-review.md +58 -0
- package/.context/resources/multi-coder-reliability-protocol.md +175 -0
- package/.context/resources/pedro-santanna-takeaways.md +96 -0
- package/.context/resources/venue-rankings/abs_ajg_2024.csv +1823 -0
- package/.context/resources/venue-rankings/abs_ajg_2024_econ.csv +356 -0
- package/.context/resources/venue-rankings/cabs_4_4star_theory.csv +40 -0
- package/.context/resources/venue-rankings/core_2026.csv +801 -0
- package/.context/resources/venue-rankings.md +147 -0
- package/.context/workflows/README.md +69 -0
- package/.context/workflows/daily-review.md +91 -0
- package/.context/workflows/meeting-actions.md +108 -0
- package/.context/workflows/replication-protocol.md +155 -0
- package/.context/workflows/weekly-review.md +113 -0
- package/.mcp-server-biblio/formatters.py +158 -0
- package/.mcp-server-biblio/pyproject.toml +11 -0
- package/.mcp-server-biblio/server.py +678 -0
- package/.mcp-server-biblio/sources/__init__.py +14 -0
- package/.mcp-server-biblio/sources/base.py +73 -0
- package/.mcp-server-biblio/sources/formatters.py +83 -0
- package/.mcp-server-biblio/sources/models.py +22 -0
- package/.mcp-server-biblio/sources/multi_source.py +243 -0
- package/.mcp-server-biblio/sources/openalex_source.py +183 -0
- package/.mcp-server-biblio/sources/scopus_source.py +309 -0
- package/.mcp-server-biblio/sources/wos_source.py +508 -0
- package/.mcp-server-biblio/uv.lock +896 -0
- package/.scripts/README.md +161 -0
- package/.scripts/ai_pattern_density.py +446 -0
- package/.scripts/conf +445 -0
- package/.scripts/config.py +122 -0
- package/.scripts/count_inventory.py +275 -0
- package/.scripts/daily_digest.py +288 -0
- package/.scripts/done +177 -0
- package/.scripts/extract_meeting_actions.py +223 -0
- package/.scripts/focus +176 -0
- package/.scripts/generate-codex-agents-md.py +217 -0
- package/.scripts/inbox +194 -0
- package/.scripts/notion_helpers.py +325 -0
- package/.scripts/openalex/query_helpers.py +306 -0
- package/.scripts/papers +227 -0
- package/.scripts/query +223 -0
- package/.scripts/session-history.py +201 -0
- package/.scripts/skill-health.py +516 -0
- package/.scripts/skill-log-miner.py +273 -0
- package/.scripts/sync-to-codex.sh +252 -0
- package/.scripts/task +213 -0
- package/.scripts/tasks +190 -0
- package/.scripts/week +206 -0
- package/CLAUDE.md +197 -0
- package/LICENSE +21 -0
- package/MEMORY.md +38 -0
- package/README.md +269 -0
- package/docs/agents.md +44 -0
- package/docs/bibliography-setup.md +55 -0
- package/docs/council-mode.md +36 -0
- package/docs/getting-started.md +245 -0
- package/docs/hooks.md +38 -0
- package/docs/mcp-servers.md +82 -0
- package/docs/notion-setup.md +109 -0
- package/docs/rules.md +33 -0
- package/docs/scripts.md +303 -0
- package/docs/setup-overview/setup-overview.pdf +0 -0
- package/docs/skills.md +70 -0
- package/docs/system.md +159 -0
- package/hooks/block-destructive-git.sh +66 -0
- package/hooks/context-monitor.py +114 -0
- package/hooks/postcompact-restore.py +157 -0
- package/hooks/precompact-autosave.py +181 -0
- package/hooks/promise-checker.sh +124 -0
- package/hooks/protect-source-files.sh +81 -0
- package/hooks/resume-context-loader.sh +53 -0
- package/hooks/startup-context-loader.sh +102 -0
- package/package.json +51 -0
- package/packages/cli-council/.github/workflows/claude-code-review.yml +44 -0
- package/packages/cli-council/.github/workflows/claude.yml +50 -0
- package/packages/cli-council/README.md +100 -0
- package/packages/cli-council/pyproject.toml +43 -0
- package/packages/cli-council/src/cli_council/__init__.py +19 -0
- package/packages/cli-council/src/cli_council/__main__.py +185 -0
- package/packages/cli-council/src/cli_council/backends/__init__.py +8 -0
- package/packages/cli-council/src/cli_council/backends/base.py +81 -0
- package/packages/cli-council/src/cli_council/backends/claude.py +25 -0
- package/packages/cli-council/src/cli_council/backends/codex.py +27 -0
- package/packages/cli-council/src/cli_council/backends/gemini.py +26 -0
- package/packages/cli-council/src/cli_council/checkpoint.py +212 -0
- package/packages/cli-council/src/cli_council/config.py +51 -0
- package/packages/cli-council/src/cli_council/council.py +391 -0
- package/packages/cli-council/src/cli_council/models.py +46 -0
- package/packages/llm-council/.github/workflows/claude-code-review.yml +44 -0
- package/packages/llm-council/.github/workflows/claude.yml +50 -0
- package/packages/llm-council/README.md +453 -0
- package/packages/llm-council/pyproject.toml +42 -0
- package/packages/llm-council/src/llm_council/__init__.py +23 -0
- package/packages/llm-council/src/llm_council/__main__.py +259 -0
- package/packages/llm-council/src/llm_council/checkpoint.py +193 -0
- package/packages/llm-council/src/llm_council/client.py +253 -0
- package/packages/llm-council/src/llm_council/config.py +232 -0
- package/packages/llm-council/src/llm_council/council.py +482 -0
- package/packages/llm-council/src/llm_council/models.py +46 -0
- package/packages/mcp-bibliography/MEMORY.md +31 -0
- package/packages/mcp-bibliography/_app.py +226 -0
- package/packages/mcp-bibliography/formatters.py +158 -0
- package/packages/mcp-bibliography/log/2026-03-13-2100.md +35 -0
- package/packages/mcp-bibliography/pyproject.toml +15 -0
- package/packages/mcp-bibliography/run.sh +20 -0
- package/packages/mcp-bibliography/scholarly_formatters.py +83 -0
- package/packages/mcp-bibliography/server.py +1857 -0
- package/packages/mcp-bibliography/tools/__init__.py +28 -0
- package/packages/mcp-bibliography/tools/_registry.py +19 -0
- package/packages/mcp-bibliography/tools/altmetric.py +107 -0
- package/packages/mcp-bibliography/tools/core.py +92 -0
- package/packages/mcp-bibliography/tools/dblp.py +52 -0
- package/packages/mcp-bibliography/tools/openalex.py +296 -0
- package/packages/mcp-bibliography/tools/opencitations.py +102 -0
- package/packages/mcp-bibliography/tools/openreview.py +179 -0
- package/packages/mcp-bibliography/tools/orcid.py +131 -0
- package/packages/mcp-bibliography/tools/scholarly.py +575 -0
- package/packages/mcp-bibliography/tools/unpaywall.py +63 -0
- package/packages/mcp-bibliography/tools/zenodo.py +123 -0
- package/packages/mcp-bibliography/uv.lock +711 -0
- package/scripts/setup.sh +143 -0
- package/skills/beamer-deck/SKILL.md +199 -0
- package/skills/beamer-deck/references/quality-rubric.md +54 -0
- package/skills/beamer-deck/references/review-prompts.md +106 -0
- package/skills/bib-validate/SKILL.md +261 -0
- package/skills/bib-validate/references/council-mode.md +34 -0
- package/skills/bib-validate/references/deep-verify.md +79 -0
- package/skills/bib-validate/references/fix-mode.md +36 -0
- package/skills/bib-validate/references/openalex-verification.md +45 -0
- package/skills/bib-validate/references/preprint-check.md +31 -0
- package/skills/bib-validate/references/ref-manager-crossref.md +41 -0
- package/skills/bib-validate/references/report-template.md +82 -0
- package/skills/code-archaeology/SKILL.md +141 -0
- package/skills/code-review/SKILL.md +265 -0
- package/skills/code-review/references/quality-rubric.md +67 -0
- package/skills/consolidate-memory/SKILL.md +208 -0
- package/skills/context-status/SKILL.md +126 -0
- package/skills/creation-guard/SKILL.md +230 -0
- package/skills/devils-advocate/SKILL.md +130 -0
- package/skills/devils-advocate/references/competing-hypotheses.md +83 -0
- package/skills/init-project/SKILL.md +115 -0
- package/skills/init-project-course/references/memory-and-settings.md +92 -0
- package/skills/init-project-course/references/organise-templates.md +94 -0
- package/skills/init-project-course/skill.md +147 -0
- package/skills/init-project-light/skill.md +139 -0
- package/skills/init-project-research/SKILL.md +368 -0
- package/skills/init-project-research/references/atlas-pipeline-sync.md +70 -0
- package/skills/init-project-research/references/atlas-schema.md +81 -0
- package/skills/init-project-research/references/confirmation-report.md +39 -0
- package/skills/init-project-research/references/domain-profile-template.md +104 -0
- package/skills/init-project-research/references/interview-round3.md +34 -0
- package/skills/init-project-research/references/literature-discovery.md +43 -0
- package/skills/init-project-research/references/scaffold-details.md +197 -0
- package/skills/init-project-research/templates/field-calibration.md +60 -0
- package/skills/init-project-research/templates/pipeline-manifest.md +63 -0
- package/skills/init-project-research/templates/run-all.sh +116 -0
- package/skills/init-project-research/templates/seed-files.md +337 -0
- package/skills/insights-deck/SKILL.md +151 -0
- package/skills/interview-me/SKILL.md +157 -0
- package/skills/latex/SKILL.md +141 -0
- package/skills/latex/references/latex-configs.md +183 -0
- package/skills/latex-autofix/SKILL.md +230 -0
- package/skills/latex-autofix/references/known-errors.md +183 -0
- package/skills/latex-autofix/references/quality-rubric.md +50 -0
- package/skills/latex-health-check/SKILL.md +161 -0
- package/skills/learn/SKILL.md +220 -0
- package/skills/learn/scripts/validate_skill.py +265 -0
- package/skills/lessons-learned/SKILL.md +201 -0
- package/skills/literature/SKILL.md +335 -0
- package/skills/literature/references/agent-templates.md +393 -0
- package/skills/literature/references/bibliometric-apis.md +44 -0
- package/skills/literature/references/cli-council-search.md +79 -0
- package/skills/literature/references/openalex-api-guide.md +371 -0
- package/skills/literature/references/openalex-common-queries.md +381 -0
- package/skills/literature/references/openalex-workflows.md +248 -0
- package/skills/literature/references/reference-manager-sync.md +36 -0
- package/skills/literature/references/scopus-api-guide.md +208 -0
- package/skills/literature/references/wos-api-guide.md +308 -0
- package/skills/multi-perspective/SKILL.md +311 -0
- package/skills/multi-perspective/references/computational-many-analysts.md +77 -0
- package/skills/pipeline-manifest/SKILL.md +226 -0
- package/skills/pre-submission-report/SKILL.md +153 -0
- package/skills/process-reviews/SKILL.md +244 -0
- package/skills/process-reviews/references/rr-routing.md +101 -0
- package/skills/project-deck/SKILL.md +87 -0
- package/skills/project-safety/SKILL.md +135 -0
- package/skills/proofread/SKILL.md +254 -0
- package/skills/proofread/references/quality-rubric.md +104 -0
- package/skills/python-env/SKILL.md +57 -0
- package/skills/quarto-deck/SKILL.md +226 -0
- package/skills/quarto-deck/references/markdown-format.md +143 -0
- package/skills/quarto-deck/references/quality-rubric.md +54 -0
- package/skills/save-context/SKILL.md +174 -0
- package/skills/session-log/SKILL.md +98 -0
- package/skills/shared/concept-validation-gate.md +161 -0
- package/skills/shared/council-protocol.md +265 -0
- package/skills/shared/distribution-diagnostics.md +164 -0
- package/skills/shared/engagement-stratified-sampling.md +218 -0
- package/skills/shared/escalation-protocol.md +74 -0
- package/skills/shared/external-audit-protocol.md +205 -0
- package/skills/shared/intercoder-reliability.md +256 -0
- package/skills/shared/mcp-degradation.md +81 -0
- package/skills/shared/method-probing-questions.md +163 -0
- package/skills/shared/multi-language-conventions.md +143 -0
- package/skills/shared/paid-api-safety.md +174 -0
- package/skills/shared/palettes.md +90 -0
- package/skills/shared/progressive-disclosure.md +92 -0
- package/skills/shared/project-documentation-content.md +443 -0
- package/skills/shared/project-documentation-format.md +281 -0
- package/skills/shared/project-documentation.md +100 -0
- package/skills/shared/publication-output.md +138 -0
- package/skills/shared/quality-scoring.md +70 -0
- package/skills/shared/reference-resolution.md +77 -0
- package/skills/shared/research-quality-rubric.md +165 -0
- package/skills/shared/rhetoric-principles.md +54 -0
- package/skills/shared/skill-design-patterns.md +272 -0
- package/skills/shared/skill-index.md +240 -0
- package/skills/shared/system-documentation.md +334 -0
- package/skills/shared/tikz-rules.md +402 -0
- package/skills/shared/validation-tiers.md +121 -0
- package/skills/shared/venue-guides/README.md +46 -0
- package/skills/shared/venue-guides/cell_press_style.md +483 -0
- package/skills/shared/venue-guides/conferences_formatting.md +564 -0
- package/skills/shared/venue-guides/cs_conference_style.md +463 -0
- package/skills/shared/venue-guides/examples/cell_summary_example.md +247 -0
- package/skills/shared/venue-guides/examples/medical_structured_abstract.md +313 -0
- package/skills/shared/venue-guides/examples/nature_abstract_examples.md +213 -0
- package/skills/shared/venue-guides/examples/neurips_introduction_example.md +245 -0
- package/skills/shared/venue-guides/journals_formatting.md +486 -0
- package/skills/shared/venue-guides/medical_journal_styles.md +535 -0
- package/skills/shared/venue-guides/ml_conference_style.md +556 -0
- package/skills/shared/venue-guides/nature_science_style.md +405 -0
- package/skills/shared/venue-guides/reviewer_expectations.md +417 -0
- package/skills/shared/venue-guides/venue_writing_styles.md +321 -0
- package/skills/split-pdf/SKILL.md +172 -0
- package/skills/split-pdf/methodology.md +48 -0
- package/skills/sync-notion/SKILL.md +93 -0
- package/skills/system-audit/SKILL.md +157 -0
- package/skills/system-audit/references/sub-agent-prompts.md +294 -0
- package/skills/task-management/SKILL.md +131 -0
- package/skills/update-focus/SKILL.md +204 -0
- package/skills/update-project-doc/SKILL.md +194 -0
- package/skills/validate-bib/SKILL.md +242 -0
- package/skills/validate-bib/references/council-mode.md +34 -0
- package/skills/validate-bib/references/deep-verify.md +71 -0
- package/skills/validate-bib/references/openalex-verification.md +45 -0
- package/skills/validate-bib/references/preprint-check.md +31 -0
- package/skills/validate-bib/references/report-template.md +62 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"""Model registry and council defaults."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
ALLOWED_PROVIDERS = {"anthropic", "openai", "google"}
|
|
14
|
+
|
|
15
|
+
AVAILABLE_MODELS: list[dict[str, str]] = [
|
|
16
|
+
# Anthropic
|
|
17
|
+
{"id": "anthropic/claude-haiku-4.5", "name": "Claude Haiku 4.5", "tier": "fast, cheap"},
|
|
18
|
+
{"id": "anthropic/claude-sonnet-4.5", "name": "Claude Sonnet 4.5", "tier": "balanced"},
|
|
19
|
+
{"id": "anthropic/claude-sonnet-4.6", "name": "Claude Sonnet 4.6", "tier": "balanced, latest"},
|
|
20
|
+
{"id": "anthropic/claude-opus-4.5", "name": "Claude Opus 4.5", "tier": "most capable"},
|
|
21
|
+
{"id": "anthropic/claude-opus-4.6", "name": "Claude Opus 4.6", "tier": "most capable, latest"},
|
|
22
|
+
# OpenAI
|
|
23
|
+
{"id": "openai/gpt-4.1-mini", "name": "GPT-4.1 Mini", "tier": "fast, cheap"},
|
|
24
|
+
{"id": "openai/gpt-4.1", "name": "GPT-4.1", "tier": "balanced"},
|
|
25
|
+
{"id": "openai/gpt-5-mini", "name": "GPT-5 Mini", "tier": "fast"},
|
|
26
|
+
{"id": "openai/gpt-5", "name": "GPT-5", "tier": "balanced, latest"},
|
|
27
|
+
{"id": "openai/gpt-5.2", "name": "GPT-5.2", "tier": "most capable, latest"},
|
|
28
|
+
{"id": "openai/o3", "name": "o3", "tier": "reasoning"},
|
|
29
|
+
{"id": "openai/o4-mini", "name": "o4 Mini", "tier": "reasoning, cheap"},
|
|
30
|
+
# Google
|
|
31
|
+
{"id": "google/gemini-2.5-flash", "name": "Gemini 2.5 Flash", "tier": "fast, cheap"},
|
|
32
|
+
{"id": "google/gemini-2.5-pro", "name": "Gemini 2.5 Pro", "tier": "balanced"},
|
|
33
|
+
{"id": "google/gemini-3-flash-preview", "name": "Gemini 3 Flash", "tier": "fast, latest"},
|
|
34
|
+
{"id": "google/gemini-3-pro-preview", "name": "Gemini 3 Pro", "tier": "balanced, latest"},
|
|
35
|
+
{"id": "google/gemini-3.1-pro-preview", "name": "Gemini 3.1 Pro", "tier": "most capable, latest"},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
# Built-in defaults (used when no user config exists)
|
|
39
|
+
_BUILTIN_DEFAULT_MODELS: list[str] = [
|
|
40
|
+
"anthropic/claude-sonnet-4.5",
|
|
41
|
+
"openai/gpt-5",
|
|
42
|
+
"google/gemini-2.5-pro",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
_BUILTIN_DEFAULT_CHAIRMAN: str = "anthropic/claude-sonnet-4.5"
|
|
46
|
+
|
|
47
|
+
# User config file
|
|
48
|
+
USER_CONFIG_PATH = Path.home() / ".config" / "llm-council" / "config.json"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _load_user_config() -> dict | None:
|
|
52
|
+
"""Load user config from ~/.config/llm-council/config.json."""
|
|
53
|
+
if not USER_CONFIG_PATH.exists():
|
|
54
|
+
return None
|
|
55
|
+
try:
|
|
56
|
+
return json.loads(USER_CONFIG_PATH.read_text())
|
|
57
|
+
except (json.JSONDecodeError, OSError):
|
|
58
|
+
logger.warning("Could not parse %s — using built-in defaults", USER_CONFIG_PATH)
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_council_defaults() -> list[str]:
|
|
63
|
+
"""Return council default models (user config > built-in)."""
|
|
64
|
+
cfg = _load_user_config()
|
|
65
|
+
if cfg and "council_models" in cfg:
|
|
66
|
+
return cfg["council_models"]
|
|
67
|
+
return list(_BUILTIN_DEFAULT_MODELS)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_chairman_default() -> str:
|
|
71
|
+
"""Return chairman default model (user config > built-in)."""
|
|
72
|
+
cfg = _load_user_config()
|
|
73
|
+
if cfg and "chairman" in cfg:
|
|
74
|
+
return cfg["chairman"]
|
|
75
|
+
return _BUILTIN_DEFAULT_CHAIRMAN
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def set_council_defaults(
|
|
79
|
+
models: list[str] | None = None,
|
|
80
|
+
chairman: str | None = None,
|
|
81
|
+
) -> dict:
|
|
82
|
+
"""Persist council defaults to user config. Returns the saved config."""
|
|
83
|
+
cfg = _load_user_config() or {}
|
|
84
|
+
if models is not None:
|
|
85
|
+
cfg["council_models"] = models
|
|
86
|
+
if chairman is not None:
|
|
87
|
+
cfg["chairman"] = chairman
|
|
88
|
+
USER_CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
89
|
+
USER_CONFIG_PATH.write_text(json.dumps(cfg, indent=2) + "\n")
|
|
90
|
+
return cfg
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def reset_council_defaults() -> None:
|
|
94
|
+
"""Remove user config, reverting to built-in defaults."""
|
|
95
|
+
if USER_CONFIG_PATH.exists():
|
|
96
|
+
USER_CONFIG_PATH.unlink()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# Public constants that resolve user config automatically
|
|
100
|
+
COUNCIL_DEFAULT_MODELS: list[str] = get_council_defaults()
|
|
101
|
+
COUNCIL_DEFAULT_CHAIRMAN: str = get_chairman_default()
|
|
102
|
+
|
|
103
|
+
OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def model_display_name(model_id: str) -> str:
|
|
107
|
+
"""Human-readable name for a model ID."""
|
|
108
|
+
names = {m["id"]: m["name"] for m in AVAILABLE_MODELS}
|
|
109
|
+
return names.get(model_id, model_id.split("/")[-1])
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _auto_tier(input_price_per_m: float) -> str:
|
|
113
|
+
if input_price_per_m < 0.5:
|
|
114
|
+
return "fast, cheap"
|
|
115
|
+
if input_price_per_m < 3.0:
|
|
116
|
+
return "balanced"
|
|
117
|
+
return "most capable"
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def load_models(path: str | Path) -> list[dict[str, str]] | None:
|
|
121
|
+
"""Load saved models from a JSON file. Returns None if file missing."""
|
|
122
|
+
p = Path(path)
|
|
123
|
+
if not p.exists():
|
|
124
|
+
return None
|
|
125
|
+
try:
|
|
126
|
+
data = json.loads(p.read_text())
|
|
127
|
+
return data.get("models", [])
|
|
128
|
+
except (json.JSONDecodeError, KeyError):
|
|
129
|
+
logger.warning("Could not parse %s — falling back to defaults", path)
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def save_models(path: str | Path, models: list[dict[str, str]]) -> None:
|
|
134
|
+
"""Persist the active model list to a JSON file."""
|
|
135
|
+
cleaned = [
|
|
136
|
+
{"id": m["id"], "name": m["name"], "tier": m.get("tier", "")}
|
|
137
|
+
for m in models
|
|
138
|
+
]
|
|
139
|
+
Path(path).write_text(json.dumps({"models": cleaned}, indent=2) + "\n")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
async def _fetch_openrouter_data() -> list[dict] | None:
|
|
143
|
+
try:
|
|
144
|
+
async with httpx.AsyncClient(timeout=15) as client:
|
|
145
|
+
resp = await client.get(OPENROUTER_MODELS_URL)
|
|
146
|
+
resp.raise_for_status()
|
|
147
|
+
return resp.json().get("data", [])
|
|
148
|
+
except Exception:
|
|
149
|
+
logger.warning("Could not reach OpenRouter API")
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _enrich_with_pricing(
|
|
154
|
+
models: list[dict[str, str]], or_data: list[dict],
|
|
155
|
+
) -> list[dict[str, str]]:
|
|
156
|
+
price_map: dict[str, dict[str, str]] = {}
|
|
157
|
+
for entry in or_data:
|
|
158
|
+
mid = entry.get("id", "")
|
|
159
|
+
pricing = entry.get("pricing", {})
|
|
160
|
+
try:
|
|
161
|
+
inp = float(pricing.get("prompt", "0")) * 1_000_000
|
|
162
|
+
out = float(pricing.get("completion", "0")) * 1_000_000
|
|
163
|
+
price_map[mid] = {
|
|
164
|
+
"input_price": f"${inp:.2f}",
|
|
165
|
+
"output_price": f"${out:.2f}",
|
|
166
|
+
}
|
|
167
|
+
except (ValueError, TypeError):
|
|
168
|
+
price_map[mid] = {"input_price": "N/A", "output_price": "N/A"}
|
|
169
|
+
|
|
170
|
+
enriched = []
|
|
171
|
+
for m in models:
|
|
172
|
+
m2 = m.copy()
|
|
173
|
+
prices = price_map.get(m2["id"], {})
|
|
174
|
+
m2["input_price"] = prices.get("input_price", "N/A")
|
|
175
|
+
m2["output_price"] = prices.get("output_price", "N/A")
|
|
176
|
+
m2["provider"] = m2["id"].split("/")[0]
|
|
177
|
+
enriched.append(m2)
|
|
178
|
+
return enriched
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def fetch_model_pricing(
|
|
182
|
+
base_models: list[dict[str, str]] | None = None,
|
|
183
|
+
) -> list[dict[str, str]]:
|
|
184
|
+
"""Fetch pricing from OpenRouter and merge into a model list."""
|
|
185
|
+
models = [m.copy() for m in (base_models or AVAILABLE_MODELS)]
|
|
186
|
+
or_data = await _fetch_openrouter_data()
|
|
187
|
+
if or_data is None:
|
|
188
|
+
for m in models:
|
|
189
|
+
m.setdefault("input_price", "N/A")
|
|
190
|
+
m.setdefault("output_price", "N/A")
|
|
191
|
+
m.setdefault("provider", m["id"].split("/")[0])
|
|
192
|
+
return models
|
|
193
|
+
return _enrich_with_pricing(models, or_data)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
async def fetch_all_provider_models() -> list[dict[str, str]]:
|
|
197
|
+
"""Fetch ALL models from allowed providers via OpenRouter."""
|
|
198
|
+
or_data = await _fetch_openrouter_data()
|
|
199
|
+
if or_data is None:
|
|
200
|
+
return []
|
|
201
|
+
|
|
202
|
+
models: list[dict[str, str]] = []
|
|
203
|
+
for entry in or_data:
|
|
204
|
+
mid = entry.get("id", "")
|
|
205
|
+
provider = mid.split("/")[0] if "/" in mid else ""
|
|
206
|
+
if provider not in ALLOWED_PROVIDERS:
|
|
207
|
+
continue
|
|
208
|
+
|
|
209
|
+
pricing = entry.get("pricing", {})
|
|
210
|
+
try:
|
|
211
|
+
inp = float(pricing.get("prompt", "0")) * 1_000_000
|
|
212
|
+
out = float(pricing.get("completion", "0")) * 1_000_000
|
|
213
|
+
except (ValueError, TypeError):
|
|
214
|
+
inp, out = 0.0, 0.0
|
|
215
|
+
|
|
216
|
+
raw_name = entry.get("name", mid)
|
|
217
|
+
for prefix in ("Anthropic: ", "OpenAI: ", "Google: "):
|
|
218
|
+
if raw_name.startswith(prefix):
|
|
219
|
+
raw_name = raw_name[len(prefix):]
|
|
220
|
+
break
|
|
221
|
+
|
|
222
|
+
models.append({
|
|
223
|
+
"id": mid,
|
|
224
|
+
"name": raw_name,
|
|
225
|
+
"tier": _auto_tier(inp),
|
|
226
|
+
"provider": provider,
|
|
227
|
+
"input_price": f"${inp:.2f}",
|
|
228
|
+
"output_price": f"${out:.2f}",
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
models.sort(key=lambda m: (m["provider"], m["name"]))
|
|
232
|
+
return models
|