Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/kosong/src/kosong/contrib/chat_provider/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
MessageDeltaUsage,
MessageParam,
MessageStartEvent,
MetadataParam,
RawContentBlockDeltaEvent,
RawContentBlockStartEvent,
RawMessageStreamEvent,
Expand Down Expand Up @@ -127,12 +128,14 @@ def __init__(
tool_message_conversion: ToolMessageConversion | None = None,
# Must provide a max_tokens. Can be overridden by .with_generation_kwargs()
default_max_tokens: int,
metadata: MetadataParam | None = None,
**client_kwargs: Any,
):
self._model = model
self._stream = stream
self._client = AsyncAnthropic(api_key=api_key, base_url=base_url, **client_kwargs)
self._tool_message_conversion: ToolMessageConversion | None = tool_message_conversion
self._metadata = metadata
self._generation_kwargs: Anthropic.GenerationKwargs = {
"max_tokens": default_max_tokens,
"beta_features": ["interleaved-thinking-2025-05-14"],
Expand Down Expand Up @@ -222,6 +225,7 @@ async def generate(
tools=tools_,
stream=self._stream,
extra_headers=extra_headers,
metadata=self._metadata if self._metadata is not None else omit,
**generation_kwargs,
Comment on lines 225 to 229
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior: when metadata is set it will be forwarded into the Anthropic messages.create request, but the snapshot tests for the Anthropic provider don’t currently assert that metadata is included/omitted correctly. Add a test case that constructs Anthropic(metadata={"user_id": "..."}), calls generate(), and asserts the request body includes the expected metadata (and optionally another case where metadata is omitted when None).

Copilot uses AI. Check for mistakes.
)
return AnthropicStreamedMessage(response)
Expand Down
1 change: 1 addition & 0 deletions src/kimi_cli/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def create_llm(
base_url=provider.base_url,
api_key=resolved_api_key,
default_max_tokens=50000,
metadata={"user_id": session_id} if session_id else None,
)
Comment on lines 169 to 173
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_llm now conditionally passes Anthropic metadata derived from session_id, but tests/core/test_create_llm.py currently has no coverage for the Anthropic branch (or the session_id→metadata wiring). Add a unit test that calls create_llm(..., session_id="...") with an anthropic provider and asserts the constructed provider carries the expected metadata (or that its outgoing request includes it, if that’s the chosen assertion style).

Copilot uses AI. Check for mistakes.
case "google_genai" | "gemini":
from kosong.contrib.chat_provider.google_genai import GoogleGenAI
Expand Down
Loading