EVEMISSTechnology

Repository 指南 · 概覽 · v6

simonw / llm

“Access large language models from the command-line” — 作者自述

  • CLI Tools
  • Python
  • Apache-2.0 · 開源授權
原始 repository
simonw/llm
來源平台
GitHub
擁有者 / 組織
simonw
授權
Apache-2.0 · 開源授權
分析的版本
1df47ddcac20d58726a993949da8ef84f4081085
最後驗證

原始專案有更新,本指南有部分內容可能已經過時。預設分支已前進到 764dc386c58b,2026-10-03 檢查。整份指南描述的是版本 1df47ddcac20。版本差異比對發現,本指南引用的 2 個程式碼區域在新版本有變動(列在下面);關於這些區域的敘述在新版本不一定成立,目前還沒有重新核對。

  • llm/default_plugins/openai_models.py:40-448 · 行有變動
  • llm/default_plugins/openai_models.py:514-895 · 行有變動

本頁中文由負責的 AI 編輯依英文正式版本 v6 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文

simonw/llm repository 概覽:從命令列使用 LLM

本頁用語說明
Entrypoint record(進入點記錄)
分析器標記為「程式可能從這裡開始執行」的檔案。附有 __main__ guard 摘錄時,表示檔案裡有 if __name__ == "__main__": 區塊,摘錄顯示它呼叫了什麼;沒有摘錄時,只是依檔名判斷。
Bounded static execution path(有界靜態執行路徑)
不執行程式、直接從原始碼重建出的呼叫鏈,走到固定步數就停。它說明在紙面上能追到多遠,不代表實際執行時會發生什麼。
Unresolved boundary(未解析邊界)
靜態路徑停下的地方:下一個呼叫進入外部函式庫,或不執行就無法確定。這是本次分析的邊界,不是 repository 的缺陷。
Static relations(靜態關係)
在原始碼中找到的呼叫與 import。「external or unresolved」表示指向分析範圍以外。
Module role(模組角色)
分析器依呼叫進出次數推論的檔案標籤(例如 core、entry/orchestration、leaf)。它描述的是在呼叫圖中的位置,不是作者的設計意圖。
Test-like files(類測試檔案)
名稱或位置看起來像測試的檔案。本次分析只計數,不執行。
Observed · inferred · author-claimed · unresolved
每句話的依據:直接讀自分析的檔案;由分析器從檔案推論;repository 作者自述(metadata、README);或本次分析無法確定。
Verified(已驗證)
本頁有兩種用法。在分析器的記錄裡(「verified provenance」「verified entrypoint」),它表示這筆記錄是直接從分析的檔案讀到的,也就是本指南所說的 observed;以進入點來說,就是檔案裡確實有 __main__ guard 的文字。分析器在 2026-10-04 修正後,只有 cli.py、main.py 這類像進入點的檔名、沒有 guard 的檔案,會記為 inferred(推測);在那之前分析的指南仍把這類檔案標成 verified,它依然只是對檔案用途的推測。它不代表程式被執行或測試過。「最後驗證」是這份指南最後一次通過本實驗室檢查的日期,檢查對象是所標示版本的分析記錄,不是對 repository 本身的審查。

一個 Python 命令列工具,平台 metadata 把它描述為從終端機使用大型語言模型的工具;採用 Apache-2.0 授權,分析了 116 個檔案。執行從一個呼叫 cli() 的 __main__ 守衛開始,cli() 再透過靜態分析看不穿的邊界載入外掛。目錄配置:docs、llm 和 tests,其中有 44 個測試檔案。

它是什麼

平台 metadata 把這個 repository 描述為一個「Access large language models from the command-line」(從命令列使用大型語言模型)的工具,首頁在 https://llm.datasette.io 。程式碼幾乎全是 Python:平台列出的主要語言是 Python,在計入的語言位元組中約有 1.23 百萬個位元組。這個專案採用 Apache-2.0 授權,根目錄有 LICENSE 檔案。平台 metadata 記錄了 12,489 個 star(2026-09-12),最新的 release 是 0.35,於 2026-09-07 發布。靜態分析涵蓋了 116 個檔案。

它怎麼啟動

把這個套件當作腳本執行時,會從 llm/__main__.py 開始,裡面有這個執行守衛:

if __name__ == "__main__":
    cli()

