mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-21 03:41:55 +03:00
Cleanup and fix mypy (#23283)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
This commit is contained in:
parent
66a2417229
commit
a4a592b4e6
@ -5,7 +5,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, AsyncGenerator, Callable, Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
@ -359,6 +359,41 @@ class GenAIClient:
|
|||||||
"finish_reason": "error",
|
"finish_reason": "error",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def chat_with_tools_stream(
|
||||||
|
self,
|
||||||
|
messages: list[dict[str, Any]],
|
||||||
|
tools: Optional[list[dict[str, Any]]] = None,
|
||||||
|
tool_choice: Optional[str] = "auto",
|
||||||
|
enable_thinking: Optional[bool] = None,
|
||||||
|
) -> AsyncGenerator[tuple[str, Any], None]:
|
||||||
|
"""Streaming counterpart to `chat_with_tools`.
|
||||||
|
|
||||||
|
Yields ``(kind, value)`` tuples where ``kind`` is one of:
|
||||||
|
- 'content_delta': value is a string fragment of the answer
|
||||||
|
- 'reasoning_delta': value is a string fragment of the reasoning
|
||||||
|
trace (emitted before content for thinking models)
|
||||||
|
- 'stats': value is a usage stats dict
|
||||||
|
- 'message': value is the final dict shape described in
|
||||||
|
`chat_with_tools`
|
||||||
|
|
||||||
|
Argument semantics — including ``enable_thinking`` — match
|
||||||
|
`chat_with_tools`. Providers that don't support streaming should
|
||||||
|
override this and yield an error 'message' event.
|
||||||
|
"""
|
||||||
|
logger.warning(
|
||||||
|
f"{self.__class__.__name__} does not support chat_with_tools_stream. "
|
||||||
|
"This method should be overridden by the provider implementation."
|
||||||
|
)
|
||||||
|
yield (
|
||||||
|
"message",
|
||||||
|
{
|
||||||
|
"content": None,
|
||||||
|
"reasoning": None,
|
||||||
|
"tool_calls": None,
|
||||||
|
"finish_reason": "error",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_providers() -> None:
|
def load_providers() -> None:
|
||||||
plugins_dir = os.path.join(os.path.dirname(__file__), "plugins")
|
plugins_dir = os.path.join(os.path.dirname(__file__), "plugins")
|
||||||
|
|||||||
@ -369,11 +369,14 @@ class GeminiClient(GenAIClient):
|
|||||||
messages: list[dict[str, Any]],
|
messages: list[dict[str, Any]],
|
||||||
tools: Optional[list[dict[str, Any]]] = None,
|
tools: Optional[list[dict[str, Any]]] = None,
|
||||||
tool_choice: Optional[str] = "auto",
|
tool_choice: Optional[str] = "auto",
|
||||||
|
enable_thinking: Optional[bool] = None,
|
||||||
) -> AsyncGenerator[tuple[str, Any], None]:
|
) -> AsyncGenerator[tuple[str, Any], None]:
|
||||||
"""
|
"""
|
||||||
Stream chat with tools; yields content deltas then final message.
|
Stream chat with tools; yields content deltas then final message.
|
||||||
|
|
||||||
Implements streaming function calling/tool usage for Gemini models.
|
Implements streaming function calling/tool usage for Gemini models.
|
||||||
|
``enable_thinking`` is accepted for interface parity; Gemini configures
|
||||||
|
thinking at the model level, so it is ignored here.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Convert messages to Gemini format
|
# Convert messages to Gemini format
|
||||||
|
|||||||
@ -309,11 +309,15 @@ class OpenAIClient(GenAIClient):
|
|||||||
messages: list[dict[str, Any]],
|
messages: list[dict[str, Any]],
|
||||||
tools: Optional[list[dict[str, Any]]] = None,
|
tools: Optional[list[dict[str, Any]]] = None,
|
||||||
tool_choice: Optional[str] = "auto",
|
tool_choice: Optional[str] = "auto",
|
||||||
|
enable_thinking: Optional[bool] = None,
|
||||||
) -> AsyncGenerator[tuple[str, Any], None]:
|
) -> AsyncGenerator[tuple[str, Any], None]:
|
||||||
"""
|
"""
|
||||||
Stream chat with tools; yields content deltas then final message.
|
Stream chat with tools; yields content deltas then final message.
|
||||||
|
|
||||||
Implements streaming function calling/tool usage for OpenAI models.
|
Implements streaming function calling/tool usage for OpenAI models.
|
||||||
|
The OpenAI chat completions API does not expose a per-request thinking
|
||||||
|
toggle, so ``enable_thinking`` is accepted for interface parity and
|
||||||
|
ignored.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
openai_tool_choice = None
|
openai_tool_choice = None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user