-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip callable types when creating pipeline ; recursively serialize co…
…mponent output to avoid pydantic serialization errors (eg on OpenAI responses)
- Loading branch information
1 parent
8ebd76c
commit d1adc2b
Showing
4 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from hayhooks.server.pipelines.models import convert_component_output | ||
from openai.types.completion_usage import CompletionTokensDetails, PromptTokensDetails | ||
|
||
|
||
def test_convert_component_output_with_nested_models(): | ||
sample_response = [ | ||
{ | ||
'model': 'gpt-4o-mini-2024-07-18', | ||
'index': 0, | ||
'finish_reason': 'stop', | ||
'usage': { | ||
'completion_tokens': 52, | ||
'prompt_tokens': 29, | ||
'total_tokens': 81, | ||
'completion_tokens_details': CompletionTokensDetails( | ||
accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0 | ||
), | ||
'prompt_tokens_details': PromptTokensDetails(audio_tokens=0, cached_tokens=0), | ||
}, | ||
} | ||
] | ||
|
||
converted_output = convert_component_output(sample_response) | ||
|
||
assert converted_output == [ | ||
{ | ||
'model': 'gpt-4o-mini-2024-07-18', | ||
'index': 0, | ||
'finish_reason': 'stop', | ||
'usage': { | ||
'completion_tokens': 52, | ||
'prompt_tokens': 29, | ||
'total_tokens': 81, | ||
'completion_tokens_details': { | ||
'accepted_prediction_tokens': 0, | ||
'audio_tokens': 0, | ||
'reasoning_tokens': 0, | ||
'rejected_prediction_tokens': 0, | ||
}, | ||
'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}, | ||
}, | ||
} | ||
] |
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