8000 Undefined array key "content" (MS OpenAI Content Filtering issue) · Issue #198 · openai-php/client · GitHub
[go: up one dir, main page]

Skip to content
Undefined array key "content" (MS OpenAI Content Filtering issue) #198
Open
@chrisrickard

Description

@chrisrickard

When using using the Azure OpenAI API, if content filtering is kicked off an error is returned Undefined array key "content" as there is no content parameter in the array within CreateResponseMessage.php

    /**
     * @param  array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}}  $attributes
     */
    public static function from(array $attributes): self
    {
        return new self(
            $attributes['role'],
            $attributes['content'],
            isset($attributes['function_call']) ? CreateResponseFunctionCall::from($attributes['function_call']) : null,
        );
    }

The choices array looks something like this,

    "choices": [
        {
            "index": 0,
            "finish_reason": "content_filter",
            "message": {
                "role": "assistant"
            },
            "content_filter_results": {
                "hate": {
                    "filtered": false,
                    "severity": "safe"
                },
                "self_harm": {
                    "filtered": false,
                    "severity": "safe"
                },
                "sexual": {
                    "filtered": true,
                    "severity": "medium"
                },
                "violence": {
                    "filtered": false,
                    "severity": "safe"
                }
            }
        }
    ],

That example above has the "sexual" filter triggered, hence why there is no content back from the assistant.

It would be great if this lib handled the content filtering issues (e.g. threw an exception with a message etc)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0