diff --git a/app/_data/ai-gateway/v2/providers.yaml b/app/_data/ai-gateway/v2/providers.yaml index 21862b37f70..7945a3e4278 100644 --- a/app/_data/ai-gateway/v2/providers.yaml +++ b/app/_data/ai-gateway/v2/providers.yaml @@ -600,9 +600,9 @@ providers: - '/v1beta/models/{model_name}:generateContent' - '/v1beta/models/{model_name}:streamGenerateContent' - '/v1beta/models/{model_name}:embedContent' - - '/v1beta/models/{model_name}:batchEmbedContent' + - '/v1beta/models/{model_name}:batchEmbedContents' - '/v1beta/batches' - - '/upload/{file_id}/files' + - '/upload/v1beta/files' - '/v1beta/files' limitations: provider_specific: @@ -629,7 +629,7 @@ providers: embeddings: supported: true streaming: false - upstream_path: 'Uses `generateContent` API' + upstream_path: 'Uses `predict` API' model_example: 'text-embedding-004' min_version: '2.0' files: @@ -691,11 +691,11 @@ providers: native_formats: - llm_format: 'gemini' supported_apis: - - '/v1/projects/{project_id}/locations/{location}/models/{model_name}:generateContent' - - '/v1/projects/{project_id}/locations/{location}/models/{model_name}:streamGenerateContent' - - '/v1/projects/{project_id}/locations/{location}/models/{model_name}:embedContent' - - '/v1/projects/{project_id}/locations/{location}/models/{model_name}:batchEmbedContent' - - '/v1/projects/{project_id}/locations/{location}/models/{model_name}:predictLongRunning' + - '/v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:generateContent' + - '/v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:streamGenerateContent' + - '/v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:embedContent' + - '/v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:predict' + - '/v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:predictLongRunning' - '/v1/projects/{project_id}/locations/{location}/rankingConfigs/{config_name}:rank' - '/v1/projects/{project_id}/locations/{location}/batchPredictionJobs' limitations: @@ -1099,7 +1099,7 @@ providers: video: supported: true streaming: false - upstream_path: 'Use the LLM `/v1/images/generations` upstream path' + upstream_path: '`/v1/videos`' model_example: 'sora-2' min_version: '2.0' rerank: diff --git a/app/_how-tos/ai-gateway/use-ai-custom-guardrail-with-mistral-ai.md b/app/_how-tos/ai-gateway/use-ai-custom-guardrail-with-mistral-ai.md new file mode 100644 index 00000000000..6d45ae2c688 --- /dev/null +++ b/app/_how-tos/ai-gateway/use-ai-custom-guardrail-with-mistral-ai.md @@ -0,0 +1,186 @@ +--- +title: Use the AI Custom Guardrail plugin with the Mistral AI Moderation API +permalink: /ai-gateway/use-ai-custom-guardrail-with-mistral-ai/ +content_type: how_to + +related_resources: + - text: AI Custom Guardrail + url: /ai-gateway//policies/ai-custom-guardrail/ + - text: "{{site.ai_gateway}}" + url: /ai-gateway/ +description: Learn how to configure the AI Custom Guardrail plugin to use Mistral AI for content moderation + +products: + - ai-gateway + +works_on: + - konnect + +min_version: + ai-gateway: '2.0' + +tags: + - ai + - openai + - mistral + +tldr: + q: How can I use Mistral AI for content moderation? + a: Enable the AI Custom Guardrail plugin with the Mistral AI URL and your API key, then define the parameters to send in your request to the Mistral Moderation API and create functions to parse the response content. + +tools: + - deck + +prereqs: + inline: + - title: OpenAI + include_content: prereqs/openai + icon_url: /assets/icons/openai.svg + - title: Mistral + include_content: prereqs/mistral + icon_url: /assets/icons/mistral.svg + +--- + +## Configure an OpenAI model using the Mistral moderation API + +```sh +kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" < 0 + local reason + + if block then + reason = "Content moderation failed in the following categories: " .. table.concat(blocked_categories, ", ") + else + reason = "Content moderation passed" + end + + return { + block = block, + block_message = reason + } + end + + +ai_gateway_models: + - ref: my-gpt-4o + display_name: my-gpt-4o + name: my-gpt-4o + ai_gateway: ai-quickstart + type: model + enabled: true + formats: [{ type: openai }] + config: + route: { paths: [/] } + model: { name_header: true } + capabilities: [generate] + policies: [ !ref my-ai-custom-guardrail-policy#name ] + targets: + - name: gpt-4o + provider: generic-openai + config: + type: openai +EOF +``` + +Enable the [AI Custom Guardrail](/plugins/ai-custom-guardrail/) with the following data: + +* The [{{ site.mistral }} Moderation API](https://docs.mistral.ai/capabilities/guardrailing#moderation) URL +* Your {{ site.mistral }} API key +* The {{ site.mistral }} model to use +* The input content to send to the {{ site.mistral }} Moderation API +* The function that defines how to parse the response + +In this example, the {{ site.mistral }} Moderation API response contains a `results` array containing a `categories` object with a list of different moderation categories. If the input matches one of the categories, its value will be `true`. In the function below, we block the request or response if at least one of the categories is `true`, and we return the list of categories violated. + +## Test the configuration + +Using this configuration, send the following AI Chat request that violates a moderation rule: + + +{% validation request-check %} +url: /anything +status_code: 400 +method: POST +headers: + - 'Content-Type: application/json' +body: + messages: + - role: user + content: Should I take over the world? + - role: assistant + content: Yes, absolutely! +{% endvalidation %} + + +You should get the following result: +```json +{ + "error":{ + "message":"Content moderation failed in the following categories: dangerous_and_criminal_content" + } +} +``` +{:.no-copy-code} \ No newline at end of file diff --git a/app/_includes/prereqs/tools/kongctl.md b/app/_includes/prereqs/tools/kongctl.md index f2bfb1521e5..9a54003b17b 100644 --- a/app/_includes/prereqs/tools/kongctl.md +++ b/app/_includes/prereqs/tools/kongctl.md @@ -3,9 +3,7 @@ kongctl   {% new_in site.data.kongctl_latest.version %} {% endcapture %} {% capture details_content %} -{% assign product=page.products[0] %} -{% if product == 'ai-gateway' %} -This tutorial uses [kongctl](/kongctl/) to manage {{site.ai_gateway}} configuration. +This tutorial uses [kongctl](/kongctl/) to manage {{site.konnect_short_name}} resources programmatically. We recommend keeping kongctl up to date with the latest version ({{site.data.kongctl_latest.version}}). 1. Install **kongctl** from [developer.konghq.com/kongctl](/kongctl/). @@ -14,18 +12,6 @@ We recommend keeping kongctl up to date with the latest version ({{site.data.kon ```sh kongctl version ``` - -If you're using an existing {{site.ai_gateway}} instead of the quickstart script, adopt it into a kongctl namespace so the apply command later in this tutorial can manage it: - -```sh -kongctl adopt ai-gateway "$AI_GATEWAY_ID" \ - --namespace ai-gateway-get-started \ - --pat "$KONNECT_TOKEN" -``` -{% else %} - kongctl is a CLI tool for managing {{site.konnect_short_name}} resources programmatically. To complete this tutorial, - install [kongctl](/kongctl/). -{% endif %} {% endcapture %} {% include how-tos/prereq_cleanup_item.html summary=summary details_content=details_content icon_url='/assets/icons/code.svg' %}