Uploaded image for project: 'OpenAI Integrations '
  1. OpenAI Integrations
  2. OPENAIINT-14

Add documentation for Azure openai services

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Neutral
    • 1.0.7
    • None
    • None

    Description

      We could/should add a way to the documentation how to use our Openai module with Azure Openai services. Maybe we could even add the special filter for Azure to our code base and just mention how to change the endpoint config.

      Decoration:

      baseUrl: https://magnolia-azure-openai.openai.azure.com/openai/deployments/magnolia-azure-openai
      components:
        authorization:
          class: info.magnolia.ai.automations.rest.RestAzureClientAuthorizationFilter
      restCalls:
        completions:
          queryParameters:
            api-version: 2023-07-01-preview
        chatCompletions:
          queryParameters:
            api-version: 2023-07-01-preview 

      Custom filter to set authorization token:

      /**
       * This file Copyright (c) 2023 Magnolia International
       * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
       *
       *
       * This program and the accompanying materials are made
       * available under the terms of the Magnolia Network Agreement
       * which accompanies this distribution, and is available at
       * http://www.magnolia-cms.com/mna.html
       *
       * Any modifications to this file must keep this entire header
       * intact.
       *
       */
      package info.magnolia.services.rest;
      ​
      import info.magnolia.ai.automations.OpenAIAutomationsModule;
      import info.magnolia.ai.automations.OpenAICredentialsProvider;
      import lombok.extern.slf4j.Slf4j;
      import org.apache.commons.lang3.StringUtils;
      ​
      import javax.inject.Inject;
      import javax.ws.rs.client.ClientRequestContext;
      import javax.ws.rs.client.ClientRequestFilter;
      import java.io.IOException;
      ​
      /**
       * The filter adds the api-key header to the requests
       */
      @Slf4j
      public class RestAzureClientAuthorizationFilter implements ClientRequestFilter {
      ​
          private final OpenAIAutomationsModule openAIAutomationsModule;
          private final OpenAICredentialsProvider openAICredentialsProvider;
          private final String API_KEY = "api-key";
      ​
          @Inject
          public RestAzureClientAuthorizationFilter(OpenAIAutomationsModule openAIAutomationsModule, OpenAICredentialsProvider openAICredentialsProvider) {
              this.openAIAutomationsModule = openAIAutomationsModule;
              this.openAICredentialsProvider = openAICredentialsProvider;
          }
      ​
          @Override
          public void filter(ClientRequestContext requestContext) throws IOException {
              requestContext.getHeaders().add(API_KEY, getAzureApiKey());
          }
      ​
          public String getAzureApiKey() {
              String bearerToken = openAICredentialsProvider.getAuthorization(openAIAutomationsModule.getApiKey());
              if (bearerToken != null && bearerToken.startsWith("Bearer")) {
                  bearerToken = StringUtils.replace(bearerToken, "Bearer ", "");
              }
      ​
              return bearerToken;
          }
      ​
      }

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              Unassigned Unassigned
              tobias.kerschbaum Tobias Kerschbaum
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: