aallam / openai-kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.
MIT License
1.5k stars 180 forks source link

Feature Request: Add Support for Content Filter Response Deserialization OR Expose Raw Response in OpenAI Kotlin Client #294

Open gh-abhay opened 10 months ago

gh-abhay commented 10 months ago

Feature Description

The current OpenAI Kotlin client lacks the ability to deserialize the Content Filter response returned by the Azure OpenAI API (Content Filter Documentation). Additionally, the client does not expose the HTTP headers, body of the response, or a way to disable deserialization of the response. This makes it impossible to use the client to call the Azure OpenAI API when we want to use the Content Filter feature.

Problem it Solves

This feature request aims to address the inability to use the Content Filter feature of the Azure OpenAI API with the current OpenAI Kotlin client. Currently, there is no workaround for this issue, which limits the functionality and usability of the client. Developers are unable to filter content as per their requirements, which can be a crucial feature for many applications.

Proposed Solution

There are two potential solutions to this problem:

  1. Add a content filter parameter as optional in the current Chat Completions and Completions response. For example:
@Serializable
public data class ChatCompletion(

    // all existing properties
    // ...

    /**
     * Content filtering results for zero or more prompts in the request. In a streaming request,
     * results for different prompts may arrive at different times or in different orders.
     */
    @SerialName("prompt_filter_results")
    val promptFilterResults: List<ContentFilterResultsForPrompt>? = null
)
  1. Expose the ability to get raw response from the client, so that we can deserialize the response ourselves. This would provide more flexibility and control over the response handling, and allow developers to handle the response as per their specific requirements.

Additional Context

The Azure OpenAI API provides a Content Filter feature that is currently unusable with the OpenAI Kotlin client due to the issues described above. Implementing either of the proposed solutions would greatly enhance the functionality and usability of the client, and allow developers to fully leverage the capabilities of the Azure OpenAI API. This would be a significant improvement for developers who need to use content filtering in their applications.