Skip to content

Commit b0f3d87

Browse files
authored
Merge branch 'wso2:master' into improvement-3084
2 parents 38509aa + 359640f commit b0f3d87

File tree

329 files changed

+42597
-1049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+42597
-1049
lines changed

components/apimgt/org.wso2.carbon.apimgt.api/pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>org.wso2.carbon.apimgt</groupId>
1313
<artifactId>apimgt</artifactId>
14-
<version>9.29.200-SNAPSHOT</version>
14+
<version>9.30.19-SNAPSHOT</version>
1515
<relativePath>../pom.xml</relativePath>
1616
</parent>
1717

@@ -21,6 +21,10 @@
2121
<name>WSO2 Carbon - API Management API</name>
2222

2323
<dependencies>
24+
<dependency>
25+
<groupId>org.wso2.orbit.com.jayway.jsonpath</groupId>
26+
<artifactId>json-path</artifactId>
27+
</dependency>
2428
<dependency>
2529
<groupId>com.googlecode.json-simple</groupId>
2630
<artifactId>json-simple</artifactId>

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java

+52
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.wso2.carbon.apimgt.api.model.Application;
2424
import org.wso2.carbon.apimgt.api.model.ApplicationInfo;
2525
import org.wso2.carbon.apimgt.api.model.Environment;
26+
import org.wso2.carbon.apimgt.api.model.LLMProvider;
2627
import org.wso2.carbon.apimgt.api.model.Monetization;
2728
import org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo;
2829
import org.wso2.carbon.apimgt.api.model.Workflow;
@@ -540,4 +541,55 @@ List<KeyManagerConfigurationDTO> getGlobalKeyManagerConfigurations(String organi
540541
* @throws APIManagementException
541542
*/
542543
void deleteGlobalKeyManagerConfigurationById(String id) throws APIManagementException;
544+
545+
/**
546+
* Adds a new LLM Provider for the given organization.
547+
*
548+
* @param provider The LLM Provider to add.
549+
* @return The added LLM Provider.
550+
* @throws APIManagementException If adding fails.
551+
*/
552+
LLMProvider addLLMProvider(LLMProvider provider) throws APIManagementException;
553+
554+
/**
555+
* Retrieves a list of LLM providers based on the given filters.
556+
*
557+
* @param organization the organization name to filter
558+
* @param name the provider name to filter
559+
* @param apiVersion the API version to filter
560+
* @param builtInSupport whether to filter
561+
* @return a list of LLM providers matching the specified filters
562+
* @throws APIManagementException if an error occurs while retrieving the providers
563+
*/
564+
List<LLMProvider> getLLMProviders(String organization, String name, String apiVersion, Boolean builtInSupport) throws APIManagementException;
565+
566+
/**
567+
* Deletes an LLM Provider by ID for the given organization.
568+
*
569+
* @param organization The organization name.
570+
* @param llmProviderId The ID of the LLM Provider.
571+
* @param builtIn Whether the provider is built-in.
572+
* @return Deleted LLM Provider.
573+
* @throws APIManagementException If deletion fails.
574+
*/
575+
LLMProvider deleteLLMProvider(String organization, String llmProviderId, boolean builtIn) throws APIManagementException;
576+
577+
/**
578+
* Updates an LLM Provider for the given organization.
579+
*
580+
* @param provider The LLM Provider with updated data.
581+
* @return Updated LLM Provider.
582+
* @throws APIManagementException If update fails.
583+
*/
584+
LLMProvider updateLLMProvider(LLMProvider provider) throws APIManagementException;
585+
586+
/**
587+
* Retrieves an LLM Provider by ID for the given organization.
588+
*
589+
* @param organization The organization name.
590+
* @param llmProviderId The ID of the LLM Provider.
591+
* @return The LLM Provider.
592+
* @throws APIManagementException If retrieval fails.
593+
*/
594+
LLMProvider getLLMProvider(String organization, String llmProviderId) throws APIManagementException;
543595
}

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConstants.java

+46
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.wso2.carbon.apimgt.api;
2020

