Skip to content

Commit 40a34bf

Browse files
authored
feat: Pass X-UPSTREAM-ENDPOINT header to the chat completion feature endpoints #1340 (#1347)
1 parent 0308574 commit 40a34bf

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

server/src/main/java/com/epam/aidial/core/server/controller/DeploymentFeatureController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.epam.aidial.core.config.Application;
44
import com.epam.aidial.core.config.Deployment;
5+
import com.epam.aidial.core.config.Model;
6+
import com.epam.aidial.core.config.Upstream;
57
import com.epam.aidial.core.server.Proxy;
68
import com.epam.aidial.core.server.ProxyContext;
79
import com.epam.aidial.core.server.data.ApiKeyData;
@@ -191,6 +193,11 @@ void handleProxyRequest(HttpClientRequest proxyRequest) {
191193
ApiKeyData proxyApiKeyData = context.getProxyApiKeyData();
192194
proxyRequest.headers().add(Proxy.HEADER_API_KEY, proxyApiKeyData.getPerRequestKey());
193195

196+
if (deployment instanceof Model model && !model.getUpstreams().isEmpty()) {
197+
Upstream upstream = model.getUpstreams().getFirst();
198+
proxyRequest.putHeader(Proxy.HEADER_UPSTREAM_ENDPOINT, upstream.getEndpoint());
199+
}
200+
194201
Buffer requestBody = context.getRequestBody();
195202
proxyRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(requestBody.length()));
196203
context.getRequestHeaders().forEach(proxyRequest::putHeader);

server/src/test/java/com/epam/aidial/core/server/FeaturesApiTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.stream.Stream;
1616
import java.util.stream.StreamSupport;
1717

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
1820
public class FeaturesApiTest extends ResourceBaseTest {
1921

2022
private static String[] convertHeadersToFlatArray(Headers headers) {
@@ -50,6 +52,13 @@ void testRateEndpointModel() {
5052
testUpstreamEndpoint(inboundPath, upstream, HttpMethod.POST, body);
5153
}
5254

55+
@Test
56+
void testConfigurationEndpointModel() {
57+
String inboundPath = "/v1/deployments/chat-gpt-35-turbo/configuration";
58+
String upstream = "http://localhost:7001/upstream/v1/deployments/gpt-35-turbo/model_config";
59+
testUpstreamEndpoint(inboundPath, upstream, HttpMethod.GET);
60+
}
61+
5362
@Test
5463
void testRateEndpointApplication() {
5564
String inboundPath = "/v1/app/rate";
@@ -102,7 +111,11 @@ void testUpstreamEndpoint(String inboundPath, String upstream, HttpMethod method
102111
try (TestWebServer server = new TestWebServer(uri.getPort())) {
103112
server.map(method, uri.getPath(), request -> {
104113
Headers responseHeaders = filterHeaders(request.getHeaders(), requestExtraHeaders);
105-
if (request.getPath().endsWith("rate_response")) {
114+
String path = request.getPath();
115+
if (path.endsWith("model_config")) {
116+
assertEquals("http://localhost:7001", request.getHeader(Proxy.HEADER_UPSTREAM_ENDPOINT));
117+
}
118+
if (path.endsWith("rate_response")) {
106119
return handleRateResponse(request, responseHeaders);
107120
} else {
108121
return TestWebServer.createResponse(200, "PONG", convertHeadersToFlatArray(responseHeaders));

server/src/test/java/com/epam/aidial/core/server/ListingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void testFeaturesModel(Vertx vertx, VertxTestContext context) {
6565
{ "rate": true, "tokenize": true, "truncate_prompt": true
6666
, "system_prompt": true, "tools": true, "seed": true
6767
, "url_attachments": true, "folder_attachments": false
68-
, "configuration": false, "allow_resume": true, "accessible_by_per_request_key": true,
68+
, "configuration": true, "allow_resume": true, "accessible_by_per_request_key": true,
6969
"content_parts": false, "temperature" : true, "cache" : false,
7070
"auto_caching" : false, "parallel_tool_calls": true,
7171
"assistant_attachments_in_request": false

server/src/test/resources/aidial.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
{"endpoint": "http://localhost:7003", "key": "modelKey3"}
139139
],
140140
"features": {
141+
"configurationEndpoint": "http://localhost:7001/upstream/v1/deployments/gpt-35-turbo/model_config",
141142
"rateEndpoint": "http://localhost:7001/upstream/v1/deployments/gpt-35-turbo/rate_response",
142143
"tokenizeEndpoint": "http://localhost:7001/upstream/v1/deployments/gpt-35-turbo/tokenizer",
143144
"truncatePromptEndpoint": "http://localhost:7001/upstream/v1/deployments/gpt-35-turbo/trim_history",

0 commit comments

Comments
 (0)