-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log LLM tool call for streamed response (#545)
Co-authored-by: Alex Hall <[email protected]>
- Loading branch information
1 parent
ff7211b
commit 68fcf5a
Showing
6 changed files
with
403 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, Callable, NamedTuple | ||
from abc import ABC, abstractmethod | ||
from typing import Any, NamedTuple | ||
|
||
from typing_extensions import LiteralString | ||
|
||
|
||
class StreamState(ABC): | ||
"""Keeps track of the state of a streamed response.""" | ||
|
||
@abstractmethod | ||
def record_chunk(self, chunk: Any) -> None: | ||
"""Update the state based on a chunk from the streamed response.""" | ||
|
||
@abstractmethod | ||
def get_response_data(self) -> Any: | ||
"""Returns the response data for including in the log.""" | ||
|
||
|
||
class EndpointConfig(NamedTuple): | ||
"""The configuration for the endpoint of a provider based on request url.""" | ||
|
||
message_template: LiteralString | ||
span_data: dict[str, Any] | ||
content_from_stream: Callable[[Any], str | None] | None | ||
stream_state_cls: type[StreamState] | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.