async-openai icon indicating copy to clipboard operation
async-openai copied to clipboard

fix<(responses)>: `parsing Error if multiple instructions are given`

Open p4r4d0xb0x opened this issue 5 months ago • 0 comments

While Using Responses api, I found that instructions Fields can be Listed response.

Expected:

{
  ...
  "instructions": "Structure My Json"
}

Response:

{
  "instructions": [
    {
      "type": "message",
      "content": [
        {
          "type": "input_text",
          "text": "You are ~~~~ ( hide ) ~~~ ract paragraphs, body text, bibliographic references, and image/table references,\n ~~~"
        }
      ],
      "role": "system"
    },
    {
      "type": "message",
      "content": [
        {
          "type": "input_text",
          "text": "structure my uploaded file"
        }
      ],
      "role": "user"
    }
  ]
}

So I Added Untagged enum

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum ResponseInstructions {
  /// The instructions that were inserted as the first item in context.
  Single(String),

  Multiple(Vec<InputMessage>)
}

p4r4d0xb0x avatar Jul 01 '25 07:07 p4r4d0xb0x