文件历史

提交图

62 次代码提交

作者 SHA1 备注 提交日期
Simon Willison 3da80543fe Phase 1: Part + Message value types
Add llm/parts.py with Part, TextPart, ReasoningPart, ToolCallPart,
ToolResultPart, AttachmentPart, Message, and StreamEvent dataclasses.
Parts round-trip through to_dict/from_dict (attachments base64-encoded);
role lives on Message, not on Part. Add user/assistant/system/
tool_message constructor helpers that accept strings, Attachments, Parts,
and nested lists.

Everything is a pure value — identity belongs to storage, which lives
elsewhere. No Response integration yet; that's Phase 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 09:27:32 -07:00
Simon Willison 7169fe9085 Add Usage to llm/__init__ __all__ (to fix Ruff)
Test / test (windows-latest, 3.10) (push) Has been cancelled
Test / test (windows-latest, 3.11) (push) Has been cancelled
Test / test (windows-latest, 3.12) (push) Has been cancelled
Test / test (windows-latest, 3.13) (push) Has been cancelled
Test / test (windows-latest, 3.14) (push) Has been cancelled
Test / test (macos-latest, 3.10) (push) Has been cancelled
Test / test (macos-latest, 3.11) (push) Has been cancelled
Test / test (macos-latest, 3.12) (push) Has been cancelled
Test / test (macos-latest, 3.13) (push) Has been cancelled
Test / test (macos-latest, 3.14) (push) Has been cancelled
Test / test (ubuntu-latest, 3.10) (push) Has been cancelled
Test / test (ubuntu-latest, 3.11) (push) Has been cancelled
Test / test (ubuntu-latest, 3.12) (push) Has been cancelled
Test / test (ubuntu-latest, 3.13) (push) Has been cancelled
Test / test (ubuntu-latest, 3.14) (push) Has been cancelled
2026-03-31 13:33:56 -07:00
Simon Willison 1562a8f444 Added some more autoclass docs, with new doctrings 2026-03-31 12:54:00 -07:00
Simon Willison 49d4e54639 register_models() model_aliases parameter 2026-03-31 12:45:38 -07:00
Simon Willison a04a6afa74 AsyncModel in llm.__all__, closes #1308 2025-11-25 13:44:42 -08:00
Simon Willison b5d1c5ee90 Tools can now return attachments
Closes #1014

- llm.ToolOutput(output='...', attachments=[...]) for tools to return attachments
- New table: `tool_results_attachments`
- Table is populated when tools return attachments
- llm --tools-debug shows attachments returned by tools
- llm logs shows attachments returned by tools
2025-06-01 10:08:36 -07:00
Simon Willison 330a568683 Raise error if a non-Toolbox subclass is passed to register(), closes #1114 2025-05-30 21:37:41 -07:00
Simon Willison 218bd10d6d Include dataclasses in plugin tool docs
Refs #1000