21+
import java.io.File;
22+
2123
/**
2224
* This class contains common constants for APIs.
2325
*/
@@ -44,4 +46,48 @@ public class APIConstants {
4446
public static final String ENDPOINT_SECURITY_PRODUCTION = "production";
4547
public static final String ENDPOINT_SECURITY_SANDBOX = "sandbox";
4648
public static final String ENDPOINT_CONFIG_SESSION_TIMEOUT = "sessionTimeOut";
49+
50+
public static class AIAPIConstants {
51+
public static final String AI_API_REQUEST_METADATA = "AI_API_REQUEST_METADATA";
52+
public static final String AI_API_RESPONSE_METADATA = "AI_API_RESPONSE_METADATA";
53+
public static final String INPUT_SOURCE_PAYLOAD = "payload";
54+
public static final String CONNECTOR_TYPE = "connectorType";
55+
public static final String LLM_PROVIDER_ID = "id";
56+
public static final String LLM_PROVIDER_NAME = "name";
57+
public static final String LLM_PROVIDER_API_VERSION = "apiVersion";
58+
public static final String LLM_PROVIDER_CONFIGURATIONS = "configurations";
59+
public static final String LLM_CONFIGS_ENDPOINT = "/llm-providers";
60+
public static final String CONFIGURATIONS = "configurations";
61+
public static final String AI_API_DEFINITION_FILE_PATH = File.separator + "repository" + File.separator +
62+
"resources" + File.separator + "api_definitions" + File.separator;
63+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_NAME = "AzureOpenAI";
64+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_VERSION = "1.0.0";
65+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_CONNECTOR = "azureOpenAi_1.0.0";
66+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_KEY = "api-key";
67+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_API_DEFINITION_FILE_NAME = "azure_api.yaml";
68+
public static final String LLM_PROVIDER_SERVICE_AZURE_OPENAI_DESCRIPTION = "Azure OpenAI service";
69+
public static final String LLM_PROVIDER_SERVICE_OPENAI_NAME = "OpenAI";
70+
public static final String LLM_PROVIDER_SERVICE_OPENAI_VERSION = "1.0.0";
71+
public static final String LLM_PROVIDER_SERVICE_OPENAI_CONNECTOR = "openAi_1.0.0";
72+
public static final String LLM_PROVIDER_SERVICE_OPENAI_KEY = "Authorization";
73+
public static final String LLM_PROVIDER_SERVICE_OPENAI_API_DEFINITION_FILE_NAME = "openai_api.yaml";
74+
public static final String LLM_PROVIDER_SERVICE_OPENAI_DESCRIPTION = "New OpenAI service";
75+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_NAME = "MistralAI";
76+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_VERSION = "1.0.0";
77+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_CONNECTOR = "mistralAi_1.0.0";
78+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_KEY = "Authorization";
79+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_API_DEFINITION_FILE_NAME = "mistral_api.yaml";
80+
public static final String LLM_PROVIDER_SERVICE_MISTRALAI_DESCRIPTION = "Mistral AI service";
81+
public static final String LLM_PROVIDER_SERVICE_METADATA_MODEL = "model";
82+
public static final String LLM_PROVIDER_SERVICE_METADATA_PROMPT_TOKEN_COUNT = "promptTokenCount";
83+
public static final String LLM_PROVIDER_SERVICE_METADATA_COMPLETION_TOKEN_COUNT = "completionTokenCount";
84+
public static final String LLM_PROVIDER_SERVICE_METADATA_TOTAL_TOKEN_COUNT = "totalTokenCount";
85+
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_MODEL = "$.model";
86+
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_PROMPT_TOKEN_COUNT = "$.usage" +
87+
".prompt_tokens";
88+
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_COMPLETION_TOKEN_COUNT = "$.usage" +
89+
".completion_tokens";
90+
public static final String LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_TOTAL_TOKEN_COUNT = "$.usage.total_tokens";
91+
public static final String LLM_PROVIDER_SERVICE_DEFAULT = "default";
92+
}
4793
}

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java

+68
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy;
3434

