MaartenGr / MaartenGr/BERTopic
Handle Responsible AI scenarios for OpenAI
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
# High Level Proposal
I would like to extend `representation.OpenAI` to handle more scenarios that crop up when using OpenAI hosted by Azure. These scenarios affect usage of the [AzureOpenAI](https://github.com/openai/openai-python/blob/89478ce06e2161fda416c685b774a97a041ae185/src/openai/lib/azure.py#L64) class. Azure places its OpenAI instance behind Responsible AI (RAI) controls which reduce harm by limiting access to sensitive (violence, hate, self-harm, sexual) content but requires more edge-cases and errors to be accounted for.
I believe that handling more RAI based scenarios for OpenAI will improve the usability of modeling using that representation model for both folks who use AzureOpenAI and OpenAI.
## Technical Details
RAI triggers can be encountered in two scenarios:
1. Sending inappropriate input
2. GPT generating sensitive output based on the prompt
### Sending inappropriate input
- Log `repr_doc_ids` within [_extract_representative_docs](https://github.com/MaartenGr/BERTopic/blob/9e5558bc2d04797280b10576added63730459621/bertopic/_bertopic.py#L3813) which cause an exception to be raised
### GPT generating sensitive output based on the prompt
- Handle all four [`CompletionChoice.finish_reason`s](https://platform.openai.com/docs/guides/text-generation/chat-completions-api)
- Open question: How do you want to handle the `length` and `function_call` and `null` finish_reasons
- Log non-`stop` finish_reasons
- Log `repr_doc_ids` which caused sensitive responses
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in bertopic/_bertopic.py at _extract_representative_docs and review how representation.OpenAI uses AzureOpenAI. Reproduce the two RAI scenarios described in the issue, then determine how the four CompletionChoice.finish_reason values should be handled. Done means logging repr_doc_ids for triggering inputs and sensitive responses, plus non-stop finish reasons, with the open handling questions resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100