Model response converter
Classes:
Name | Description |
---|---|
ModelResponseConverter |
Wrap an LLM SDK call and normalize its output via a converter. |
Classes¶
ModelResponseConverter
¶
Wrap an LLM SDK call and normalize its output via a converter.
Supports sync/async invocation and streaming. Use invoke()
for
non-streaming calls and stream()
for streaming calls.
Methods:
Name | Description |
---|---|
__init__ |
Initialize ModelResponseConverter. |
invoke |
Call the underlying function and convert a non-streaming response to Message. |
stream |
Call the underlying function and yield normalized streaming events and final Message. |
Attributes:
Name | Type | Description |
---|---|---|
converter |
|
|
response |
|
Source code in pyagenity/adapters/llm/model_response_converter.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
Attributes¶
Functions¶
__init__
¶
__init__(response, converter)
Initialize ModelResponseConverter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any | Callable[..., Any]
|
The LLM response or a callable returning a response. |
required |
|
BaseConverter | str
|
Converter instance or string identifier (e.g., "litellm"). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the converter is not supported. |
Source code in pyagenity/adapters/llm/model_response_converter.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
invoke
async
¶
invoke()
Call the underlying function and convert a non-streaming response to Message.
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The normalized message from the LLM response. |
Raises:
Type | Description |
---|---|
Exception
|
If the underlying function or converter fails. |
Source code in pyagenity/adapters/llm/model_response_converter.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
stream
async
¶
stream(config, node_name, meta=None)
Call the underlying function and yield normalized streaming events and final Message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict
|
Node configuration parameters for streaming. |
required |
|
str
|
Name of the node processing the response. |
required |
|
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
Name | Type | Description |
---|---|---|
Message |
AsyncGenerator[Message]
|
Normalized streaming message events from the LLM response. |
Raises:
Type | Description |
---|---|
ValueError
|
If config is not provided. |
Exception
|
If the underlying function or converter fails. |
Source code in pyagenity/adapters/llm/model_response_converter.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|