Refs https://github.com/simonw/llm/issues/997#issuecomment-2873497310
2025-05-26 10:05:10 -07:00
Simon Willison 7eb8acb767 llm.get_key() is now a documented utility, closes #1094
Refs #1093, https://github.com/simonw/llm-tools-datasette/issues/2
2025-05-26 09:39:40 -07:00
Simon Willison bb336d33a0 Toolbox class for class-based tool collections (#1086)
* Toolbox class for class-based tool collections

Refs #1059, #1058, #1057
2025-05-25 22:42:52 -07:00
Simon Willison d2886d4692 Record which plugin a tool came from, including in DB - refs #1020 2025-05-23 15:44:12 -07:00
Simon Willison e90705ebf1 Respect name= for register_tools, closes #1032 2025-05-21 21:53:22 -07:00
Simon Willison c81f0560e0 Fixed remaining mypy problems, refs #1023
Refs https://github.com/simonw/llm/pull/996#issuecomment-2878191352
2025-05-13 17:19:30 -07:00
Simon Willison e319069503 Initial implementation of --td and --ta, refs #1005
Uses new mechanism from #1007
2025-05-13 17:19:30 -07:00
Simon Willison 290c0f13f3 register_tools() hook, get_tools() utility
Refs #991
2025-05-13 17:19:30 -07:00
Simon Willison 7bc2f78156 Capture tool calls from OpenAI streaming sync responses
Refs https://github.com/simonw/llm/issues/988#issuecomment-2869079084
2025-05-13 17:19:30 -07:00
Simon Willison 84ab4cd409 supports_tools Model property, Tool.function(..., name=) option
Refs https://github.com/simonw/llm/issues/935#issuecomment-2869042481
2025-05-13 17:19:30 -07:00
Simon Willison e02863c1ca Fragment plugins can now optionally return attachments (#974)
Closes #972
2025-05-04 14:50:27 -07:00
Simon Willison a571a4e948 register_fragment_loaders() hook (#886)
* Docs and shape of register_fragment_loaders hook, refs #863
* Update docs for fragment loaders returning a list of FragmentString
* Support multiple fragments with same content, closes #888
* Call the pm.hook.register_fragment_loaders hook
* Test for register_fragment_loaders hook
* Rename FragmentString to Fragment

Closes #863
2025-04-06 17:03:34 -07:00
Simon Willison 6c9a8efb50 register_template_loaders plugin hook, closes #809
* Moved templates CLI commands next to each other
* llm templates loaders command
* Template loader tests
* Documentation for template loaders
2025-03-21 16:46:44 -07:00
Simon Willison 8d32b71ef1 Renamed build_json_schema to schema_dsl 2025-02-27 10:22:29 -08:00
Simon Willison 7bf1ea665e Made load_conversation() async_ aware, closes #742 2025-02-16 20:19:38 -08:00
Simon Willison 6c6b100f3e KeyModel and AsyncKeyModel classes for models that taken keys (#753)
* New KeyModel and AsyncKeyModel classes for models that taken keys - closes #744
* llm prompt --key now uses new mechanism, including for async
* use new key mechanism in llm chat command
* Python API tests for llm.KeyModel and llm.AsyncKeyModel
* Python API docs for for prompt(... key="")
* Mention await model.prompt() takes other parameters, reorg sections
* Better title for the model tutorial
* Docs on writing model plugins that take a key
2025-02-16 14:38:51 -08:00
Simon Willison b6be09aa28 Fix get_models() and get_async_models() duplicates bug
Closes #667, refs #640
2024-12-05 13:44:07 -08:00
Simon Willison c52cfee881 llm.get_models() and llm.get_async_models(), closes #640 2024-11-20 20:09:06 -08:00
Simon Willison ba75c674cb llm.get_async_model(), llm.AsyncModel base class and OpenAI async models (#613)
- https://github.com/simonw/llm/issues/507#issuecomment-2458639308

* register_model is now async aware

Refs https://github.com/simonw/llm/issues/507#issuecomment-2458658134

* Refactor Chat and AsyncChat to use _Shared base class

Refs https://github.com/simonw/llm/issues/507#issuecomment-2458692338

* fixed function name

* Fix for infinite loop

* Applied Black

* Ran cog

* Applied Black

* Add Response.from_row() classmethod back again

It does not matter that this is a blocking call, since it is a classmethod

* Made mypy happy with llm/models.py

* mypy fixes for openai_models.py

I am unhappy with this, had to duplicate some code.

* First test for AsyncModel

* Still have not quite got this working

* Fix for not loading plugins during tests, refs #626

* audio/wav not audio/wave, refs #603

* Black and mypy and ruff all happy

* Refactor to avoid generics

* Removed obsolete response() method

* Support text = await async_mock_model.prompt("hello")

* Initial docs for llm.get_async_model() and await model.prompt()

Refs #507

* Initial async model plugin creation docs

* duration_ms ANY to pass test

* llm models --async option

Refs https://github.com/simonw/llm/pull/613#issuecomment-2474724406

* Removed obsolete TypeVars

* Expanded register_models() docs for async

* await model.prompt() now returns AsyncResponse

Refs https://github.com/simonw/llm/pull/613#issuecomment-2475157822

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-13 17:51:00 -08:00
Simon Willison 330e171e86 Fix for not loading plugins during tests, refs #626 2024-11-12 21:42:49 -08:00
Simon Willison be2953e6ab Ruff and mypy fixes 2024-10-28 15:41:34 -07:00
Simon Willison 6df00f92ff First working prototype of new attachments feature, refs #587 2024-10-28 15:41:34 -07:00
Simon Willison 6deed8f976 get_model() improvement, get_default_model() / set_default_wodel() now documented
Refs #553
2024-08-18 17:37:31 -07:00
Simon Willison ed5a535484 Apply Black, refs #378 2024-01-25 17:29:28 -08:00
Simon Willison d9d9bb38d7 Drop Python 3.7, add 3.8, fix pkg_resources warning, refs #378 2024-01-25 16:48:49 -08:00
Simon Willison 6c43948325 llm.user_dir() creates directory if needed, closes #275
Would have fixed this bug too:
- https://github.com/simonw/llm-sentence-transformers/issues/9
2023-09-13 15:58:18 -07:00
Simon Willison 6012f31e36 llm plugins --all option, closes #259 2023-09-10 14:18:16 -07:00
Simon Willison b84f6f9ffd Docs for LLM_LOAD_PLUGINS, closes #256 2023-09-10 14:12:37 -07:00
Simon Willison a54743f228 Fix to get embedding set_alias to work
Refs:
- https://github.com/simonw/llm-sentence-transformers/issues/4
- https://github.com/simonw/llm/issues/192
2023-09-03 18:15:45 -07:00
Simon Willison 0eda99e91c Default embedding model finishing touches, closes #222 2023-09-03 17:21:47 -07:00
Simon Willison 0ec516559a Collection.similar methods, refs #191 2023-09-01 16:26:58 -07:00
Simon Willison 6f761702dc Initial Collection class plus test, refs #191 2023-09-01 13:04:05 -07:00
Simon Willison 77cf56e54a Initial CLI support and plugin hook for embeddings, refs #185
* Embeddings plugin hook + OpenAI implementation
* llm.get_embedding_model(name) function
* llm embed command, for returning embeddings or saving them to SQLite
* Tests using an EmbedDemo embedding model
* llm embed-models list and emeb-models default commands
* llm embed-db path and llm embed-db collections commands
2023-08-27 22:24:10 -07:00
Simon Willison dff36f0edc Change of policy: keys.json over-rides environment variables, closes #158 2023-08-20 23:27:21 -07:00
Simon Willison c290b44d45 llm.remove_alias() function, refs #154 2023-08-19 22:06:51 -07:00
Simon Willison 8cdcf1e689 llm.set_alias() function, refs #154 2023-08-19 22:01:29 -07:00
Simon Willison d31d97e06f Refactor get_key() with docs and better varible names
The actual logic is unchanged, but it is a lot easier to understand what it does now.

Refs #158
2023-08-17 15:03:55 -07:00
Simon Willison 6a578c35cf mypy fix for new aliases code, refs #151 2023-08-12 09:17:29 -07:00
Simon Willison 458a59a8f4 Actually register aliases from aliases.json, closes #151 2023-08-12 09:15:17 -07:00
Simon Willison 7bef414de7 Nicer error message for unknown models with -c mode, closes #92 2023-07-11 19:29:54 -07:00
Simon Willison c7271dd6b4 llm.ModelError class, refs #96 2023-07-11 10:52:48 -07:00
Simon Willison 2554a06e36 Docs for llm.user_dir(), closes #83 2023-07-11 07:43:57 -07:00
Simon Willison 88d839fa85 Create conversations and responses tables and write to them, refs #91 2023-07-11 07:21:22 -07:00