Skip to content

Commit 01486c8

Browse files
authored
feat: add a new genai locator module (#298)
* chore: support the new genai endpoint format * feat: add a new genai locator module * chore: adding tests to mock out calls to config endpoin * chore: correct the parameter passing of properties
1 parent d248e5c commit 01486c8

16 files changed

Lines changed: 830 additions & 1 deletion

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ buildscript {
22
ext {
33
jmockitVersion = "1.49"
44
springBootVersion = "3.4.3"
5+
springAiVersion = "1.0.0"
56
}
67
}
78

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.parallel=true
22

33
group=io.pivotal.cfenv
4-
version=3.4.0-SNAPSHOT
4+
version=3.5.0-SNAPSHOT
55
onlyShowStandardStreamsOnTestFailure=false
66

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Tanzu GenAI support
2+
3+
This library is for use when accessing a Tanzu GenAI tile (version >= 10.2) configured plan with CF. This library uses the `VCAP_SERVICES` environment data to set properties that will enable a GenAILocator.
4+
5+
## Spring Applications
6+
7+
Spring Applications can use this library to auto-configure a GenAILocator that can be used to determine which models/mcp servers are available, what capabilities they support and a method of accessing them.
8+
9+
This service provides the following properties to your spring application:
10+
11+
| Property Name | Value |
12+
|--------------------------|---------------------------------|
13+
| genai.locator.config-url | config_url (from VCAP_SERVICES) |
14+
| genai.locator.api-base | api_base (from VCAP_SERVICES) |
15+
| genai.locator.api-key | api_key (from VCAP_SERVICES) |
16+
17+
Please see the Sample Apps below for more information.
18+
19+
### Sample Apps
20+
21+
Sample apps using this library are available at TODO.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id 'io.pivotal.cfenv.java-conventions'
3+
}
4+
5+
description = 'Java CF Env Tanzu GenAI'
6+
7+
dependencies {
8+
api project(':java-cfenv-boot')
9+
api "org.springframework.ai:spring-ai-openai:${springAiVersion}"
10+
implementation("org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}")
11+
12+
testImplementation project(':java-cfenv-test-support')
13+
testImplementation "junit:junit"
14+
testImplementation "org.jmockit:jmockit:${jmockitVersion}"
15+
16+
testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
17+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
18+
}
19+
}
20+
21+
tasks.named('jar') {
22+
manifest {
23+
attributes 'Automatic-Module-Name': 'io.pivotal.cfenv.boot.genai'
24+
}
25+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.pivotal.cfenv.boot.genai;
17+
18+
import java.util.Map;
19+
20+
import io.pivotal.cfenv.core.CfCredentials;
21+
import io.pivotal.cfenv.core.CfService;
22+
import io.pivotal.cfenv.spring.boot.CfEnvProcessor;
23+
import io.pivotal.cfenv.spring.boot.CfEnvProcessorProperties;
24+
25+
/**
26+
* Retrieve GenAI on Tanzu Platform properties from {@link CfCredentials} and
27+
* set {@literal genai.locator.*} Boot properties.
28+
*
29+
* @author Gareth Evans
30+
**/
31+
public class CfGenaiProcessor implements CfEnvProcessor {
32+
33+
@Override
34+
public boolean accept(CfService service) {
35+
boolean isGenAIService = service.existsByTagIgnoreCase("genai") || service.existsByLabelStartsWith("genai");
36+
// we only want to process service instances that are generated from Tanzu Platform 10.2 or later
37+
return (isGenAIService && service.getCredentials().getMap().containsKey("endpoint"));
38+
}
39+
40+
@Override
41+
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
42+
Map<String, Object> endpoint = (Map<String, Object>)cfCredentials.getMap().get("endpoint");
43+
44+
properties.put("genai.locator.config-url", endpoint.get("config_url"));
45+
properties.put("genai.locator.api-key", endpoint.get("api_key"));
46+
properties.put("genai.locator.api-base", endpoint.get( "api_base"));
47+
}
48+
49+
@Override
50+
public CfEnvProcessorProperties getProperties() {
51+
return CfEnvProcessorProperties.builder()
52+
.propertyPrefixes("genai.locator")
53+
.serviceName("Tanzu GenAI Locator").build();
54+
}
55+
}

0 commit comments

Comments
 (0)