3535
import java.io.ByteArrayInputStream;
36+
import java.io.InputStream;
3637
import java.util.List;
3738
import java.util.Map;
3839
import java.util.Set;
@@ -65,6 +66,31 @@ public interface APIProvider extends APIManager {
6566
Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws
6667
APIManagementException;
6768

69+
/**
70+
* This method is to delete Sequence Backend by type
71+
*
72+
* @param apiUUID API Id
73+
* @param type Key type
74+
* @throws APIManagementException If failed to delete Sequence Backend
75+
*/
76+
void deleteCustomBackendByID(String apiUUID, String type) throws APIManagementException;
77+
78+
/**
79+
* This method is to delete all Sequence Backends by APIID
80+
*
81+
* @param apiUUID API ID
82+
* @throws APIManagementException If failed to delete Sequence Backend
83+
*/
84+
void deleteCustomBackendByAPIID(String apiUUID) throws APIManagementException;
85+
86+
/**
87+
* This method is to delete Sequence Backends of a specific revision
88+
* @param apiUUID API Id
89+
* @param revisionId Revision Id
90+
* @throws APIManagementException If failed to delete Sequence Backend
91+
*/
92+
void deleteSequenceBackendByRevision(String apiUUID, String revisionId) throws APIManagementException;
93+
6894
/**
6995
* @param apiTypeWrapper Api type wrapper
7096
* @param parentCommentID
@@ -315,6 +341,39 @@ List<SubscribedAPI> getSubscriptionsOfAPI(String apiName, String apiVersion, Str
315341
*/
316342
API updateAPI(API api, API existingAPI) throws APIManagementException, FaultGatewaysException;
317343

344+
/**
345+
* This method is to update Sequence Backend
346+
*
347+
* @param api API
348+
* @param type Key Type
349+
* @param sequence Sequence Content
350+
* @param seqName Sequence Name
351+
* @param customBackendUUID Sequence Id
352+
* @throws APIManagementException If not updated
353+
*/
354+
void updateCustomBackend(String api, String type, String sequence, String seqName, String customBackendUUID)
355+
throws APIManagementException;
356+
357+
/**
358+
* THis method is to retrieve Sequence Backend data
359+
*
360+
* @param apiUUID API Id
361+
* @param type Key Type
362+
* @return SequenceBackendData object
363+
* @throws APIManagementException If data is not properly retrieved
364+
*/
365+
SequenceBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException;
366+
367+
/**
368+
* This method is to retrieve all Sequence Backends of an API
369+
*
370+
* @param apiUUID API Id
371+
* @return List of Sequence Backends
372+
* @throws APIManagementException If not found
373+
*/
374+
375+
List<SequenceBackendData> getAllSequenceBackendsByAPIUUID(String apiUUID) throws APIManagementException;
376+
318377
/**
319378
* Create a new version of the <code>api</code>, with version <code>newVersion</code>
320379
*
@@ -1701,6 +1760,15 @@ Map<String, Object> searchPaginatedAPIProducts(String searchQuery, String tenant
17011760
*/
17021761
String getSecuritySchemeOfAPI(String uuid, String organization) throws APIManagementException;
17031762

1763+
/**
1764+
* Returns whether subscription validation is disabled for an API
1765+
*
1766+
* @param uuid UUID of the API
1767+
* @return whether subscription validation is disabled
1768+
* @throws APIManagementException if failed get API from APIIdentifier
1769+
*/
1770+
boolean isSubscriptionValidationDisabled(String uuid) throws APIManagementException;
1771+
17041772
/**
17051773
* Returns details of an API
17061774
* @param uuid UUID of the API's registry artifact
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.apimgt.api;
20+
21+
import org.osgi.service.component.annotations.Component;
22+
import org.wso2.carbon.apimgt.api.model.LLMProvider;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
/**
28+
* Azure OpenAI LLM Provider Service.
29+
*/
30+
@Component(
31+
name = "azureOpenAi.llm.provider.service",
32+
immediate = true,
33+
service = LLMProviderService.class
34+
)
35+
public class AzureOpenAiLLMProviderService extends BuiltInLLMProviderService {
36+
37+
@Override
38+
public String getType() {
39+
40+
return APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_CONNECTOR;
41+
}
42+
43+
@Override
44+
public LLMProvider registerLLMProvider(String organization, String apiDefinitionFilePath)
45+
throws APIManagementException {
46+
47+
try {
48+
LLMProvider llmProvider = new LLMProvider();
49+
llmProvider.setName(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_NAME);
50+
llmProvider.setApiVersion(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_VERSION);
51+
llmProvider.setOrganization(organization);
52+
llmProvider.setDescription(
53+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_DESCRIPTION);
54+
llmProvider.setBuiltInSupport(true);
55+
llmProvider.setApiDefinition(readApiDefinition(
56+
apiDefinitionFilePath
57+
+ APIConstants.AIAPIConstants
58+
.LLM_PROVIDER_SERVICE_AZURE_OPENAI_API_DEFINITION_FILE_NAME));
59+
60+
LLMProviderConfiguration llmProviderConfiguration = new LLMProviderConfiguration();
61+
llmProviderConfiguration.setAuthHeader(APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_AZURE_OPENAI_KEY);
62+
llmProviderConfiguration.setAuthQueryParam(null);
63+
llmProviderConfiguration.setConnectorType(this.getType());
64+
65+
List<LLMProviderMetadata> llmProviderMetadata = new ArrayList<>();
66+
llmProviderMetadata.add(new LLMProviderMetadata(
67+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_MODEL,
68+
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
69+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_MODEL));
70+
llmProviderMetadata.add(new LLMProviderMetadata(
71+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_PROMPT_TOKEN_COUNT,
72+
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
73+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_PROMPT_TOKEN_COUNT));
74+
llmProviderMetadata.add(new LLMProviderMetadata(
75+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_COMPLETION_TOKEN_COUNT,
76+
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
77+
APIConstants.AIAPIConstants
78+
.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_COMPLETION_TOKEN_COUNT));
79+
llmProviderMetadata.add(new LLMProviderMetadata(
80+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_TOTAL_TOKEN_COUNT,
81+
APIConstants.AIAPIConstants.INPUT_SOURCE_PAYLOAD,
82+
APIConstants.AIAPIConstants.LLM_PROVIDER_SERVICE_METADATA_IDENTIFIER_TOTAL_TOKEN_COUNT));
83+
llmProviderConfiguration.setMetadata(llmProviderMetadata);
84+
85+
llmProvider.setConfigurations(llmProviderConfiguration.toJsonString());
86+
return llmProvider;
87+
} catch (Exception e) {
88+
throw new APIManagementException("Error occurred when registering LLM Provider:" + this.getType());
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)