chore: set cs env for appsmith-ai plugin (#40336)
## Description > Set CS env in Appsmith AI Plugin Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/14590322409> > Commit: 0944d9caff3638d6c19ec147eed0c7fd62716ff9 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14590322409&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 22 Apr 2025 09:46:25 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for configuring the AI proxy base path URL, allowing more flexible integration with AI services. - **Refactor** - Updated internal logic to construct AI service request URLs dynamically based on the configured base path, improving adaptability to different deployment environments. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
This commit is contained in:
parent
988537f805
commit
ddc0777038
|
|
@ -7,4 +7,8 @@ public interface SharedConfigCE {
|
|||
int getMaxResponseSize();
|
||||
|
||||
String getRemoteExecutionUrl();
|
||||
|
||||
default String getAIProxyBasePathUrl() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,9 +52,10 @@ public class AppsmithAiPlugin extends BasePlugin {
|
|||
}
|
||||
|
||||
public static class AppsmithAiPluginExecutor extends BaseRestApiPluginExecutor {
|
||||
private static final AiServerService aiServerService = new AiServerServiceImpl();
|
||||
private final AiServerService aiServerService =
|
||||
new AiServerServiceImpl(this.sharedConfig.getAIProxyBasePathUrl());
|
||||
|
||||
private static final TriggerService triggerService = new TriggerServiceImpl(aiServerService, objectMapper);
|
||||
private final TriggerService triggerService = new TriggerServiceImpl(aiServerService, objectMapper);
|
||||
private static final Gson gson = new GsonBuilder().create();
|
||||
|
||||
public AppsmithAiPluginExecutor(SharedConfig config) {
|
||||
|
|
@ -124,7 +125,10 @@ public class AppsmithAiPlugin extends BasePlugin {
|
|||
AiServerRequestDTO aiServerRequestDTO = new AiServerRequestDTO(feature, query);
|
||||
|
||||
ActionExecutionRequest actionExecutionRequest = RequestCaptureFilter.populateRequestFields(
|
||||
actionConfiguration, RequestUtils.getQueryUri(), insertedParams, objectMapper);
|
||||
actionConfiguration,
|
||||
RequestUtils.getQueryUri(this.sharedConfig.getAIProxyBasePathUrl()),
|
||||
insertedParams,
|
||||
objectMapper);
|
||||
|
||||
SourceDetails sourceDetails = SourceDetails.createSourceDetails(executeActionDTO);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
|||
|
||||
public class AppsmithAiConstants {
|
||||
public static final String USECASE = "usecase";
|
||||
public static final String AI_SERVER_HOST = "https://cs.appsmith.com/api/v1/proxy";
|
||||
public static final String AI_PROXY_BASE_PATH = "/api/v1/proxy";
|
||||
public static final String ASSISTANT_PATH = "/assistant";
|
||||
public static final String QUERY_PATH = ASSISTANT_PATH + "/query";
|
||||
public static final String ASSOCIATE_PATH = ASSISTANT_PATH + "/files/datasource";
|
||||
|
|
|
|||
|
|
@ -27,10 +27,15 @@ import static com.external.plugins.constants.AppsmithAiConstants.SOURCE_DETAILS;
|
|||
|
||||
public class AiServerServiceImpl implements AiServerService {
|
||||
private final Gson gson = new GsonBuilder().create();
|
||||
private final String aiChatAssistantBaseUrl;
|
||||
|
||||
public AiServerServiceImpl(String aiChatAssistantBaseUrl) {
|
||||
this.aiChatAssistantBaseUrl = aiChatAssistantBaseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> associateDatasource(AssociateDTO associateDTO) {
|
||||
URI uri = RequestUtils.getAssociateUri();
|
||||
URI uri = RequestUtils.getAssociateUri(this.aiChatAssistantBaseUrl);
|
||||
String jsonBody = gson.toJson(associateDTO);
|
||||
|
||||
return RequestUtils.makeRequest(
|
||||
|
|
@ -45,7 +50,7 @@ public class AiServerServiceImpl implements AiServerService {
|
|||
|
||||
@Override
|
||||
public Mono<Void> disassociateDatasource(AssociateDTO associateDTO) {
|
||||
URI uri = RequestUtils.getAssociateUri();
|
||||
URI uri = RequestUtils.getAssociateUri(this.aiChatAssistantBaseUrl);
|
||||
String jsonBody = gson.toJson(associateDTO);
|
||||
|
||||
return RequestUtils.makeRequest(
|
||||
|
|
@ -67,7 +72,7 @@ public class AiServerServiceImpl implements AiServerService {
|
|||
|
||||
return RequestUtils.makeRequest(
|
||||
HttpMethod.POST,
|
||||
RequestUtils.getFileStatusUri(),
|
||||
RequestUtils.getFileStatusUri(this.aiChatAssistantBaseUrl),
|
||||
MediaType.APPLICATION_JSON,
|
||||
createSourceDetailsHeader(sourceDetails),
|
||||
BodyInserters.fromValue(jsonBody))
|
||||
|
|
@ -79,7 +84,7 @@ public class AiServerServiceImpl implements AiServerService {
|
|||
public Mono<Object> uploadFiles(List<FilePart> fileParts, SourceDetails sourceDetails) {
|
||||
return RequestUtils.makeRequest(
|
||||
HttpMethod.POST,
|
||||
RequestUtils.getFileUploadUri(),
|
||||
RequestUtils.getFileUploadUri(this.aiChatAssistantBaseUrl),
|
||||
createSourceDetailsHeader(sourceDetails),
|
||||
fileParts)
|
||||
.flatMap(RequestUtils::handleResponse);
|
||||
|
|
@ -87,7 +92,7 @@ public class AiServerServiceImpl implements AiServerService {
|
|||
|
||||
@Override
|
||||
public Mono<Object> executeQuery(AiServerRequestDTO aiServerRequestDTO, SourceDetails sourceDetails) {
|
||||
URI uri = RequestUtils.getQueryUri();
|
||||
URI uri = getUriForFeature(aiServerRequestDTO);
|
||||
String jsonBody = gson.toJson(aiServerRequestDTO);
|
||||
return RequestUtils.makeRequest(
|
||||
HttpMethod.POST,
|
||||
|
|
@ -103,4 +108,8 @@ public class AiServerServiceImpl implements AiServerService {
|
|||
headers.put(SOURCE_DETAILS, HeadersUtil.createSourceDetailsHeader(sourceDetails));
|
||||
return headers;
|
||||
}
|
||||
|
||||
private URI getUriForFeature(AiServerRequestDTO aiServerRequestDTO) {
|
||||
return RequestUtils.getQueryUri(this.aiChatAssistantBaseUrl);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.time.Duration;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.external.plugins.constants.AppsmithAiConstants.AI_SERVER_HOST;
|
||||
import static com.external.plugins.constants.AppsmithAiConstants.AI_PROXY_BASE_PATH;
|
||||
import static com.external.plugins.constants.AppsmithAiConstants.ASSOCIATE_PATH;
|
||||
import static com.external.plugins.constants.AppsmithAiConstants.DATA;
|
||||
import static com.external.plugins.constants.AppsmithAiConstants.EXCHANGE_STRATEGIES;
|
||||
|
|
@ -48,20 +48,20 @@ public class RequestUtils {
|
|||
return (String) formData.get(key);
|
||||
}
|
||||
|
||||
public static URI getQueryUri() {
|
||||
return URI.create(AI_SERVER_HOST + QUERY_PATH);
|
||||
public static URI getQueryUri(String aiChatAssistantUri) {
|
||||
return URI.create(aiChatAssistantUri + AI_PROXY_BASE_PATH + QUERY_PATH);
|
||||
}
|
||||
|
||||
public static URI getAssociateUri() {
|
||||
return URI.create(AI_SERVER_HOST + ASSOCIATE_PATH);
|
||||
public static URI getAssociateUri(String aiChatAssistantUri) {
|
||||
return URI.create(aiChatAssistantUri + AI_PROXY_BASE_PATH + ASSOCIATE_PATH);
|
||||
}
|
||||
|
||||
public static URI getFileUploadUri() {
|
||||
return URI.create(AI_SERVER_HOST + FILE_PATH);
|
||||
public static URI getFileUploadUri(String aiChatAssistantUri) {
|
||||
return URI.create(aiChatAssistantUri + AI_PROXY_BASE_PATH + FILE_PATH);
|
||||
}
|
||||
|
||||
public static URI getFileStatusUri() {
|
||||
return URI.create(AI_SERVER_HOST + FILES_STATUS_PATH);
|
||||
public static URI getFileStatusUri(String aiChatAssistantUri) {
|
||||
return URI.create(aiChatAssistantUri + AI_PROXY_BASE_PATH + FILES_STATUS_PATH);
|
||||
}
|
||||
|
||||
public static Mono<ResponseEntity<byte[]>> makeRequest(
|
||||
|
|
|
|||
|
|
@ -33,4 +33,9 @@ public class SharedConfigImpl implements SharedConfig {
|
|||
public String getRemoteExecutionUrl() {
|
||||
return cloudServicesConfig.getBaseUrl() + "/api/v1/actions/execute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAIProxyBasePathUrl() {
|
||||
return cloudServicesConfig.getBaseUrl();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user