fix: Responses API previous_response input items

This adds storing of input items with previous responses and then
restores those input items to prepend to the user's messages list when
using conversation state.

I missed this in the initial implementation, but it makes sense that we
have to store the input items from previous responses so that we can
reconstruct the proper messages stack for multi-turn conversations -
just the output from previous responses isn't enough context for the
models to follow the turns and the original instructions.

Signed-off-by: Ben Browning <bbrownin@redhat.com>
This commit is contained in:
Ben Browning 2025-04-30 12:25:38 -04:00
parent 272d3359ee
commit 467fb19345
2 changed files with 106 additions and 29 deletions

View file

@ -131,3 +131,20 @@ OpenAIResponseInputTool = Annotated[
Field(discriminator="type"),
]
register_schema(OpenAIResponseInputTool, name="OpenAIResponseInputTool")
@json_schema_type
class OpenAIResponseInputItemMessage(OpenAIResponseInputMessage):
id: str
@json_schema_type
class OpenAIResponseInputItemList(BaseModel):
data: list[OpenAIResponseInputItemMessage]
object: Literal["list"] = "list"
@json_schema_type
class OpenAIResponsePreviousResponseWithInputItems(BaseModel):
input_items: OpenAIResponseInputItemList
response: OpenAIResponseObject