一條有界執行路徑把這個守衛連到 llm/cli.py 裡的 cli 函式;分析器也依檔名啟發式規則把 llm/cli.py 標為可能的可執行進入點。從那裡開始,靜態路徑顯示 llm/cli.py 會呼叫 llm/plugins.py 裡的 load_plugins。這些載入外掛的路徑停在 pm.load_setuptools_entrypoints 和 hasattr 這類未解析邊界,所以外掛探索實際上做了什麼,不在靜態分析看得到的範圍內。依靜態呼叫次數,分析器把 llm/cli.py 標為 entry/orchestration 候選,有 105 個呼入和 245 個呼出。

結構

這個 repository 分成三個頂層子系統:docs、llm 和 tests;分析器在 docs 底下算到 35 個檔案、llm 底下 20 個、tests 底下 44 個。在被分析的模組中,llm/__init__.py 的呼入次數最高:754 個呼入、48 個呼出,這暗示它是整個套件共用的對外介面。其次是 llm/parts.py,有 470 個呼入;llm/models.py(130 個呼入)和 llm/logs.py(123 個呼入)也是核心候選。分析器總共記錄了 9,698 條靜態關係:9,116 個呼叫和 582 個 import,其中 2,324 條解析到本地目標,7,374 條仍是外部或未解析。有一個測試模組 tests/test_parts.py 有 422 個呼出、沒有任何呼入,分析器把它解讀為 orchestration 候選。

依賴與測試

唯一擷取到的依賴記錄來自 docs/requirements.txt,內容是文件工具:sphinx(固定在 7.2.6)、furo、sphinx-autobuild、sphinx-copybutton、sphinx-markdown-builder、myst-parser 和 cogapp。這些記錄裡沒有執行期依賴,因為分析器不解析 pyproject.toml 的依賴表。這個 repository 確實有三個建置/依賴清單檔,所以打包資訊是存在的,只是只被讀了一部分。測試方面,分析器算到 44 個測試檔案。在列出的測試模組中,tests/test_logs_store.py 有 58 個呼入和 348 個呼出,tests/test_openai_messages.py 有 27 個呼入和 92 個呼出,tests/test_openai_responses.py 有 26 個呼入和 93 個呼出。tests/test_logs_store.py 定義了 TestCanonicalJson、TestMessageHash、TestSchema、TestChainRoundTrip、TestDedup、TestThreads、TestForking 和 TestPendingToolCalls 等測試類別,而 llm/logs.py 定義了 LogStore 類別。

先讀什麼

先讀 README.md(分析器把它歸為專案層級的重要檔案),再依這個順序往下:

  • pyproject.toml(這個 repository 三個依賴清單檔之一),以及根目錄的 LICENSE 檔案。
  • 進入鏈:llm/__main__.py 和 llm/cli.py。
  • 被引用最多的模組 llm/__init__.py,以及 llm/plugins.py,進入鏈會走到它的 load_plugins。
  • 被大量引用的 service/core 模組 llm/models.py 和 llm/parts.py,接著看 logging 那一側的 llm/logs.py。

這次分析的限制

這份指南只依據靜態分析:反射、執行期依賴注入、動態 import、monkey-patching、產生的程式碼、框架在執行期的接線和動態分派都沒有解析。涵蓋範圍並不完整:9,698 條靜態關係中有 7,374 條仍是外部或未解析。外掛載入是一道硬邊界:從 llm/cli.py 進入 load_plugins 的有界路徑,停在 pm.load_setuptools_entrypoints 和 LLM_LOAD_PLUGINS.split 這類未解析的呼叫,所以動態載入的外掛做了什麼,在這裡完全看不到。依賴資料並不完整:只解析了 requirements 形式的依賴清單,pyproject.toml 的依賴表被略過。安裝、執行與建置流程的推論並不完整,安裝指令也沒有經過這次分析驗證。從 README 擷取的文字是逐行取出的,可能抓到程式碼而不是說明文字,所以這類文字應視為作者自述。

值得注意的符號

  • llm/__init__.py 集中了查詢用的輔助函式:get_plugins、get_models_with_aliases、get_tools、get_embedding_model 和 get_model_aliases。
  • llm/parts.py 定義了訊息片段(message part)的模型:Part、TextPart、ReasoningPart、ToolCallPart、ToolResultPart、AttachmentPart 和 Message,另有 normalize_parts 以及 system、user 兩個輔助函式。
  • llm/models.py 定義了面向模型的型別:Usage、Attachment、Tool、ServerSideTool、Toolbox、ToolCall、ToolResult 和 ToolOutput。
  • llm/logs.py 以 LogStore(第 143-711 行)為中心,搭配 canonical_json、content_hash 和 message_hash 等輔助函式。
  • llm/default_plugins/openai_models.py 有 register_models、register_embedding_models 和 register_commands,還有一個 OpenAIEmbeddingModel 類別。

