文件历史

22 次代码提交

作者 SHA1 备注 提交日期
Simon Willison 82b1f4c17a Docs: rewrite parts/messages section around messages= API
- python-api.md: 'Parts and stream events' section reworks the example
  code around response.messages[].parts and drops the old parts=
  parameter docs. New 'Prompting with messages' section shows the
  user/assistant/system/tool_message helpers, parallel tool calls as
  one assistant message, and Attachment-as-positional-arg.
- advanced-model-plugins.md: plugin author guide walks prompt.messages
  instead of the old flat prompt.parts + legacy fields. provider_metadata
  example no longer passes role= to TextPart; storage reference updated
  to message_parts table.
2026-04-12 21:50:46 -07:00
Simon Willison 5217a0bace Parts: serialization round-trip, stream safety, provider_metadata
Round out the parts API so transcripts survive serialization and so
providers can stash opaque multi-turn state on parts and stream events.

Serialization:
- AttachmentPart.from_dict now supported; inline content bytes round-trip
  as base64.
- ToolResultPart.attachments round-trip through to_dict/from_dict.

Stream assembler:
- _build_parts raises ValueError when an incompatible StreamEvent type
  appears at the same part_index, instead of silently overwriting the
  earlier part. tool_call_name and tool_call_args stay compatible.

OpenAI parts=[] support:
- build_messages emits assistant tool_calls and role:"tool" messages for
  ToolCallPart and ToolResultPart passed via parts=.

provider_metadata:
- New optional dict on TextPart, ReasoningPart, ToolCallPart,
  ToolResultPart, and StreamEvent for opaque provider data that must be
  echoed back on the next request (Anthropic signature/encrypted_content,
  Gemini thoughtSignature, OpenAI Responses encrypted_content).
- StreamEvent values merge onto the finalized Part per top-level namespace
  key, last non-None wins.
- Persisted via existing content_json column and reloaded by
  _load_parts_from_db; no schema change.
- Plugin author guide in docs/plugins/advanced-model-plugins.md.

Types:
- Widen execute() return types to Iterator[str | StreamEvent] /
  AsyncGenerator[str | StreamEvent, None] on abstract Model/AsyncModel
  bases and OpenAI Chat implementations.
- Initialize _reasoning_token_count on _BaseResponse so mypy stops
  flagging the OpenAI plugin.
2026-04-12 20:59:21 -07:00
Simon Willison 1562a8f444 Added some more autoclass docs, with new doctrings 2026-03-31 12:54:00 -07:00
Simon Willison 796e8952e8 Deploy advanced-model-plugins.md
!stable-docs

Refs #1137
2025-05-29 22:27:48 -07:00
Simon Willison f2cf81e29a Move LLM_RAISE_ERRORS to advanced model plugins, closes #1121 2025-05-28 08:02:25 -07:00
Simon Willison 301db6d76c responses.resolved_model column and response.set_resolved_model(model_id) method, closes #1117 2025-05-28 07:17:03 -07:00
Simon Willison fe7a1f0ee7 Tweaked header 2025-05-27 13:06:12 -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 35d460c5e3 How to add tool support to model plugins, closes #1000 2025-05-26 09:57:04 -07:00
Simon Willison 88b806ae1a Got multi-tool OpenAI chat working, in no-stream mode too
Refs #1017, #1019
2025-05-13 17:19:30 -07:00
Simon Willison 9a39af82cd Tip about lazy loading dependencies, closes #949
!stable-docs
2025-04-23 10:55:13 -07:00
Simon Willison 090e971bf4 Model feature list for advanced plugins documentation
!stable-docs
2025-03-19 21:43:17 -07:00
Simon Willison 8d32b71ef1 Renamed build_json_schema to schema_dsl 2025-02-27 10:22:29 -08:00
Simon Willison 62c90dd472 llm prompt --schema X option and model.prompt(..., schema=) parameter (#777)
Refs #776

* Implemented new llm prompt --schema and model.prompt(schema=)
* Log schema to responses.schema_id and schemas table
* Include schema in llm logs Markdown output
* Test for schema=pydantic_model
* Initial --schema CLI documentation
* Python docs for schema=
* Advanced plugin docs on schemas
2025-02-26 16:58:28 -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 e449fd4f46 Typo fix
!stable-docs
2025-01-22 22:17:07 -08:00
Simon Willison cfb10f4afd Log input tokens, output tokens and token details (#642)
* Store input_tokens, output_tokens, token_details on Response, closes #610
* llm prompt -u/--usage option
* llm logs -u/--usage option
* Docs on tracking token usage in plugins
* OpenAI default plugin logs usage
2024-11-19 20:21:59 -08:00
Simon Willison cf172cc70a response.text_or_raise() workaround
Closes https://github.com/simonw/llm/issues/632
2024-11-14 15:08:41 -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 7520671176 audio/wav not audio/wave, refs #603 2024-11-12 21:43:07 -08:00
Simon Willison 0cc4072bcd Support attachments without prompts, closes #611 2024-11-05 21:27:18 -08:00
Simon Willison 1126393ba1 Docs for writing models that accept attachments, refs #587 2024-10-28 15:41:34 -07:00