Please review
Given a input text, outputs if the model classifies it as violating OpenAI's content policy. Related guide: Moderations
Comment From: tzolov
Hi @hemeda3 , thank you for your contribution.
The safety moderation is something we've been considering for a while but still have not tackled.
As Spring AI supports multiple LLMs providers and their APIs it important for as to come with a design that "generalise" and "unifies" (as much as possible) features such as the safety moderation
.
(btw, the code in the spring-ai-core/model package is meant to be generic for all models)
For example most LLM provides offer some sort of safety policies:
Google's Vertex Gemini and PaLM2 has this: - https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/configure-safety-attributes - https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/configure-safety-attributes - https://cloud.google.com/vertex-ai/docs/generative-ai/learn/responsible-ai
Microsoft Azure OpenAi: - https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/content-filter?tabs=warning%2Cpython
Amazon Bedrok Guardrails - https://aws.amazon.com/bedrock/guardrails/
OpenAI - https://platform.openai.com/docs/guides/moderation .....
@markpollack what do you think?
Comment From: hemeda3
@tzolov thanks for taking the time to check my PR. I followed OpenAiImageApi as good generic example , almost copy paste the structure file names etc..
https://docs.spring.io/spring-ai/reference/api/index.html#generic-model-api
but seems you're talking about new or different approach I guess something more generic than the one mentioned in this image, I guess it should be sharable across models which I believe will be new structure/design specifically diff from this structure https://docs.spring.io/spring-ai/reference/api/index.html#generic-model-api
if I understood your comment correctly then I think we can close this PR since it's too early
also I can also create new PR more generic way, assuming something different than OpenAiImageApi
Comment From: tzolov
@hemeda3, I'm truly impressed with your effort and understanding of our somewhat poorly documented concepts. What i'm saying is that we still have not clear understanding how we are going to extend the generic model (you've shown above) to model the safety moderations in way we can implement it of the various providers. We are just asking for bit more patience until we get there. Then I will have more time to review your PR and continue the work
Comment From: radhakrishna67
I can not wait to see this feature in the upcoming releases. Please prioritize it.
Comment From: markpollack
Hi. I understand the concern of putting classes in the generic model package before having a second impl, but I figure we can adjust as we go considering this is a very clean PR. Thanks @hemeda3 ! very much appreciated.
Added docs and merged into current naming conventions and use of new approach for retry/errorhandler since this PR was authored.
merged in 189468127c234ced9256f951023fc8fb29b08da2