這次分析無法確定的事

這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。

  • 執行時會載入哪些外掛、外掛探索是否成功,都無法確定;load_plugins 路徑停在未解析邊界。
  • pyproject.toml 裡的執行期依賴宣告不明,因為只解析了 requirements 形式的依賴清單。
  • 這次分析沒有實際執行任何東西:沒有安裝、沒有建置,也沒有執行指令。
  • 有 7,374 條靜態關係仍是外部或未解析,包括動態分派和動態 import。
  • 大小寫不同的 readme.md 被排除在重要檔案清單之外,因為它不在被分析的檔案清單裡。
陳述與依據 — 39 條陳述,39 條經獨立驗證者確認(英文原文)

上面每一句都是一條陳述,各自引用分析裡的依據編號。編號是這次分析內部的;表格列出每條陳述靠的是什麼、依據有多強。

Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.

Claim Epistemic status Verifier Grounding (global IDs)
c1 Platform metadata describes the repository as a tool to "Access large language models from the command-line" and gives https://llm.datasette.io as its homepage. author_claimed supported analysis_f20a9f60553ce57f:meta_description, analysis_f20a9f60553ce57f:meta_homepage
c2 The codebase is almost entirely Python: platform metadata lists Python as the primary language with about 1.23 million counted language bytes. observed supported analysis_f20a9f60553ce57f:meta_primary_language, analysis_f20a9f60553ce57f:meta_language_bytes
c3 The project is licensed Apache-2.0 and includes a root-level LICENSE file. observed supported analysis_f20a9f60553ce57f:meta_license, analysis_f20a9f60553ce57f:important_4
c4 Platform metadata records 12,489 stargazers (2026-09-12) and a latest release, 0.35, published 2026-09-07. observed supported analysis_f20a9f60553ce57f:meta_stars, analysis_f20a9f60553ce57f:meta_latest_release
c5 Static analysis covered 116 files. inferred supported analysis_f20a9f60553ce57f:summary_repository
c6 llm/__main__.py contains a Python __main__ execution guard that calls cli(). observed supported analysis_f20a9f60553ce57f:py_entry_8d052da6b4aa
c7 A bounded execution path connects the llm/__main__.py guard to the cli function in llm/cli.py. inferred supported analysis_f20a9f60553ce57f:exec_1883828468e7
c8 The analyzer flags llm/cli.py as a likely executable entrypoint by filename heuristic. observed supported analysis_f20a9f60553ce57f:entry_1
c9 Static paths show llm/cli.py calling load_plugins in llm/plugins.py. inferred supported analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_bbf7b5170507, analysis_f20a9f60553ce57f:exec_cf7f251ec694, analysis_f20a9f60553ce57f:exec_25ee09cebebb
c10 The plugin-loading paths terminate at unresolved boundaries such as pm.load_setuptools_entrypoints and hasattr, so plugin discovery behavior sits outside the static view. inferred supported analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_bbf7b5170507
c11 By static call degree the analyzer labels llm/cli.py an entry/orchestration candidate, with 105 incoming and 245 outgoing calls. inferred supported analysis_f20a9f60553ce57f:role_4
c12 The repository organizes into three top-level subsystems: docs, llm, and tests. observed supported analysis_f20a9f60553ce57f:subsys_1, analysis_f20a9f60553ce57f:subsys_2, analysis_f20a9f60553ce57f:subsys_3
c13 The analyzer counts 35 files under docs, 20 under llm, and 44 under tests. inferred supported analysis_f20a9f60553ce57f:summary_repository
c14 llm/__init__.py has the highest incoming call count among listed modules — 754 incoming against 48 outgoing — which suggests it acts as the package's shared surface. inferred supported analysis_f20a9f60553ce57f:role_2
c15 llm/parts.py has 470 incoming calls; llm/models.py has 130 and llm/logs.py 123, and both are core candidates. inferred supported analysis_f20a9f60553ce57f:role_12, analysis_f20a9f60553ce57f:role_11, analysis_f20a9f60553ce57f:role_9
c16 The analyzer recorded 9,698 static relations (9,116 calls, 582 imports); 2,324 resolved locally and 7,374 stayed external or unresolved. observed supported analysis_f20a9f60553ce57f:relation_counts
c17 tests/test_parts.py shows 422 outgoing calls and none incoming, which the analyzer reads as an orchestration candidate. inferred supported analysis_f20a9f60553ce57f:role_35
c18 The only captured dependency records come from docs/requirements.txt and describe documentation tooling: sphinx (pinned 7.2.6), furo, sphinx-autobuild, sphinx-copybutton, sphinx-markdown-builder, myst-parser, and cogapp. observed supported analysis_f20a9f60553ce57f:dep_1, analysis_f20a9f60553ce57f:dep_2, analysis_f20a9f60553ce57f:dep_3, analysis_f20a9f60553ce57f:dep_4, analysis_f20a9f60553ce57f:dep_5, analysis_f20a9f60553ce57f:dep_6, analysis_f20a9f60553ce57f:dep_7
c19 Runtime dependencies are absent from the records because the analyzer does not parse pyproject.toml dependency tables. observed supported analysis_f20a9f60553ce57f:lim_3
c20 The repository contains three build/dependency manifest files, so packaging information exists but was only partially read. observed supported analysis_f20a9f60553ce57f:ev_manifest_1, analysis_f20a9f60553ce57f:lim_3
c21 The analyzer counted 44 test files. observed supported analysis_f20a9f60553ce57f:ev_tests_1
c22 Among the listed test modules, tests/test_logs_store.py has 58 incoming and 348 outgoing calls, tests/test_openai_messages.py has 27 incoming and 92 outgoing, and tests/test_openai_responses.py has 26 incoming and 93 outgoing. inferred supported analysis_f20a9f60553ce57f:role_30, analysis_f20a9f60553ce57f:role_33, analysis_f20a9f60553ce57f:role_34
c23 tests/test_logs_store.py defines test classes including TestCanonicalJson, TestMessageHash, TestSchema, TestChainRoundTrip, TestDedup, TestThreads, TestForking, and TestPendingToolCalls; llm/logs.py defines the LogStore class. observed supported analysis_f20a9f60553ce57f:py_class_c59e4f001cc5, analysis_f20a9f60553ce57f:py_class_a3431f6d8baf, analysis_f20a9f60553ce57f:py_class_6c8514e9876a, analysis_f20a9f60553ce57f:py_class_d874ffc278ff, analysis_f20a9f60553ce57f:py_class_ef348f556c51, analysis_f20a9f60553ce57f:py_class_ea12736c1139, analysis_f20a9f60553ce57f:py_class_bb2a35c93fa0, analysis_f20a9f60553ce57f:py_class_ba1eb0a80d60, analysis_f20a9f60553ce57f:py_class_861b6a204af3
c24 README.md is classed by the analyzer as a project-level important file, so it is the natural first read. observed supported analysis_f20a9f60553ce57f:important_1
c25 pyproject.toml is one of the repository's three build/dependency manifests, and a LICENSE file sits at the root. observed supported analysis_f20a9f60553ce57f:important_3, analysis_f20a9f60553ce57f:ev_manifest_1, analysis_f20a9f60553ce57f:important_4
c26 The entry chain is llm/__main__.py followed by llm/cli.py. observed supported analysis_f20a9f60553ce57f:important_5, analysis_f20a9f60553ce57f:important_6, analysis_f20a9f60553ce57f:py_entry_8d052da6b4aa
c27 Next, llm/__init__.py is the most referenced module, and llm/plugins.py contains the load_plugins call the entry chain reaches. inferred supported analysis_f20a9f60553ce57f:role_2, analysis_f20a9f60553ce57f:exec_c714034a13f9
c28 Finish with llm/models.py and llm/parts.py, heavily referenced service/core modules, and llm/logs.py for the logging side. inferred supported analysis_f20a9f60553ce57f:role_11, analysis_f20a9f60553ce57f:role_12, analysis_f20a9f60553ce57f:role_9
c29 The analysis is static only: reflection, runtime dependency injection, dynamic imports, monkey-patching, generated code, framework runtime wiring, and dynamic dispatch are not resolved. observed supported analysis_f20a9f60553ce57f:lim_1
c30 Coverage is partial: 7,374 of the 9,698 static relations remained external or unresolved. observed supported analysis_f20a9f60553ce57f:relation_counts
c31 Plugin loading is a hard boundary: bounded paths from llm/cli.py into load_plugins end at unresolved calls such as pm.load_setuptools_entrypoints and LLM_LOAD_PLUGINS.split, so dynamically loaded plugin behavior is invisible to this analysis. inferred supported analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_cf7f251ec694
c32 Dependency data is incomplete: only requirements-style manifests were parsed; pyproject.toml dependency tables were skipped. observed supported analysis_f20a9f60553ce57f:lim_3
c33 Install, run, and build flow inference is partial, and installation commands are unverified by this analysis. observed supported analysis_f20a9f60553ce57f:lim_2
c34 README-derived text is extracted line by line and may capture code instead of prose, so it should be read as author-claimed. observed supported analysis_f20a9f60553ce57f:lim_4
c35 llm/__init__.py concentrates lookup helpers: get_plugins, get_models_with_aliases, get_tools, get_embedding_model, and get_model_aliases. observed supported analysis_f20a9f60553ce57f:py_func_b506016ee9cb, analysis_f20a9f60553ce57f:py_func_dcf6267c03ad, analysis_f20a9f60553ce57f:py_func_476d9808f6f6, analysis_f20a9f60553ce57f:py_func_950a3b14de8b, analysis_f20a9f60553ce57f:py_func_ae5e3dc917be
c36 llm/parts.py defines the message-part model: Part, TextPart, ReasoningPart, ToolCallPart, ToolResultPart, AttachmentPart, and Message, plus normalize_parts and the system and user helpers. observed supported analysis_f20a9f60553ce57f:py_class_e405bd6299b8, analysis_f20a9f60553ce57f:py_class_11475bf90694, analysis_f20a9f60553ce57f:py_class_7fda580a5258, analysis_f20a9f60553ce57f:py_class_85b1b68efc46, analysis_f20a9f60553ce57f:py_class_ec9c6c4c70cd, analysis_f20a9f60553ce57f:py_class_fde29fbfcdf5, analysis_f20a9f60553ce57f:py_class_8b0cd450e370, analysis_f20a9f60553ce57f:py_func_c8a35b884418, analysis_f20a9f60553ce57f:py_func_3c1e67a86835, analysis_f20a9f60553ce57f:py_func_4fff1179a215
c37 llm/models.py defines model-facing types: Usage, Attachment, Tool, ServerSideTool, Toolbox, ToolCall, ToolResult, and ToolOutput. observed supported analysis_f20a9f60553ce57f:py_class_1cf62603547b, analysis_f20a9f60553ce57f:py_class_77c3bda28bf3, analysis_f20a9f60553ce57f:py_class_0ac0d456aaac, analysis_f20a9f60553ce57f:py_class_5f55e4c4befa, analysis_f20a9f60553ce57f:py_class_448a3b899038, analysis_f20a9f60553ce57f:py_class_db5c48316c4b, analysis_f20a9f60553ce57f:py_class_bcd768a80e23, analysis_f20a9f60553ce57f:py_class_a119860c2d60
c38 llm/logs.py centers on LogStore (lines 143-711) with canonical_json, content_hash, and message_hash helpers. observed supported analysis_f20a9f60553ce57f:py_class_861b6a204af3, analysis_f20a9f60553ce57f:py_func_145efc3329cd, analysis_f20a9f60553ce57f:py_func_5d911d7e0494, analysis_f20a9f60553ce57f:py_func_678618701eb5
c39 llm/default_plugins/openai_models.py holds register_models, register_embedding_models, and register_commands, plus an OpenAIEmbeddingModel class. observed supported analysis_f20a9f60553ce57f:py_func_e9f6a58f456f, analysis_f20a9f60553ce57f:py_func_4816ca37a50d, analysis_f20a9f60553ce57f:py_func_dd176d248cb5, analysis_f20a9f60553ce57f:py_class_12b36795c0e9

來源、權利與說明 · attribution-license-templates/v0.1

權利聲明。原始 repository 託管於 GitHub。其原始碼、文件、名稱、媒體與相關素材的權利,仍屬各自的作者、貢獻者與其他權利人所有,並受該 repository 的授權條款約束。

Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.

平台聲明。GitHub 是所連結 repository 的來源託管平台。GitHub 與相關標誌為 GitHub, Inc. 的商標。除非另有明確說明,EVEMISS Technology 與 GitHub 之間沒有隸屬或背書關係。

GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.

這一頁怎麼來的。本頁由對應版本的 repository 分析與 AI 輔助的編輯工具產生。技術陳述綁定所分析的版本;原始 repository 更新後,可能重新驗證。

This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.

本頁包含 AI 輔助分析,並經 EVEMISS Technology 人工與 AI 協力審閱。 · 回報權利疑慮 · 所有 repository 指南