@@ -3829,6 +3829,35 @@ func TestResponsesToPrompt_DropsEmptyMessages(t *testing.T) {
38293829 require .Contains (t , warnings [0 ].Message , "dropping empty assistant message" )
38303830 })
38313831
3832+ t .Run ("should drop assistant messages with only reasoning that cannot be sent" , func (t * testing.T ) {
3833+ t .Parallel ()
3834+
3835+ prompt := fantasy.Prompt {
3836+ {
3837+ Role : fantasy .MessageRoleUser ,
3838+ Content : []fantasy.MessagePart {
3839+ fantasy.TextPart {Text : "Hello" },
3840+ },
3841+ },
3842+ {
3843+ Role : fantasy .MessageRoleAssistant ,
3844+ Content : []fantasy.MessagePart {
3845+ fantasy.ReasoningPart {ProviderOptions : fantasy.ProviderOptions {
3846+ Name : & ResponsesReasoningMetadata {ItemID : "rs_1" },
3847+ }},
3848+ },
3849+ },
3850+ }
3851+
3852+ input , warnings , err := toResponsesPrompt (prompt , "system" )
3853+
3854+ require .NoError (t , err )
3855+
3856+ require .Len (t , input , 1 , "should only have user message" )
3857+ require .Len (t , warnings , 1 )
3858+ require .Contains (t , warnings [0 ].Message , "dropping empty assistant message" )
3859+ })
3860+
38323861 t .Run ("should keep assistant messages with text content" , func (t * testing.T ) {
38333862 t .Parallel ()
38343863
@@ -4764,7 +4793,11 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
47644793 fantasy.ReasoningPart {
47654794 Text : "thinking" ,
47664795 ProviderOptions : fantasy.ProviderOptions {
4767- Name : & ResponsesReasoningMetadata {Summary : []string {}},
4796+ Name : & ResponsesReasoningMetadata {
4797+ EncryptedContent : & encryptedContent ,
4798+ Summary : []string {},
4799+ Finalized : true ,
4800+ },
47684801 },
47694802 },
47704803 fantasy.TextPart {Text : "4" },
@@ -4783,8 +4816,7 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
47834816 require .NoError (t , err )
47844817 require .Empty (t , warnings )
47854818
4786- // Without an ItemID the reasoning cannot be sent. Order: user,
4787- // assistant text, user.
4819+ // user, assistant text, user.
47884820 require .Len (t , input , 3 )
47894821 for _ , item := range input {
47904822 require .Nil (t , item .OfReasoning )
@@ -4810,138 +4842,6 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
48104842 })
48114843}
48124844
4813- func TestResponsesToPrompt_ReasoningWithWebSearchCombined (t * testing.T ) {
4814- t .Parallel ()
4815-
4816- reasoningItemID := "rs_002"
4817- webSearchItemID := "ws_002"
4818-
4819- prompt := fantasy.Prompt {
4820- {
4821- Role : fantasy .MessageRoleUser ,
4822- Content : []fantasy.MessagePart {
4823- fantasy.TextPart {Text : "What is the weather in San Francisco?" },
4824- },
4825- },
4826- {
4827- Role : fantasy .MessageRoleAssistant ,
4828- Content : []fantasy.MessagePart {
4829- fantasy.ReasoningPart {
4830- Text : "I should look this up." ,
4831- ProviderOptions : fantasy.ProviderOptions {
4832- Name : & ResponsesReasoningMetadata {
4833- ItemID : reasoningItemID ,
4834- Summary : []string {},
4835- },
4836- },
4837- },
4838- fantasy.ToolCallPart {
4839- ToolCallID : webSearchItemID ,
4840- ToolName : "web_search" ,
4841- ProviderExecuted : true ,
4842- },
4843- fantasy.ToolResultPart {
4844- ToolCallID : webSearchItemID ,
4845- ProviderExecuted : true ,
4846- ProviderOptions : fantasy.ProviderOptions {
4847- Name : & WebSearchCallMetadata {
4848- ItemID : webSearchItemID ,
4849- Status : "completed" ,
4850- Action : & WebSearchAction {Type : "search" , Query : "weather in San Francisco" },
4851- },
4852- },
4853- },
4854- fantasy.TextPart {Text : "Sunny." },
4855- },
4856- },
4857- {
4858- Role : fantasy .MessageRoleUser ,
4859- Content : []fantasy.MessagePart {
4860- fantasy.TextPart {Text : "And Tokyo?" },
4861- },
4862- },
4863- }
4864-
4865- input , warnings , err := toResponsesPrompt (prompt , "system" )
4866-
4867- require .NoError (t , err )
4868- require .Empty (t , warnings )
4869-
4870- // Reasoning without encrypted content is skipped. Order: user,
4871- // web_search_call, assistant text, user.
4872- require .Len (t , input , 4 )
4873- require .NotNil (t , input [1 ].OfWebSearchCall )
4874- for _ , item := range input {
4875- require .Nil (t , item .OfItemReference )
4876- require .Nil (t , item .OfReasoning )
4877- }
4878- }
4879-
4880- func TestResponsesToPrompt_ReasoningWithFunctionCallCombined (t * testing.T ) {
4881- t .Parallel ()
4882-
4883- reasoningItemID := "rs_003"
4884- functionCallID := "call_003"
4885-
4886- prompt := fantasy.Prompt {
4887- {
4888- Role : fantasy .MessageRoleUser ,
4889- Content : []fantasy.MessagePart {
4890- fantasy.TextPart {Text : "compute 1+1" },
4891- },
4892- },
4893- {
4894- Role : fantasy .MessageRoleAssistant ,
4895- Content : []fantasy.MessagePart {
4896- fantasy.ReasoningPart {
4897- Text : "I'll call add." ,
4898- ProviderOptions : fantasy.ProviderOptions {
4899- Name : & ResponsesReasoningMetadata {
4900- ItemID : reasoningItemID ,
4901- Summary : []string {},
4902- },
4903- },
4904- },
4905- fantasy.ToolCallPart {
4906- ToolCallID : functionCallID ,
4907- ToolName : "add" ,
4908- Input : `{"a":1,"b":1}` ,
4909- },
4910- },
4911- },
4912- {
4913- Role : fantasy .MessageRoleTool ,
4914- Content : []fantasy.MessagePart {
4915- fantasy.ToolResultPart {
4916- ToolCallID : functionCallID ,
4917- Output : fantasy.ToolResultOutputContentText {Text : "2" },
4918- },
4919- },
4920- },
4921- {
4922- Role : fantasy .MessageRoleUser ,
4923- Content : []fantasy.MessagePart {
4924- fantasy.TextPart {Text : "thanks" },
4925- },
4926- },
4927- }
4928-
4929- input , warnings , err := toResponsesPrompt (prompt , "system" )
4930-
4931- require .NoError (t , err )
4932- require .Empty (t , warnings )
4933-
4934- // Reasoning without encrypted content is skipped. Order: user,
4935- // function_call(call_003), function_call_output(call_003), user.
4936- require .Len (t , input , 4 )
4937-
4938- require .NotNil (t , input [1 ].OfFunctionCall )
4939- require .Equal (t , functionCallID , input [1 ].OfFunctionCall .CallID )
4940-
4941- require .NotNil (t , input [2 ].OfFunctionCallOutput )
4942- require .Equal (t , functionCallID , input [2 ].OfFunctionCallOutput .CallID )
4943- }
4944-
49454845func TestResponsesStream_RequiresTerminalEventBeforeFinish (t * testing.T ) {
49464846 t .Parallel ()
49474847
0 commit comments