From c119edbe3a81219e9be2fac42c923fe537432734 Mon Sep 17 00:00:00 2001 From: pasant9 Date: Tue, 22 Oct 2024 17:31:53 +0530 Subject: [PATCH] Add AI API tests --- .../clients/admin/api/LlmProviderApi.java | 440 ++++++++++++++++++ .../clients/admin/api/LlmProvidersApi.java | 306 ++++++++++++ .../api/dto/AIAPIQuotaLimitAllOfDTO.java | 185 ++++++++ .../admin/api/dto/AIAPIQuotaLimitDTO.java | 243 ++++++++++ .../admin/api/dto/LLMProviderRequestDTO.java | 216 +++++++++ .../admin/api/dto/LLMProviderResponseDTO.java | 273 +++++++++++ .../dto/LLMProviderSummaryResponseDTO.java | 215 +++++++++ .../LLMProviderSummaryResponseListDTO.java | 131 ++++++ .../admin/src/main/resources/admin-api.yaml | 263 +++++++++++ .../test/impl/RestAPIAdminImpl.java | 73 ++- .../tests/aiapi/AIAPITestCase.java | 169 ++++++- .../resources/ai-api/mistral-add-props.json | 2 +- 12 files changed, 2505 insertions(+), 11 deletions(-) create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProviderApi.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProvidersApi.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitAllOfDTO.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitDTO.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderRequestDTO.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderResponseDTO.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseDTO.java create mode 100644 modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseListDTO.java diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProviderApi.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProviderApi.java new file mode 100644 index 0000000000..f3144a1c5f --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProviderApi.java @@ -0,0 +1,440 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api; + +import org.wso2.am.integration.clients.admin.ApiCallback; +import org.wso2.am.integration.clients.admin.ApiClient; +import org.wso2.am.integration.clients.admin.ApiException; +import org.wso2.am.integration.clients.admin.ApiResponse; +import org.wso2.am.integration.clients.admin.Configuration; +import org.wso2.am.integration.clients.admin.Pair; +import org.wso2.am.integration.clients.admin.ProgressRequestBody; +import org.wso2.am.integration.clients.admin.ProgressResponseBody; + +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; + + +import org.wso2.am.integration.clients.admin.api.dto.ErrorDTO; +import java.io.File; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderResponseDTO; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LlmProviderApi { + private ApiClient localVarApiClient; + + public LlmProviderApi() { + this(Configuration.getDefaultApiClient()); + } + + public LlmProviderApi(ApiClient apiClient) { + this.localVarApiClient = apiClient; + } + + public ApiClient getApiClient() { + return localVarApiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.localVarApiClient = apiClient; + } + + /** + * Build call for llmProvidersLlmProviderIdDelete + * @param llmProviderId LLM Provider UUID (required) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + + +
Status Code Description Response Headers
200 OK. LLM provider successfully deleted. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdDeleteCall(String llmProviderId, final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/llm-providers/{llmProviderId}" + .replaceAll("\\{" + "llmProviderId" + "\\}", localVarApiClient.escapeString(llmProviderId.toString())); + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call llmProvidersLlmProviderIdDeleteValidateBeforeCall(String llmProviderId, final ApiCallback _callback) throws ApiException { + + // verify the required parameter 'llmProviderId' is set + if (llmProviderId == null) { + throw new ApiException("Missing the required parameter 'llmProviderId' when calling llmProvidersLlmProviderIdDelete(Async)"); + } + + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdDeleteCall(llmProviderId, _callback); + return localVarCall; + + } + + /** + * Delete a LLM Provider + * Delete a LLM Provider by llmProviderId + * @param llmProviderId LLM Provider UUID (required) + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + +
Status Code Description Response Headers
200 OK. LLM provider successfully deleted. -
404 Not Found. The specified resource does not exist. -
+ */ + public void llmProvidersLlmProviderIdDelete(String llmProviderId) throws ApiException { + llmProvidersLlmProviderIdDeleteWithHttpInfo(llmProviderId); + } + + /** + * Delete a LLM Provider + * Delete a LLM Provider by llmProviderId + * @param llmProviderId LLM Provider UUID (required) + * @return ApiResponse<Void> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + +
Status Code Description Response Headers
200 OK. LLM provider successfully deleted. -
404 Not Found. The specified resource does not exist. -
+ */ + public ApiResponse llmProvidersLlmProviderIdDeleteWithHttpInfo(String llmProviderId) throws ApiException { + okhttp3.Call localVarCall = llmProvidersLlmProviderIdDeleteValidateBeforeCall(llmProviderId, null); + return localVarApiClient.execute(localVarCall); + } + + /** + * Delete a LLM Provider (asynchronously) + * Delete a LLM Provider by llmProviderId + * @param llmProviderId LLM Provider UUID (required) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + + +
Status Code Description Response Headers
200 OK. LLM provider successfully deleted. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdDeleteAsync(String llmProviderId, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdDeleteValidateBeforeCall(llmProviderId, _callback); + localVarApiClient.executeAsync(localVarCall, _callback); + return localVarCall; + } + /** + * Build call for llmProvidersLlmProviderIdGet + * @param llmProviderId LLM Provider UUID (required) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. OpenAPI specification -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdGetCall(String llmProviderId, final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/llm-providers/{llmProviderId}" + .replaceAll("\\{" + "llmProviderId" + "\\}", localVarApiClient.escapeString(llmProviderId.toString())); + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call llmProvidersLlmProviderIdGetValidateBeforeCall(String llmProviderId, final ApiCallback _callback) throws ApiException { + + // verify the required parameter 'llmProviderId' is set + if (llmProviderId == null) { + throw new ApiException("Missing the required parameter 'llmProviderId' when calling llmProvidersLlmProviderIdGet(Async)"); + } + + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdGetCall(llmProviderId, _callback); + return localVarCall; + + } + + /** + * Get LLM Provider + * Get a LLM Provider + * @param llmProviderId LLM Provider UUID (required) + * @return LLMProviderResponseDTO + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. OpenAPI specification -
+ */ + public LLMProviderResponseDTO llmProvidersLlmProviderIdGet(String llmProviderId) throws ApiException { + ApiResponse localVarResp = llmProvidersLlmProviderIdGetWithHttpInfo(llmProviderId); + return localVarResp.getData(); + } + + /** + * Get LLM Provider + * Get a LLM Provider + * @param llmProviderId LLM Provider UUID (required) + * @return ApiResponse<LLMProviderResponseDTO> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. OpenAPI specification -
+ */ + public ApiResponse llmProvidersLlmProviderIdGetWithHttpInfo(String llmProviderId) throws ApiException { + okhttp3.Call localVarCall = llmProvidersLlmProviderIdGetValidateBeforeCall(llmProviderId, null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * Get LLM Provider (asynchronously) + * Get a LLM Provider + * @param llmProviderId LLM Provider UUID (required) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. OpenAPI specification -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdGetAsync(String llmProviderId, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdGetValidateBeforeCall(llmProviderId, _callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } + /** + * Build call for llmProvidersLlmProviderIdPut + * @param llmProviderId LLM Provider UUID (required) + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + + + +
Status Code Description Response Headers
200 OK. LLM Provider updated. -
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdPutCall(String llmProviderId, String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/llm-providers/{llmProviderId}" + .replaceAll("\\{" + "llmProviderId" + "\\}", localVarApiClient.escapeString(llmProviderId.toString())); + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + if (name != null) { + localVarFormParams.put("name", name); + } + + if (apiVersion != null) { + localVarFormParams.put("apiVersion", apiVersion); + } + + if (description != null) { + localVarFormParams.put("description", description); + } + + if (configurations != null) { + localVarFormParams.put("configurations", configurations); + } + + if (apiDefinition != null) { + localVarFormParams.put("apiDefinition", apiDefinition); + } + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + "multipart/form-data" + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call llmProvidersLlmProviderIdPutValidateBeforeCall(String llmProviderId, String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + + // verify the required parameter 'llmProviderId' is set + if (llmProviderId == null) { + throw new ApiException("Missing the required parameter 'llmProviderId' when calling llmProvidersLlmProviderIdPut(Async)"); + } + + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdPutCall(llmProviderId, name, apiVersion, description, configurations, apiDefinition, _callback); + return localVarCall; + + } + + /** + * Update an LLM provider + * Update a LLM provider by LLMProviderId + * @param llmProviderId LLM Provider UUID (required) + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @return LLMProviderResponseDTO + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + + +
Status Code Description Response Headers
200 OK. LLM Provider updated. -
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public LLMProviderResponseDTO llmProvidersLlmProviderIdPut(String llmProviderId, String name, String apiVersion, String description, String configurations, File apiDefinition) throws ApiException { + ApiResponse localVarResp = llmProvidersLlmProviderIdPutWithHttpInfo(llmProviderId, name, apiVersion, description, configurations, apiDefinition); + return localVarResp.getData(); + } + + /** + * Update an LLM provider + * Update a LLM provider by LLMProviderId + * @param llmProviderId LLM Provider UUID (required) + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @return ApiResponse<LLMProviderResponseDTO> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + + +
Status Code Description Response Headers
200 OK. LLM Provider updated. -
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public ApiResponse llmProvidersLlmProviderIdPutWithHttpInfo(String llmProviderId, String name, String apiVersion, String description, String configurations, File apiDefinition) throws ApiException { + okhttp3.Call localVarCall = llmProvidersLlmProviderIdPutValidateBeforeCall(llmProviderId, name, apiVersion, description, configurations, apiDefinition, null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * Update an LLM provider (asynchronously) + * Update a LLM provider by LLMProviderId + * @param llmProviderId LLM Provider UUID (required) + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + + + +
Status Code Description Response Headers
200 OK. LLM Provider updated. -
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call llmProvidersLlmProviderIdPutAsync(String llmProviderId, String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = llmProvidersLlmProviderIdPutValidateBeforeCall(llmProviderId, name, apiVersion, description, configurations, apiDefinition, _callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } +} diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProvidersApi.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProvidersApi.java new file mode 100644 index 0000000000..dbb3b110ee --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/LlmProvidersApi.java @@ -0,0 +1,306 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api; + +import org.wso2.am.integration.clients.admin.ApiCallback; +import org.wso2.am.integration.clients.admin.ApiClient; +import org.wso2.am.integration.clients.admin.ApiException; +import org.wso2.am.integration.clients.admin.ApiResponse; +import org.wso2.am.integration.clients.admin.Configuration; +import org.wso2.am.integration.clients.admin.Pair; +import org.wso2.am.integration.clients.admin.ProgressRequestBody; +import org.wso2.am.integration.clients.admin.ProgressResponseBody; + +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; + + +import org.wso2.am.integration.clients.admin.api.dto.ErrorDTO; +import java.io.File; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderResponseDTO; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderSummaryResponseListDTO; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LlmProvidersApi { + private ApiClient localVarApiClient; + + public LlmProvidersApi() { + this(Configuration.getDefaultApiClient()); + } + + public LlmProvidersApi(ApiClient apiClient) { + this.localVarApiClient = apiClient; + } + + public ApiClient getApiClient() { + return localVarApiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.localVarApiClient = apiClient; + } + + /** + * Build call for llmProvidersGet + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. LLM providers returned -
+ */ + public okhttp3.Call llmProvidersGetCall(final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/llm-providers"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call llmProvidersGetValidateBeforeCall(final ApiCallback _callback) throws ApiException { + + + okhttp3.Call localVarCall = llmProvidersGetCall(_callback); + return localVarCall; + + } + + /** + * Get all LLM providers + * Get all LLM providers + * @return LLMProviderSummaryResponseListDTO + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. LLM providers returned -
+ */ + public LLMProviderSummaryResponseListDTO llmProvidersGet() throws ApiException { + ApiResponse localVarResp = llmProvidersGetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * Get all LLM providers + * Get all LLM providers + * @return ApiResponse<LLMProviderSummaryResponseListDTO> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. LLM providers returned -
+ */ + public ApiResponse llmProvidersGetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = llmProvidersGetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * Get all LLM providers (asynchronously) + * Get all LLM providers + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 OK. LLM providers returned -
+ */ + public okhttp3.Call llmProvidersGetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = llmProvidersGetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } + /** + * Build call for llmProvidersPost + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created LLM provider as entity in the body. -
400 Bad Request. Invalid request or validation error. -
+ */ + public okhttp3.Call llmProvidersPostCall(String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/llm-providers"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + if (name != null) { + localVarFormParams.put("name", name); + } + + if (apiVersion != null) { + localVarFormParams.put("apiVersion", apiVersion); + } + + if (description != null) { + localVarFormParams.put("description", description); + } + + if (configurations != null) { + localVarFormParams.put("configurations", configurations); + } + + if (apiDefinition != null) { + localVarFormParams.put("apiDefinition", apiDefinition); + } + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + "multipart/form-data" + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call llmProvidersPostValidateBeforeCall(String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + + + okhttp3.Call localVarCall = llmProvidersPostCall(name, apiVersion, description, configurations, apiDefinition, _callback); + return localVarCall; + + } + + /** + * Add a LLM provider + * Add a new LLM provider + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @return LLMProviderResponseDTO + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created LLM provider as entity in the body. -
400 Bad Request. Invalid request or validation error. -
+ */ + public LLMProviderResponseDTO llmProvidersPost(String name, String apiVersion, String description, String configurations, File apiDefinition) throws ApiException { + ApiResponse localVarResp = llmProvidersPostWithHttpInfo(name, apiVersion, description, configurations, apiDefinition); + return localVarResp.getData(); + } + + /** + * Add a LLM provider + * Add a new LLM provider + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @return ApiResponse<LLMProviderResponseDTO> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created LLM provider as entity in the body. -
400 Bad Request. Invalid request or validation error. -
+ */ + public ApiResponse llmProvidersPostWithHttpInfo(String name, String apiVersion, String description, String configurations, File apiDefinition) throws ApiException { + okhttp3.Call localVarCall = llmProvidersPostValidateBeforeCall(name, apiVersion, description, configurations, apiDefinition, null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * Add a LLM provider (asynchronously) + * Add a new LLM provider + * @param name (optional) + * @param apiVersion (optional) + * @param description (optional) + * @param configurations LLM Provider configurations (optional) + * @param apiDefinition OpenAPI specification (optional) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created LLM provider as entity in the body. -
400 Bad Request. Invalid request or validation error. -
+ */ + public okhttp3.Call llmProvidersPostAsync(String name, String apiVersion, String description, String configurations, File apiDefinition, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = llmProvidersPostValidateBeforeCall(name, apiVersion, description, configurations, apiDefinition, _callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } +} diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitAllOfDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitAllOfDTO.java new file mode 100644 index 0000000000..e4415467b3 --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitAllOfDTO.java @@ -0,0 +1,185 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.IOException; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* AIAPIQuotaLimitAllOfDTO +*/ + +public class AIAPIQuotaLimitAllOfDTO { + public static final String SERIALIZED_NAME_REQUEST_COUNT = "requestCount"; + @SerializedName(SERIALIZED_NAME_REQUEST_COUNT) + private Long requestCount; + + public static final String SERIALIZED_NAME_TOTAL_TOKEN_COUNT = "totalTokenCount"; + @SerializedName(SERIALIZED_NAME_TOTAL_TOKEN_COUNT) + private Long totalTokenCount; + + public static final String SERIALIZED_NAME_PROMPT_TOKEN_COUNT = "promptTokenCount"; + @SerializedName(SERIALIZED_NAME_PROMPT_TOKEN_COUNT) + private Long promptTokenCount; + + public static final String SERIALIZED_NAME_COMPLETION_TOKEN_COUNT = "completionTokenCount"; + @SerializedName(SERIALIZED_NAME_COMPLETION_TOKEN_COUNT) + private Long completionTokenCount; + + + public AIAPIQuotaLimitAllOfDTO requestCount(Long requestCount) { + + this.requestCount = requestCount; + return this; + } + + /** + * Maximum number of requests allowed + * @return requestCount + **/ + @ApiModelProperty(example = "300", required = true, value = "Maximum number of requests allowed") + + public Long getRequestCount() { + return requestCount; + } + + + public void setRequestCount(Long requestCount) { + this.requestCount = requestCount; + } + + + public AIAPIQuotaLimitAllOfDTO totalTokenCount(Long totalTokenCount) { + + this.totalTokenCount = totalTokenCount; + return this; + } + + /** + * Maximum number of total tokens allowed + * @return totalTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "800", value = "Maximum number of total tokens allowed") + + public Long getTotalTokenCount() { + return totalTokenCount; + } + + + public void setTotalTokenCount(Long totalTokenCount) { + this.totalTokenCount = totalTokenCount; + } + + + public AIAPIQuotaLimitAllOfDTO promptTokenCount(Long promptTokenCount) { + + this.promptTokenCount = promptTokenCount; + return this; + } + + /** + * Maximum number of prompt tokens allowed + * @return promptTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "400", value = "Maximum number of prompt tokens allowed") + + public Long getPromptTokenCount() { + return promptTokenCount; + } + + + public void setPromptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; + } + + + public AIAPIQuotaLimitAllOfDTO completionTokenCount(Long completionTokenCount) { + + this.completionTokenCount = completionTokenCount; + return this; + } + + /** + * Maximum number of completion tokens allowed + * @return completionTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "500", value = "Maximum number of completion tokens allowed") + + public Long getCompletionTokenCount() { + return completionTokenCount; + } + + + public void setCompletionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AIAPIQuotaLimitAllOfDTO aiAPIQuotaLimitAllOf = (AIAPIQuotaLimitAllOfDTO) o; + return Objects.equals(this.requestCount, aiAPIQuotaLimitAllOf.requestCount) && + Objects.equals(this.totalTokenCount, aiAPIQuotaLimitAllOf.totalTokenCount) && + Objects.equals(this.promptTokenCount, aiAPIQuotaLimitAllOf.promptTokenCount) && + Objects.equals(this.completionTokenCount, aiAPIQuotaLimitAllOf.completionTokenCount); + } + + @Override + public int hashCode() { + return Objects.hash(requestCount, totalTokenCount, promptTokenCount, completionTokenCount); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class AIAPIQuotaLimitAllOfDTO {\n"); + sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); + sb.append(" totalTokenCount: ").append(toIndentedString(totalTokenCount)).append("\n"); + sb.append(" promptTokenCount: ").append(toIndentedString(promptTokenCount)).append("\n"); + sb.append(" completionTokenCount: ").append(toIndentedString(completionTokenCount)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitDTO.java new file mode 100644 index 0000000000..cacbc13c23 --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/AIAPIQuotaLimitDTO.java @@ -0,0 +1,243 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.IOException; +import org.wso2.am.integration.clients.admin.api.dto.AIAPIQuotaLimitAllOfDTO; +import org.wso2.am.integration.clients.admin.api.dto.ThrottleLimitBaseDTO; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* AIAPIQuotaLimitDTO +*/ + +public class AIAPIQuotaLimitDTO { + public static final String SERIALIZED_NAME_TIME_UNIT = "timeUnit"; + @SerializedName(SERIALIZED_NAME_TIME_UNIT) + private String timeUnit; + + public static final String SERIALIZED_NAME_UNIT_TIME = "unitTime"; + @SerializedName(SERIALIZED_NAME_UNIT_TIME) + private Integer unitTime; + + public static final String SERIALIZED_NAME_REQUEST_COUNT = "requestCount"; + @SerializedName(SERIALIZED_NAME_REQUEST_COUNT) + private Long requestCount; + + public static final String SERIALIZED_NAME_TOTAL_TOKEN_COUNT = "totalTokenCount"; + @SerializedName(SERIALIZED_NAME_TOTAL_TOKEN_COUNT) + private Long totalTokenCount; + + public static final String SERIALIZED_NAME_PROMPT_TOKEN_COUNT = "promptTokenCount"; + @SerializedName(SERIALIZED_NAME_PROMPT_TOKEN_COUNT) + private Long promptTokenCount; + + public static final String SERIALIZED_NAME_COMPLETION_TOKEN_COUNT = "completionTokenCount"; + @SerializedName(SERIALIZED_NAME_COMPLETION_TOKEN_COUNT) + private Long completionTokenCount; + + + public AIAPIQuotaLimitDTO timeUnit(String timeUnit) { + + this.timeUnit = timeUnit; + return this; + } + + /** + * Unit of the time. Allowed values are \"sec\", \"min\", \"hour\", \"day\" + * @return timeUnit + **/ + @ApiModelProperty(example = "min", required = true, value = "Unit of the time. Allowed values are \"sec\", \"min\", \"hour\", \"day\"") + + public String getTimeUnit() { + return timeUnit; + } + + + public void setTimeUnit(String timeUnit) { + this.timeUnit = timeUnit; + } + + + public AIAPIQuotaLimitDTO unitTime(Integer unitTime) { + + this.unitTime = unitTime; + return this; + } + + /** + * Time limit that the throttling limit applies. + * @return unitTime + **/ + @ApiModelProperty(example = "10", required = true, value = "Time limit that the throttling limit applies.") + + public Integer getUnitTime() { + return unitTime; + } + + + public void setUnitTime(Integer unitTime) { + this.unitTime = unitTime; + } + + + public AIAPIQuotaLimitDTO requestCount(Long requestCount) { + + this.requestCount = requestCount; + return this; + } + + /** + * Maximum number of requests allowed + * @return requestCount + **/ + @ApiModelProperty(example = "300", required = true, value = "Maximum number of requests allowed") + + public Long getRequestCount() { + return requestCount; + } + + + public void setRequestCount(Long requestCount) { + this.requestCount = requestCount; + } + + + public AIAPIQuotaLimitDTO totalTokenCount(Long totalTokenCount) { + + this.totalTokenCount = totalTokenCount; + return this; + } + + /** + * Maximum number of total tokens allowed + * @return totalTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "800", value = "Maximum number of total tokens allowed") + + public Long getTotalTokenCount() { + return totalTokenCount; + } + + + public void setTotalTokenCount(Long totalTokenCount) { + this.totalTokenCount = totalTokenCount; + } + + + public AIAPIQuotaLimitDTO promptTokenCount(Long promptTokenCount) { + + this.promptTokenCount = promptTokenCount; + return this; + } + + /** + * Maximum number of prompt tokens allowed + * @return promptTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "400", value = "Maximum number of prompt tokens allowed") + + public Long getPromptTokenCount() { + return promptTokenCount; + } + + + public void setPromptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; + } + + + public AIAPIQuotaLimitDTO completionTokenCount(Long completionTokenCount) { + + this.completionTokenCount = completionTokenCount; + return this; + } + + /** + * Maximum number of completion tokens allowed + * @return completionTokenCount + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "500", value = "Maximum number of completion tokens allowed") + + public Long getCompletionTokenCount() { + return completionTokenCount; + } + + + public void setCompletionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AIAPIQuotaLimitDTO aiAPIQuotaLimit = (AIAPIQuotaLimitDTO) o; + return Objects.equals(this.timeUnit, aiAPIQuotaLimit.timeUnit) && + Objects.equals(this.unitTime, aiAPIQuotaLimit.unitTime) && + Objects.equals(this.requestCount, aiAPIQuotaLimit.requestCount) && + Objects.equals(this.totalTokenCount, aiAPIQuotaLimit.totalTokenCount) && + Objects.equals(this.promptTokenCount, aiAPIQuotaLimit.promptTokenCount) && + Objects.equals(this.completionTokenCount, aiAPIQuotaLimit.completionTokenCount); + } + + @Override + public int hashCode() { + return Objects.hash(timeUnit, unitTime, requestCount, totalTokenCount, promptTokenCount, completionTokenCount); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class AIAPIQuotaLimitDTO {\n"); + sb.append(" timeUnit: ").append(toIndentedString(timeUnit)).append("\n"); + sb.append(" unitTime: ").append(toIndentedString(unitTime)).append("\n"); + sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); + sb.append(" totalTokenCount: ").append(toIndentedString(totalTokenCount)).append("\n"); + sb.append(" promptTokenCount: ").append(toIndentedString(promptTokenCount)).append("\n"); + sb.append(" completionTokenCount: ").append(toIndentedString(completionTokenCount)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderRequestDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderRequestDTO.java new file mode 100644 index 0000000000..daecdc4b3b --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderRequestDTO.java @@ -0,0 +1,216 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.File; +import java.io.IOException; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* LLMProviderRequestDTO +*/ + +public class LLMProviderRequestDTO { + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public static final String SERIALIZED_NAME_API_VERSION = "apiVersion"; + @SerializedName(SERIALIZED_NAME_API_VERSION) + private String apiVersion; + + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; + @SerializedName(SERIALIZED_NAME_DESCRIPTION) + private String description; + + public static final String SERIALIZED_NAME_CONFIGURATIONS = "configurations"; + @SerializedName(SERIALIZED_NAME_CONFIGURATIONS) + private String configurations; + + public static final String SERIALIZED_NAME_API_DEFINITION = "apiDefinition"; + @SerializedName(SERIALIZED_NAME_API_DEFINITION) + private File apiDefinition; + + + public LLMProviderRequestDTO name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "OpenAI", value = "") + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public LLMProviderRequestDTO apiVersion(String apiVersion) { + + this.apiVersion = apiVersion; + return this; + } + + /** + * Get apiVersion + * @return apiVersion + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "1.0.0", value = "") + + public String getApiVersion() { + return apiVersion; + } + + + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + + public LLMProviderRequestDTO description(String description) { + + this.description = description; + return this; + } + + /** + * Get description + * @return description + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "OpenAI LLM", value = "") + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public LLMProviderRequestDTO configurations(String configurations) { + + this.configurations = configurations; + return this; + } + + /** + * LLM Provider configurations + * @return configurations + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "LLM Provider configurations") + + public String getConfigurations() { + return configurations; + } + + + public void setConfigurations(String configurations) { + this.configurations = configurations; + } + + + public LLMProviderRequestDTO apiDefinition(File apiDefinition) { + + this.apiDefinition = apiDefinition; + return this; + } + + /** + * OpenAPI specification + * @return apiDefinition + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "OpenAPI specification") + + public File getApiDefinition() { + return apiDefinition; + } + + + public void setApiDefinition(File apiDefinition) { + this.apiDefinition = apiDefinition; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LLMProviderRequestDTO llMProviderRequest = (LLMProviderRequestDTO) o; + return Objects.equals(this.name, llMProviderRequest.name) && + Objects.equals(this.apiVersion, llMProviderRequest.apiVersion) && + Objects.equals(this.description, llMProviderRequest.description) && + Objects.equals(this.configurations, llMProviderRequest.configurations) && + Objects.equals(this.apiDefinition, llMProviderRequest.apiDefinition); + } + + @Override + public int hashCode() { + return Objects.hash(name, apiVersion, description, configurations, apiDefinition); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class LLMProviderRequestDTO {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" apiVersion: ").append(toIndentedString(apiVersion)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" configurations: ").append(toIndentedString(configurations)).append("\n"); + sb.append(" apiDefinition: ").append(toIndentedString(apiDefinition)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderResponseDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderResponseDTO.java new file mode 100644 index 0000000000..03354f0121 --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderResponseDTO.java @@ -0,0 +1,273 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.IOException; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* LLMProviderResponseDTO +*/ + +public class LLMProviderResponseDTO { + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + private String id; + + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public static final String SERIALIZED_NAME_API_VERSION = "apiVersion"; + @SerializedName(SERIALIZED_NAME_API_VERSION) + private String apiVersion; + + public static final String SERIALIZED_NAME_BUILT_IN_SUPPORT = "builtInSupport"; + @SerializedName(SERIALIZED_NAME_BUILT_IN_SUPPORT) + private Boolean builtInSupport; + + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; + @SerializedName(SERIALIZED_NAME_DESCRIPTION) + private String description; + + public static final String SERIALIZED_NAME_CONFIGURATIONS = "configurations"; + @SerializedName(SERIALIZED_NAME_CONFIGURATIONS) + private String configurations; + + public static final String SERIALIZED_NAME_API_DEFINITION = "apiDefinition"; + @SerializedName(SERIALIZED_NAME_API_DEFINITION) + private String apiDefinition; + + + public LLMProviderResponseDTO id(String id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "ece92bdc-e1e6-325c-b6f4-656208a041e9", value = "") + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public LLMProviderResponseDTO name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "OpenAI", value = "") + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public LLMProviderResponseDTO apiVersion(String apiVersion) { + + this.apiVersion = apiVersion; + return this; + } + + /** + * Get apiVersion + * @return apiVersion + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "1.0.0", value = "") + + public String getApiVersion() { + return apiVersion; + } + + + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + + public LLMProviderResponseDTO builtInSupport(Boolean builtInSupport) { + + this.builtInSupport = builtInSupport; + return this; + } + + /** + * Is built-in support + * @return builtInSupport + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "Is built-in support") + + public Boolean isBuiltInSupport() { + return builtInSupport; + } + + + public void setBuiltInSupport(Boolean builtInSupport) { + this.builtInSupport = builtInSupport; + } + + + public LLMProviderResponseDTO description(String description) { + + this.description = description; + return this; + } + + /** + * Get description + * @return description + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "OpenAI LLM", value = "") + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public LLMProviderResponseDTO configurations(String configurations) { + + this.configurations = configurations; + return this; + } + + /** + * LLM Provider configurations + * @return configurations + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "LLM Provider configurations") + + public String getConfigurations() { + return configurations; + } + + + public void setConfigurations(String configurations) { + this.configurations = configurations; + } + + + public LLMProviderResponseDTO apiDefinition(String apiDefinition) { + + this.apiDefinition = apiDefinition; + return this; + } + + /** + * OpenAPI specification + * @return apiDefinition + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "OpenAPI specification") + + public String getApiDefinition() { + return apiDefinition; + } + + + public void setApiDefinition(String apiDefinition) { + this.apiDefinition = apiDefinition; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LLMProviderResponseDTO llMProviderResponse = (LLMProviderResponseDTO) o; + return Objects.equals(this.id, llMProviderResponse.id) && + Objects.equals(this.name, llMProviderResponse.name) && + Objects.equals(this.apiVersion, llMProviderResponse.apiVersion) && + Objects.equals(this.builtInSupport, llMProviderResponse.builtInSupport) && + Objects.equals(this.description, llMProviderResponse.description) && + Objects.equals(this.configurations, llMProviderResponse.configurations) && + Objects.equals(this.apiDefinition, llMProviderResponse.apiDefinition); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, apiVersion, builtInSupport, description, configurations, apiDefinition); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class LLMProviderResponseDTO {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" apiVersion: ").append(toIndentedString(apiVersion)).append("\n"); + sb.append(" builtInSupport: ").append(toIndentedString(builtInSupport)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" configurations: ").append(toIndentedString(configurations)).append("\n"); + sb.append(" apiDefinition: ").append(toIndentedString(apiDefinition)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseDTO.java new file mode 100644 index 0000000000..2d688c9569 --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseDTO.java @@ -0,0 +1,215 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.IOException; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* LLMProviderSummaryResponseDTO +*/ + +public class LLMProviderSummaryResponseDTO { + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + private String id; + + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public static final String SERIALIZED_NAME_API_VERSION = "apiVersion"; + @SerializedName(SERIALIZED_NAME_API_VERSION) + private String apiVersion; + + public static final String SERIALIZED_NAME_BUILT_IN_SUPPORT = "builtInSupport"; + @SerializedName(SERIALIZED_NAME_BUILT_IN_SUPPORT) + private Boolean builtInSupport; + + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; + @SerializedName(SERIALIZED_NAME_DESCRIPTION) + private String description; + + + public LLMProviderSummaryResponseDTO id(String id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "ece92bdc-e1e6-325c-b6f4-656208a041e9", value = "") + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public LLMProviderSummaryResponseDTO name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "open-ai", value = "") + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public LLMProviderSummaryResponseDTO apiVersion(String apiVersion) { + + this.apiVersion = apiVersion; + return this; + } + + /** + * Get apiVersion + * @return apiVersion + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "1.0.0", value = "") + + public String getApiVersion() { + return apiVersion; + } + + + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + + public LLMProviderSummaryResponseDTO builtInSupport(Boolean builtInSupport) { + + this.builtInSupport = builtInSupport; + return this; + } + + /** + * Is built-in support + * @return builtInSupport + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "Is built-in support") + + public Boolean isBuiltInSupport() { + return builtInSupport; + } + + + public void setBuiltInSupport(Boolean builtInSupport) { + this.builtInSupport = builtInSupport; + } + + + public LLMProviderSummaryResponseDTO description(String description) { + + this.description = description; + return this; + } + + /** + * Get description + * @return description + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "OpenAI LLM Provider", value = "") + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LLMProviderSummaryResponseDTO llMProviderSummaryResponse = (LLMProviderSummaryResponseDTO) o; + return Objects.equals(this.id, llMProviderSummaryResponse.id) && + Objects.equals(this.name, llMProviderSummaryResponse.name) && + Objects.equals(this.apiVersion, llMProviderSummaryResponse.apiVersion) && + Objects.equals(this.builtInSupport, llMProviderSummaryResponse.builtInSupport) && + Objects.equals(this.description, llMProviderSummaryResponse.description); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, apiVersion, builtInSupport, description); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class LLMProviderSummaryResponseDTO {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" apiVersion: ").append(toIndentedString(apiVersion)).append("\n"); + sb.append(" builtInSupport: ").append(toIndentedString(builtInSupport)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseListDTO.java b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseListDTO.java new file mode 100644 index 0000000000..0b632c3a0c --- /dev/null +++ b/modules/integration/tests-common/clients/admin/src/gen/java/org/wso2/am/integration/clients/admin/api/dto/LLMProviderSummaryResponseListDTO.java @@ -0,0 +1,131 @@ +/* + * WSO2 API Manager - Admin + * This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://:/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=&password=&scope=\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://:/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6) + * + * The version of the OpenAPI document: v4 + * Contact: architecture@wso2.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.wso2.am.integration.clients.admin.api.dto; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderSummaryResponseDTO; +import com.fasterxml.jackson.annotation.JsonCreator; +/** +* LLMProviderSummaryResponseListDTO +*/ + +public class LLMProviderSummaryResponseListDTO { + public static final String SERIALIZED_NAME_COUNT = "count"; + @SerializedName(SERIALIZED_NAME_COUNT) + private Integer count; + + public static final String SERIALIZED_NAME_LIST = "list"; + @SerializedName(SERIALIZED_NAME_LIST) + private List list = null; + + + public LLMProviderSummaryResponseListDTO count(Integer count) { + + this.count = count; + return this; + } + + /** + * Number of LLM Providers returned. + * @return count + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "1", value = "Number of LLM Providers returned. ") + + public Integer getCount() { + return count; + } + + + public void setCount(Integer count) { + this.count = count; + } + + + public LLMProviderSummaryResponseListDTO list(List list) { + + this.list = list; + return this; + } + + /** + * Get list + * @return list + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + + public List getList() { + return list; + } + + + public void setList(List list) { + this.list = list; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LLMProviderSummaryResponseListDTO llMProviderSummaryResponseList = (LLMProviderSummaryResponseListDTO) o; + return Objects.equals(this.count, llMProviderSummaryResponseList.count) && + Objects.equals(this.list, llMProviderSummaryResponseList.list); + } + + @Override + public int hashCode() { + return Objects.hash(count, list); + } + + +@Override +public String toString() { +StringBuilder sb = new StringBuilder(); +sb.append("class LLMProviderSummaryResponseListDTO {\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" list: ").append(toIndentedString(list)).append("\n"); +sb.append("}"); +return sb.toString(); +} + +/** +* Convert the given object to string with each line indented by 4 spaces +* (except the first line). +*/ +private String toIndentedString(Object o) { +if (o == null) { +return "null"; +} +return o.toString().replace("\n", "\n "); +} + +} + diff --git a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml index 1e34da2414..062a0a2327 100644 --- a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml +++ b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml @@ -2782,6 +2782,166 @@ paths: source: 'curl -k -X DELETE -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://127.0.0.1:9443/api/am/admin/v4/labels/d7cf8523-9180-4255-84fa-6cb171c1f779"' + ###################################################### + # LLM Providers resource APIs + ###################################################### + /llm-providers: + get: + tags: + - LLMProviders + summary: Get all LLM providers + description: | + Get all LLM providers + responses: + 200: + description: | + OK. + LLM providers returned + content: + application/json: + schema: + $ref: '#/components/schemas/LLMProviderSummaryResponseList' + security: + - OAuth2Security: + - apim:admin + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/llm-providers"' + + post: + tags: + - LLMProviders + summary: Add a LLM provider + description: | + Add a new LLM provider + requestBody: + description: | + LLM provider object that should to be added + content: + multipart/form-data: + schema: + required: + - name + - apiVersion + - configurations + - apiDefinition + $ref: '#/components/schemas/LLMProviderRequest' + required: true + responses: + 201: + description: | + Created. + Successful response with the newly created LLM provider as entity in the body. + content: + application/json: + schema: + $ref: '#/components/schemas/LLMProviderResponse' + 400: + $ref: '#/components/responses/BadRequest' + security: + - OAuth2Security: + - apim:admin + - apim:llm_provider_manage + x-code-samples: + - lang: Curl + source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" -d @data.json "https://127.0.0.1:9443/api/am/admin/v4/llm-providers"' + + ###################################################### + # The "Individual LLM Provider" resource APIs + ###################################################### + /llm-providers/{llmProviderId}: + put: + tags: + - LLMProvider + summary: Update an LLM provider + description: | + Update a LLM provider by LLMProviderId + parameters: + - $ref: '#/components/parameters/llmProviderId' + requestBody: + description: | + LLM Provider object with updated information + content: + multipart/form-data: + schema: + required: + - apiDefinition + $ref: '#/components/schemas/LLMProviderRequest' + required: true + responses: + 200: + description: | + OK. + LLM Provider updated. + content: + application/json: + schema: + $ref: '#/components/schemas/LLMProviderResponse' + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + security: + - OAuth2Security: + - apim:admin + - apim:llm_provider_manage + x-code-samples: + - lang: Curl + source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" -d @data.json "https://127.0.0.1:9443/api/am/admin/v4/llm-providers/a2f1e643-9b2a-4f58-bd7a-8c2d3f1e9d6f"' + + delete: + tags: + - LLMProvider + summary: Delete a LLM Provider + description: | + Delete a LLM Provider by llmProviderId + parameters: + - $ref: '#/components/parameters/llmProviderId' + responses: + 200: + description: | + OK. + LLM provider successfully deleted. + content: { } + 404: + $ref: '#/components/responses/NotFound' + security: + - OAuth2Security: + - apim:admin + - apim:llm_provider_manage + x-code-samples: + - lang: Curl + source: 'curl -k -X DELETE -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/llm-providers/a2f1e643-9b2a-4f58-bd7a-8c2d3f1e9d6f"' + + get: + tags: + - LLMProvider + summary: Get LLM Provider + description: | + Get a LLM Provider + parameters: + - $ref: '#/components/parameters/llmProviderId' + responses: + 200: + description: | + OK. + OpenAPI specification + content: + application/json: + schema: + $ref: '#/components/schemas/LLMProviderResponse' + security: + - OAuth2Security: + - apim:admin + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/llm-providers/a2f1e643-9b2a-4f58-bd7a-8c2d3f1e9d6f"' + ###################################################### # The "Environment" resource API ###################################################### @@ -5330,6 +5490,100 @@ components: type: array items: $ref: '#/components/schemas/Environment' + LLMProviderRequest: + title: LLMProvider + type: object + properties: + name: + maxLength: 255 + minLength: 1 + type: string + example: OpenAI + apiVersion: + maxLength: 255 + minLength: 1 + type: string + example: 1.0.0 + description: + maxLength: 1023 + type: string + example: OpenAI LLM + configurations: + type: string + description: LLM Provider configurations + apiDefinition: + type: string + description: OpenAPI specification + format: binary + LLMProviderResponse: + title: LLMProviderResponse + type: object + properties: + id: + type: string + readOnly: true + example: ece92bdc-e1e6-325c-b6f4-656208a041e9 + name: + maxLength: 255 + minLength: 1 + type: string + example: OpenAI + apiVersion: + maxLength: 255 + minLength: 1 + type: string + example: 1.0.0 + builtInSupport: + type: boolean + description: Is built-in support + description: + maxLength: 1023 + type: string + example: OpenAI LLM + configurations: + type: string + description: LLM Provider configurations + apiDefinition: + type: string + description: OpenAPI specification + LLMProviderSummaryResponse: + title: LLMProviderSummaryResponse + type: object + properties: + id: + type: string + readOnly: true + example: ece92bdc-e1e6-325c-b6f4-656208a041e9 + name: + maxLength: 255 + minLength: 1 + type: string + example: open-ai + apiVersion: + maxLength: 255 + minLength: 1 + type: string + example: 1.0.0 + builtInSupport: + type: boolean + description: Is built-in support + description: + maxLength: 1023 + type: string + example: OpenAI LLM Provider + LLMProviderSummaryResponseList: + title: LLMProviderSummaryResponseList + type: object + properties: + count: + type: integer + description: | + Number of LLM Providers returned. + example: 1 + list: + type: array + items: + $ref: '#/components/schemas/LLMProviderSummaryResponse' VHost: title: Virtual Host required: @@ -6332,6 +6586,14 @@ components: required: true schema: type: string + llmProviderId: + name: llmProviderId + in: path + description: | + LLM Provider UUID + required: true + schema: + type: string policyId: name: policyId in: path @@ -6511,3 +6773,4 @@ components: apim:admin_alert_manage: Manage admin alerts apim:api_workflow_view: Retrive workflow requests apim:scope_manage: Manage system scopes + apim:llm_provider_manage: Manage LLM Providers diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java index fe81dea422..cfabed8911 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java @@ -63,6 +63,8 @@ public class RestAPIAdminImpl { private LabelApi labelApi = new LabelApi(); private LabelCollectionApi labelCollectionApi = new LabelCollectionApi(); private EnvironmentApi environmentApi = new EnvironmentApi(); + private LlmProviderApi llmProviderApi = new LlmProviderApi(); + private LlmProvidersApi llmProvidersApi = new LlmProvidersApi(); private EnvironmentCollectionApi environmentCollectionApi = new EnvironmentCollectionApi(); private TenantConfigApi tenantConfigApi = new TenantConfigApi(); private TenantConfigSchemaApi tenantConfigSchemaApi = new TenantConfigSchemaApi(); @@ -145,6 +147,8 @@ public RestAPIAdminImpl(String username, String password, String tenantDomain, S labelApi.setApiClient(apiAdminClient); labelCollectionApi.setApiClient(apiAdminClient); environmentApi.setApiClient(apiAdminClient); + llmProviderApi.setApiClient(apiAdminClient); + llmProvidersApi.setApiClient(apiAdminClient); environmentCollectionApi.setApiClient(apiAdminClient); workflowCollectionApi.setApiClient(apiAdminClient); workflowsIndividualApi.setApiClient(apiAdminClient); @@ -245,6 +249,73 @@ public ApiResponse deleteApiCategory(String uuid) throws ApiException { return apiCategoryIndividualApi.apiCategoriesApiCategoryIdDeleteWithHttpInfo(uuid, null, null); } + /** + * Retrieves a list of LLM Providers. + * + * @return ApiResponse containing a list of LLMProviderSummaryResponseListDTO with details about available LLM providers. + * @throws ApiException if there is an error during the API call. + */ + public ApiResponse getLLMProviders() throws ApiException { + return llmProvidersApi.llmProvidersGetWithHttpInfo(); + } + + /** + * Retrieves details of a specific LLM Provider by its ID. + * + * @param llmProviderId The unique identifier of the LLM provider. + * @return ApiResponse containing LLMProviderResponseDTO with details of the specified LLM provider. + * @throws ApiException if there is an error during the API call. + */ + public ApiResponse getLLMProvider(String llmProviderId) throws ApiException { + return llmProviderApi.llmProvidersLlmProviderIdGetWithHttpInfo(llmProviderId); + } + + /** + * Add the details of a specific LLM Provider. + * + * @param name The new name of the LLM provider. + * @param apiVersion The API version of the LLM provider. + * @param description A brief description of the LLM provider. + * @param configuration Configuration details for the LLM provider. + * @param apiDefinition The API definition file for the LLM provider. + * @return ApiResponse containing LLMProviderResponseDTO with the updated details of the LLM provider. + * @throws ApiException if there is an error during the API call. + */ + public ApiResponse addLLMProvider(String name, String apiVersion, String description, + String configuration, File apiDefinition) throws ApiException { + + return llmProvidersApi.llmProvidersPostWithHttpInfo(name, apiVersion, description, configuration, + apiDefinition); + } + + /** + * Updates the details of a specific LLM Provider by its ID. + * + * @param llmProviderId The unique identifier of the LLM provider. + * @param name The new name of the LLM provider. + * @param apiVersion The API version of the LLM provider. + * @param description A brief description of the LLM provider. + * @param configuration Configuration details for the LLM provider. + * @param apiDefinition The API definition file for the LLM provider. + * @return ApiResponse containing LLMProviderResponseDTO with the updated details of the LLM provider. + * @throws ApiException if there is an error during the API call. + */ + public ApiResponse updateLLMProvider(String llmProviderId, String name, String apiVersion, String description, + String configuration, File apiDefinition) throws ApiException { + return llmProviderApi.llmProvidersLlmProviderIdPutWithHttpInfo(llmProviderId, name, apiVersion, description, configuration, apiDefinition); + } + + /** + * Deletes a specific LLM Provider by its ID. + * + * @param llmProviderId The unique identifier of the LLM provider to be deleted. + * @return ApiResponse containing void, indicating successful deletion of the LLM provider. + * @throws ApiException if there is an error during the API call. + */ + public ApiResponse deleteLLMProvider(String llmProviderId) throws ApiException { + return llmProviderApi.llmProvidersLlmProviderIdDeleteWithHttpInfo(llmProviderId); + } + /*** * This method is used to put an system scopes mapping. * @@ -683,7 +754,7 @@ public ApiResponse deleteEnvironment(String environmentId) throws ApiExcep return environmentApi.environmentsEnvironmentIdDeleteWithHttpInfo(environmentId); } - + /** * This method is used to retrieve applications. * diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi/AIAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi/AIAPITestCase.java index 7fe6780444..e036f2e5f0 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi/AIAPITestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi/AIAPITestCase.java @@ -30,6 +30,10 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; +import org.wso2.am.integration.clients.admin.ApiResponse; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderResponseDTO; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderSummaryResponseDTO; +import org.wso2.am.integration.clients.admin.api.dto.LLMProviderSummaryResponseListDTO; import org.wso2.am.integration.clients.publisher.api.v1.dto.APIDTO; import org.wso2.am.integration.clients.store.api.v1.dto.APIKeyDTO; import org.wso2.am.integration.clients.store.api.v1.dto.ApplicationDTO; @@ -51,7 +55,9 @@ import java.io.FileWriter; import java.io.IOException; import java.net.Socket; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; @@ -63,7 +69,7 @@ /** * AI API Test Case */ -@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) +@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE}) public class AIAPITestCase extends APIMIntegrationBaseTest { private static final Log log = LogFactory.getLog(AIAPITestCase.class); @@ -90,14 +96,44 @@ public class AIAPITestCase extends APIMIntegrationBaseTest { private int lowerPortLimit = 9950; private int upperPortLimit = 9999; + private String llmProviderId; + private final String llmProviderName = "TestAIService"; + private final String llmProviderApiVersion = "1.0.0"; + private final String llmProviderDescription = "This is a copy of MistralAI service"; + + private final String incorrectLlmProviderConfigurations = "{\"connectorType\":\"mistralAi_1.0.0\"," + + "\"metadata\":[{\"attributeName\":\"model\"," + + "\"inputSource\":\"payload\",\"attributeIdentifier\":\"$.usage.model\"}," + + "{\"attributeName\":\"promptTokenCount\",\"inputSource\":\"payload\",\"attributeIdentifier\":\"$" + + ".usage.prompt_tokens\"},{\"attributeName\":\"completionTokenCount\",\"inputSource\":\"payload\"," + + "\"attributeIdentifier\":\"$.usage.completion_tokens\"},{\"attributeName\":\"totalTokenCount\"," + + "\"inputSource\":\"payload\",\"attributeIdentifier\":\"$.usage.total_tokens\"}]," + + "\"authHeader\":\"Authorization\"}"; + + private final String correctLlmProviderConfigurations = "{\"connectorType\":\"mistralAi_1.0.0\"," + + "\"metadata\":[{\"attributeName\":\"model\"," + + "\"inputSource\":\"payload\",\"attributeIdentifier\":\"$.usage.model\"}," + + "{\"attributeName\":\"promptTokenCount\",\"inputSource\":\"payload\",\"attributeIdentifier\":\"$" + + ".usage.prompt_tokens\"},{\"attributeName\":\"completionTokenCount\",\"inputSource\":\"payload\"," + + "\"attributeIdentifier\":\"$.usage.completion_tokens\"},{\"attributeName\":\"totalTokenCount\"," + + "\"inputSource\":\"payload\",\"attributeIdentifier\":\"$.usage.total_tokens\"}]," + + "\"authHeader\":\"Authorization\"}"; + + private List defaultLlmProviders = new ArrayList<>(); + + private final String apiDefinitionFileName = "mistral-def.json"; + + private final String mistralResponseFileName = "mistral-response.json"; @Factory(dataProvider = "userModeDataProvider") public AIAPITestCase(TestUserMode userMode) { + this.userMode = userMode; } @DataProvider public static Object[][] userModeDataProvider() { + return new Object[][]{ {TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}, @@ -106,7 +142,11 @@ public static Object[][] userModeDataProvider() { @BeforeClass(alwaysRun = true) public void setEnvironment() throws Exception { + super.init(userMode); + defaultLlmProviders.add("MistralAI"); + defaultLlmProviders.add("OpenAI"); + defaultLlmProviders.add("AzureOpenAI"); // Add application ApplicationDTO applicationDTO = restAPIStore.addApplication(applicationName, @@ -115,18 +155,101 @@ public void setEnvironment() throws Exception { Assert.assertNotNull(applicationId); resourcePath = TestConfigurationProvider.getResourceLocation() + "ai-api" + File.separator; - mistralResponse = readFile(resourcePath + "mistral-response.json"); + mistralResponse = readFile(resourcePath + mistralResponseFileName); // Start WireMock server startWiremockServer(); } + /** + * Tests the retrieval of predefined LLM providers and verifies all are present. + * Ensures that all predefined LLM providers are retrieved successfully. + */ + @Test(groups = {"wso2.am"}, description = "Test retrieve LLM Providers") + public void testPredefinedLLMProviders() throws Exception { + + List copyDefaultLlmProviders = new ArrayList<>(defaultLlmProviders); + ApiResponse llmProviders = restAPIAdmin.getLLMProviders(); + assertEquals(Response.Status.OK.getStatusCode(), + llmProviders.getStatusCode(), "Failed to retrieve LLM providers"); + for (LLMProviderSummaryResponseDTO provider : llmProviders.getData().getList()) { + if (defaultLlmProviders.contains(provider.getName())) { + copyDefaultLlmProviders.remove(provider.getName()); + } + } + assertEquals(0, + copyDefaultLlmProviders.size(), "Failed to retrieve all predefined LLM providers"); + } + + /** + * Adds a custom LLM provider and verifies successful creation. + * Ensures the provider is created with the given details and retrieves its ID. + */ + @Test(groups = {"wso2.am"}, description = "Add LLM Provider", + dependsOnMethods = "testPredefinedLLMProviders") + public void addCustomLLMProvider() throws Exception { + + String originalDefinition = readFile(resourcePath + apiDefinitionFileName); + File file = getTempFileWithContent(originalDefinition); + + ApiResponse createProviderResponse = restAPIAdmin.addLLMProvider(llmProviderName, + llmProviderApiVersion, llmProviderDescription, incorrectLlmProviderConfigurations, file); + + assertEquals(Response.Status.CREATED.getStatusCode(), + createProviderResponse.getStatusCode(), "Failed to add a LLM provider"); + llmProviderId = createProviderResponse.getData().getId(); + } + + /** + * Retrieves a specified LLM provider and verifies the provider's details. + * Ensures the provider is retrieved successfully and the name and API version match. + */ + @Test(groups = {"wso2.am"}, description = "Get LLM Provider", + dependsOnMethods = "addCustomLLMProvider") + public void retrieveCustomLLMProvider() throws Exception { + + ApiResponse getProviderResponse = restAPIAdmin.getLLMProvider(llmProviderId); + assertEquals(Response.Status.OK.getStatusCode(), + getProviderResponse.getStatusCode(), "Failed to retrieve LLM provider"); + assertEquals(getProviderResponse.getData().getName(), llmProviderName, "LLM provider name does not " + + "match"); + assertEquals(getProviderResponse.getData().getApiVersion(), + llmProviderApiVersion, "LLM provider API version does not match"); + } + + /** + * Updates a specified LLM provider with new configurations and verifies the update. + * Ensures the updated provider is retrieved successfully and the configurations are correct. + */ + @Test(groups = {"wso2.am"}, description = "Update LLM Provider", + dependsOnMethods = "addCustomLLMProvider") + public void updateCustomLLMProvider() throws Exception { + + String originalDefinition = readFile(resourcePath + apiDefinitionFileName); + File file = getTempFileWithContent(originalDefinition); + + ApiResponse updateProviderResponse = restAPIAdmin.updateLLMProvider(llmProviderId, + llmProviderName, llmProviderApiVersion, llmProviderDescription, + correctLlmProviderConfigurations, file); + + assertEquals(Response.Status.OK.getStatusCode(), + updateProviderResponse.getStatusCode(), "Failed to update LLM provider"); + + ApiResponse getProviderResponse = restAPIAdmin.getLLMProvider(llmProviderId); + assertEquals(Response.Status.OK.getStatusCode(), + getProviderResponse.getStatusCode(), "Failed to retrieve LLM provider"); + assertEquals(getProviderResponse.getData().getConfigurations(), + correctLlmProviderConfigurations, "Failed to update LLM provider configurations"); + } + /** * Test Mistral AI API creation, deployment, and publishing */ - @Test(groups = { "wso2.am" }, description = "Test Mistral AI API creation, deployment and publishing") + @Test(groups = {"wso2.am"}, description = "Test Mistral AI API creation, deployment and publishing", + dependsOnMethods = "updateCustomLLMProvider") public void testMistralAIAPICreationAndPublish() throws Exception { - String originalDefinition = readFile(resourcePath + "mistral-def.json"); + + String originalDefinition = readFile(resourcePath + apiDefinitionFileName); String additionalProperties = readFile(resourcePath + "mistral-add-props.json"); JSONObject additionalPropertiesObj = new JSONObject(additionalProperties); @@ -162,7 +285,7 @@ public void testMistralAIAPICreationAndPublish() throws Exception { /** * Test Mistral AI API invocation */ - @Test(groups = { "wso2.am" }, description = "Test AI API invocation", + @Test(groups = {"wso2.am"}, description = "Test AI API invocation", dependsOnMethods = "testMistralAIAPICreationAndPublish") public void testMistralAIApiInvocation() throws Exception { @@ -191,17 +314,43 @@ public void testMistralAIApiInvocation() throws Exception { assertEquals(mistralResponse, serviceResponse.getData(), "Mistral AI API response mismatch"); } + /** + * Deletes a specified LLM provider after removing API subscriptions and applications. + * Verifies that the provider is successfully deleted and no longer listed. + */ + @Test(groups = {"wso2.am"}, description = "Delete LLM Provider", + dependsOnMethods = "testMistralAIApiInvocation") + public void deleteLLMProvider() throws Exception { + + restAPIStore.removeAPISubscriptionByName(mistralAPIName, mistralAPIVersion, apiProvider, applicationName); + restAPIStore.deleteApplication(applicationId); + restAPIPublisher.deleteAPI(mistralAPIId); + + ApiResponse deleteProviderResponse = restAPIAdmin.deleteLLMProvider(llmProviderId); + assertEquals(Response.Status.OK.getStatusCode(), + deleteProviderResponse.getStatusCode(), "Failed to delete LLM provider"); + + ApiResponse llmProviders = restAPIAdmin.getLLMProviders(); + assertEquals(Response.Status.OK.getStatusCode(), + llmProviders.getStatusCode(), "Failed to retrieve LLM providers"); + for (LLMProviderSummaryResponseDTO provider : llmProviders.getData().getList()) { + if (provider.getName().equals(llmProviderName)) { + Assert.fail("LLM Provider " + llmProviderName + " has not deleted correctly"); + } + } + + } + @AfterClass(alwaysRun = true) public void destroyAPIs() throws Exception { + if (wireMockServer != null) { wireMockServer.stop(); } - restAPIStore.removeAPISubscriptionByName(mistralAPIName, mistralAPIVersion, apiProvider, applicationName); - restAPIStore.deleteApplication(applicationId); - restAPIPublisher.deleteAPI(mistralAPIId); } private File getTempFileWithContent(String content) throws IOException { + File temp = File.createTempFile("swagger", ".json"); try (BufferedWriter out = new BufferedWriter(new FileWriter(temp))) { out.write(content); @@ -211,6 +360,7 @@ private File getTempFileWithContent(String content) throws IOException { } private void startWiremockServer() throws Exception { + endpointPort = getAvailablePort(); wireMockServer = new WireMockServer(options().port(endpointPort)); @@ -222,13 +372,13 @@ private void startWiremockServer() throws Exception { log.info("Wiremock server started on port " + endpointPort); } - /** * Find a free port to start backend WebSocket server in given port range * * @return Available Port Number */ private int getAvailablePort() { + while (lowerPortLimit < upperPortLimit) { if (isPortFree(lowerPortLimit)) { return lowerPortLimit; @@ -245,6 +395,7 @@ private int getAvailablePort() { * @return status */ private boolean isPortFree(int port) { + Socket s = null; try { s = new Socket(endpointHost, port); diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/ai-api/mistral-add-props.json b/modules/integration/tests-integration/tests-backend/src/test/resources/ai-api/mistral-add-props.json index 3540da4073..f750df0299 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/ai-api/mistral-add-props.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/ai-api/mistral-add-props.json @@ -40,7 +40,7 @@ "subtypeConfiguration": { "subtype": "AIAPI", "configuration": { - "llmProviderName": "MistralAI", + "llmProviderName": "TestAIService", "llmProviderApiVersion": "1.0.0" } },