Skip to content

Commit

Permalink
Merge branch 'wso2:master' into improvement-3084
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanhr authored Oct 3, 2024
2 parents 38509aa + 359640f commit b0f3d87
Show file tree
Hide file tree
Showing 329 changed files with 42,597 additions and 1,049 deletions.
6 changes: 5 additions & 1 deletion components/apimgt/org.wso2.carbon.apimgt.api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.30.19-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -21,6 +21,10 @@
<name>WSO2 Carbon - API Management API</name>

<dependencies>
<dependency>
<groupId>org.wso2.orbit.com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.wso2.carbon.apimgt.api.model.Application;
import org.wso2.carbon.apimgt.api.model.ApplicationInfo;
import org.wso2.carbon.apimgt.api.model.Environment;
import org.wso2.carbon.apimgt.api.model.LLMProvider;
import org.wso2.carbon.apimgt.api.model.Monetization;
import org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo;
import org.wso2.carbon.apimgt.api.model.Workflow;
Expand Down Expand Up @@ -540,4 +541,55 @@ List<KeyManagerConfigurationDTO> getGlobalKeyManagerConfigurations(String organi
* @throws APIManagementException
*/
void deleteGlobalKeyManagerConfigurationById(String id) throws APIManagementException;

/**
* Adds a new LLM Provider for the given organization.
*
* @param provider The LLM Provider to add.
* @return The added LLM Provider.
* @throws APIManagementException If adding fails.
*/
LLMProvider addLLMProvider(LLMProvider provider) throws APIManagementException;

/**
* Retrieves a list of LLM providers based on the given filters.
*
* @param organization the organization name to filter
* @param name the provider name to filter
* @param apiVersion the API version to filter
* @param builtInSupport whether to filter
* @return a list of LLM providers matching the specified filters
* @throws APIManagementException if an error occurs while retrieving the providers
*/
List<LLMProvider> getLLMProviders(String organization, String name, String apiVersion, Boolean builtInSupport) throws APIManagementException;

/**
* Deletes an LLM Provider by ID for the given organization.
*
* @param organization The organization name.
* @param llmProviderId The ID of the LLM Provider.
* @param builtIn Whether the provider is built-in.
* @return Deleted LLM Provider.
* @throws APIManagementException If deletion fails.
*/
LLMProvider deleteLLMProvider(String organization, String llmProviderId, boolean builtIn) throws APIManagementException;

/**
* Updates an LLM Provider for the given organization.
*
* @param provider The LLM Provider with updated data.
* @return Updated LLM Provider.
* @throws APIManagementException If update fails.
*/
LLMProvider updateLLMProvider(LLMProvider provider) throws APIManagementException;

/**
* Retrieves an LLM Provider by ID for the given organization.
*
* @param organization The organization name.
* @param llmProviderId The ID of the LLM Provider.
* @return The LLM Provider.
* @throws APIManagementException If retrieval fails.
*/
LLMProvider getLLMProvider(String organization, String llmProviderId) throws APIManagementException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.apimgt.api;

import java.io.File;

/**
* This class contains common constants for APIs.
*/
Expand All @@ -44,4 +46,48 @@ public class APIConstants {
public static final String ENDPOINT_SECURITY_PRODUCTION = "production";
public static final String ENDPOINT_SECURITY_SANDBOX = "sandbox";
public static final String ENDPOINT_CONFIG_SESSION_TIMEOUT = "sessionTimeOut";

public static class AIAPIConstants {
public static final String AI_API_REQUEST_METADATA = "AI_API_REQUEST_METADATA";
public static final String AI_API_RESPONSE_METADATA = "AI_API_RESPONSE_METADATA";
public static final String INPUT_SOURCE_PAYLOAD = "payload";
public static final String CONNECTOR_TYPE = "connectorType";
public static final String LLM_PROVIDER_ID = "id";
public static final String LLM_PROVIDER_NAME = "name";
public static final String LLM_PROVIDER_API_VERSION = "apiVersion";
public static final String LLM_PROVIDER_CONFIGURATIONS = "configurations";
public static final String LLM_CONFIGS_ENDPOINT = "/llm-providers";
public static final String CONFIGURATIONS = "configurations";
public static final String AI_API_DEFINITION_FILE_PATH = File.separator + "repository" + File.separator +
"resources" + File.separator + "api_definitions" + File.separator;
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_NAME = "AzureOpenAI";
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_VERSION = "1.0.0";
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_CONNECTOR = "azureOpenAi_1.0.0";
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_KEY = "api-key";
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_API_DEFINITION_FILE_NAME = "azure_api.yaml";
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_DESCRIPTION = "Azure OpenAI service";
public static final String LLM_PROVIDER_SERVICE_OPENAI_NAME = "OpenAI";
public static final String LLM_PROVIDER_SERVICE_OPENAI_VERSION = "1.0.0";
public static final String LLM_PROVIDER_SERVICE_OPENAI_CONNECTOR = "openAi_1.0.0";
public static final String LLM_PROVIDER_SERVICE_OPENAI_KEY = "Authorization";
public static final String LLM_PROVIDER_SERVICE_OPENAI_API_DEFINITION_FILE_NAME = "openai_api.yaml";
public static final String LLM_PROVIDER_SERVICE_OPENAI_DESCRIPTION = "New OpenAI service";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_NAME = "MistralAI";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_VERSION = "1.0.0";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_CONNECTOR = "mistralAi_1.0.0";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_KEY = "Authorization";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_API_DEFINITION_FILE_NAME = "mistral_api.yaml";
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_DESCRIPTION = "Mistral AI service";
public static final String LLM_PROVIDER_SERVICE_METADATA_MODEL = "model";
public static final String LLM_PROVIDER_SERVICE_METADATA_PROMPT_TOKEN_COUNT = "promptTokenCount";
public static final String LLM_PROVIDER_SERVICE_METADATA_COMPLETION_TOKEN_COUNT = "completionTokenCount";
public static final String LLM_PROVIDER_SERVICE_METADATA_TOTAL_TOKEN_COUNT = "totalTokenCount";
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_MODEL = "$.model";
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_PROMPT_TOKEN_COUNT = "$.usage" +
".prompt_tokens";
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_COMPLETION_TOKEN_COUNT = "$.usage" +
".completion_tokens";
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_TOTAL_TOKEN_COUNT = "$.usage.total_tokens";
public static final String LLM_PROVIDER_SERVICE_DEFAULT = "default";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -65,6 +66,31 @@ public interface APIProvider extends APIManager {
Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws
APIManagementException;

/**
* This method is to delete Sequence Backend by type
*
* @param apiUUID API Id
* @param type Key type
* @throws APIManagementException If failed to delete Sequence Backend
*/
void deleteCustomBackendByID(String apiUUID, String type) throws APIManagementException;

/**
* This method is to delete all Sequence Backends by APIID
*
* @param apiUUID API ID
* @throws APIManagementException If failed to delete Sequence Backend
*/
void deleteCustomBackendByAPIID(String apiUUID) throws APIManagementException;

/**
* This method is to delete Sequence Backends of a specific revision
* @param apiUUID API Id
* @param revisionId Revision Id
* @throws APIManagementException If failed to delete Sequence Backend
*/
void deleteSequenceBackendByRevision(String apiUUID, String revisionId) throws APIManagementException;

/**
* @param apiTypeWrapper Api type wrapper
* @param parentCommentID
Expand Down Expand Up @@ -315,6 +341,39 @@ List<SubscribedAPI> getSubscriptionsOfAPI(String apiName, String apiVersion, Str
*/
API updateAPI(API api, API existingAPI) throws APIManagementException, FaultGatewaysException;

/**
* This method is to update Sequence Backend
*
* @param api API
* @param type Key Type
* @param sequence Sequence Content
* @param seqName Sequence Name
* @param customBackendUUID Sequence Id
* @throws APIManagementException If not updated
*/
void updateCustomBackend(String api, String type, String sequence, String seqName, String customBackendUUID)
throws APIManagementException;

/**
* THis method is to retrieve Sequence Backend data
*
* @param apiUUID API Id
* @param type Key Type
* @return SequenceBackendData object
* @throws APIManagementException If data is not properly retrieved
*/
SequenceBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException;

/**
* This method is to retrieve all Sequence Backends of an API
*
* @param apiUUID API Id
* @return List of Sequence Backends
* @throws APIManagementException If not found
*/

List<SequenceBackendData> getAllSequenceBackendsByAPIUUID(String apiUUID) throws APIManagementException;

/**
* Create a new version of the <code>api</code>, with version <code>newVersion</code>
*
Expand Down Expand Up @@ -1701,6 +1760,15 @@ Map<String, Object> searchPaginatedAPIProducts(String searchQuery, String tenant
*/
String getSecuritySchemeOfAPI(String uuid, String organization) throws APIManagementException;

/**
* Returns whether subscription validation is disabled for an API
*
* @param uuid UUID of the API
* @return whether subscription validation is disabled
* @throws APIManagementException if failed get API from APIIdentifier
*/
boolean isSubscriptionValidationDisabled(String uuid) throws APIManagementException;

/**
* Returns details of an API
* @param uuid UUID of the API's registry artifact
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.apimgt.api;

import org.osgi.service.component.annotations.Component;
import org.wso2.carbon.apimgt.api.model.LLMProvider;

import java.util.ArrayList;
import java.util.List;

/**
* Azure OpenAI LLM Provider Service.
*/
@Component(
name = "azureOpenAi.llm.provider.service",
immediate = true,
service = LLMProviderService.class
)
public class AzureOpenAiLLMProviderService extends BuiltInLLMProviderService {

@Override
public String getType() {

return APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_CONNECTOR;
}

@Override
public LLMProvider registerLLMProvider(String organization, String apiDefinitionFilePath)
throws APIManagementException {

try {
LLMProvider llmProvider = new LLMProvider();
llmProvider.setName(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_NAME);
llmProvider.setApiVersion(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_VERSION);
llmProvider.setOrganization(organization);
llmProvider.setDescription(
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_DESCRIPTION);
llmProvider.setBuiltInSupport(true);
llmProvider.setApiDefinition(readApiDefinition(
apiDefinitionFilePath
+ APIConstants.AIAPIConstants
.LLM_PROVIDER_SERVICE_AZURE_OPENAI_API_DEFINITION_FILE_NAME));

LLMProviderConfiguration llmProviderConfiguration = new LLMProviderConfiguration();
llmProviderConfiguration.setAuthHeader(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_KEY);
llmProviderConfiguration.setAuthQueryParam(null);
llmProviderConfiguration.setConnectorType(this.getType());

List<LLMProviderMetadata> llmProviderMetadata = new ArrayList<>();
llmProviderMetadata.add(new LLMProviderMetadata(
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_MODEL,
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_MODEL));
llmProviderMetadata.add(new LLMProviderMetadata(
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_PROMPT_TOKEN_COUNT,
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_PROMPT_TOKEN_COUNT));
llmProviderMetadata.add(new LLMProviderMetadata(
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_COMPLETION_TOKEN_COUNT,
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
APIConstants.AIAPIConstants
.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_COMPLETION_TOKEN_COUNT));
llmProviderMetadata.add(new LLMProviderMetadata(
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_TOTAL_TOKEN_COUNT,
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_TOTAL_TOKEN_COUNT));
llmProviderConfiguration.setMetadata(llmProviderMetadata);

llmProvider.setConfigurations(llmProviderConfiguration.toJsonString());
return llmProvider;
} catch (Exception e) {
throw new APIManagementException("Error occurred when registering LLM Provider:" + this.getType());
}
}
}
Loading

0 comments on commit b0f3d87

Please sign in to comment.