mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
ci/lint: prek commit gateway (ruff check/format + basedpyright)
Add prek.toml so git commit runs ruff-pre-commit (fix then format) and pdm-based basedpyright. Document install/install-hook; clear type warnings that made basedpyright exit non-zero under recommended mode.
This commit is contained in:
@@ -10,7 +10,6 @@ from plyngent.lmproto.openai_compatible.model import (
|
||||
ChatCompletionsParam,
|
||||
DeveloperChatMessage,
|
||||
SystemChatMessage,
|
||||
ToolChatMessage,
|
||||
UserChatMessage,
|
||||
)
|
||||
|
||||
@@ -44,7 +43,7 @@ _SEED_MESSAGE_TEMPLATE = (
|
||||
)
|
||||
|
||||
|
||||
def format_transcript(messages: Sequence[AnyChatMessage]) -> str: # noqa: C901
|
||||
def format_transcript(messages: Sequence[AnyChatMessage]) -> str:
|
||||
"""Render messages as plain text for a summarization prompt."""
|
||||
lines: list[str] = []
|
||||
for msg in messages:
|
||||
@@ -65,10 +64,9 @@ def format_transcript(messages: Sequence[AnyChatMessage]) -> str: # noqa: C901
|
||||
lines.append(f"[assistant tool_call] {call.function.name}({call.function.arguments})")
|
||||
else:
|
||||
lines.append(f"[assistant tool_call] custom id={call.id}")
|
||||
elif isinstance(msg, ToolChatMessage):
|
||||
lines.append(f"[tool {msg.tool_call_id}] {msg.content}")
|
||||
else:
|
||||
lines.append(f"[message] {msg!r}")
|
||||
# ToolChatMessage (remaining AnyChatMessage arm)
|
||||
lines.append(f"[tool {msg.tool_call_id}] {msg.content}")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ from plyngent.lmproto.openai_compatible.model import (
|
||||
StreamFunctionDelta,
|
||||
StreamToolCallDelta,
|
||||
SystemChatMessage,
|
||||
ToolChatMessage,
|
||||
ToolFunctionItem,
|
||||
UserChatMessage,
|
||||
)
|
||||
@@ -106,17 +105,14 @@ def chat_messages_to_responses_input(
|
||||
items.append(ResponseEasyInputMessage(role="user", content=message.content))
|
||||
elif isinstance(message, AssistantChatMessage):
|
||||
items.extend(_assistant_to_input_items(message))
|
||||
elif isinstance(message, ToolChatMessage):
|
||||
else:
|
||||
# ToolChatMessage (remaining AnyChatMessage arm)
|
||||
items.append(
|
||||
ResponseFunctionToolCallOutput(
|
||||
call_id=message.tool_call_id,
|
||||
output=message.content,
|
||||
)
|
||||
)
|
||||
else:
|
||||
content = getattr(message, "content", None)
|
||||
if isinstance(content, str) and content:
|
||||
items.append(ResponseEasyInputMessage(role="user", content=content))
|
||||
|
||||
instructions = "\n\n".join(instructions_parts) if instructions_parts else None
|
||||
return instructions, items
|
||||
@@ -173,13 +169,10 @@ def responses_status_to_finish_reason(
|
||||
status_s = status if isinstance(status, str) else None
|
||||
if status_s == "incomplete":
|
||||
details = response.incomplete_details
|
||||
reason = None
|
||||
if details is not UNSET and details is not None:
|
||||
raw_reason = details.reason
|
||||
if raw_reason is not UNSET and isinstance(raw_reason, str):
|
||||
reason = raw_reason
|
||||
if reason == "content_filter":
|
||||
return "content_filter"
|
||||
if raw_reason is not UNSET and raw_reason == "content_filter":
|
||||
return "content_filter"
|
||||
return "length"
|
||||
if status_s in {"failed", "cancelled"}:
|
||||
return status_s
|
||||
|
||||
@@ -95,7 +95,8 @@ class TodoStack:
|
||||
for frame in cast("list[object]", frames_raw):
|
||||
if not isinstance(frame, dict):
|
||||
continue
|
||||
frame_items = msgspec.convert(frame.get("items"), type=list[TodoItem])
|
||||
frame_map = cast("dict[str, object]", frame)
|
||||
frame_items = msgspec.convert(frame_map.get("items"), type=list[TodoItem])
|
||||
items.extend(frame_items)
|
||||
return cls(TodoStackData(items=items, next_id=next_id))
|
||||
except msgspec.ValidationError, TypeError, ValueError:
|
||||
|
||||
@@ -17,7 +17,6 @@ from plyngent.lmproto.openai_compatible.model import (
|
||||
AssistantFunctionToolCall,
|
||||
DeveloperChatMessage,
|
||||
SystemChatMessage,
|
||||
ToolChatMessage,
|
||||
UserChatMessage,
|
||||
)
|
||||
from plyngent.runtime import ProviderNotSupportedError
|
||||
@@ -36,7 +35,7 @@ _YOLO_MODE_CHOICES = ("on", "off", "once")
|
||||
_EXPORT_FORMAT_CHOICES = ("md", "json")
|
||||
|
||||
|
||||
class HistoryLimitType(click.ParamType):
|
||||
class HistoryLimitType(click.ParamType[int]):
|
||||
"""``N`` (int >= 1) or the shortcut ``last`` (equivalent to ``1``)."""
|
||||
|
||||
name: str = "history_limit"
|
||||
@@ -1100,15 +1099,9 @@ def _print_history_message_full(index: int, message: AnyChatMessage) -> None:
|
||||
if isinstance(message, AssistantChatMessage):
|
||||
_print_history_assistant_full(index, message)
|
||||
return
|
||||
if isinstance(message, ToolChatMessage):
|
||||
click.secho(f"{index}. tool({message.tool_call_id}):", fg="magenta")
|
||||
click.echo(message.content or "")
|
||||
click.echo()
|
||||
return
|
||||
role = getattr(message, "role", type(message).__name__)
|
||||
content = getattr(message, "content", "")
|
||||
click.echo(f"{index}. {role}:")
|
||||
click.echo(str(content))
|
||||
# ToolChatMessage (remaining AnyChatMessage arm)
|
||||
click.secho(f"{index}. tool({message.tool_call_id}):", fg="magenta")
|
||||
click.echo(message.content or "")
|
||||
click.echo()
|
||||
|
||||
|
||||
@@ -1134,11 +1127,8 @@ def _format_history_message(index: int, message: AnyChatMessage) -> str:
|
||||
parts.append(f"tool_calls=[{', '.join(names)}]")
|
||||
body = " ".join(parts) if parts else "(empty)"
|
||||
return f"{index}. assistant: {body}"
|
||||
if isinstance(message, ToolChatMessage):
|
||||
return f"{index}. tool({message.tool_call_id}): {_preview_content(message.content)}"
|
||||
role = getattr(message, "role", type(message).__name__)
|
||||
content = getattr(message, "content", "")
|
||||
return f"{index}. {role}: {_preview_content(str(content))}"
|
||||
# ToolChatMessage
|
||||
return f"{index}. tool({message.tool_call_id}): {_preview_content(message.content)}"
|
||||
|
||||
|
||||
def _run_slash_argv(args: Sequence[str], state: ReplState) -> None:
|
||||
|
||||
Reference in New Issue
Block a user