Skip to content

feat: add a new genai locator module #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ buildscript {
ext {
jmockitVersion = "1.49"
springBootVersion = "3.4.3"
springAiVersion = "1.0.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.parallel=true

group=io.pivotal.cfenv
version=3.4.0-SNAPSHOT
version=3.5.0-SNAPSHOT
onlyShowStandardStreamsOnTestFailure=false

21 changes: 21 additions & 0 deletions java-cfenv-boot-tanzu-genai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Tanzu GenAI support

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.

## Spring Applications

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.

This service provides the following properties to your spring application:

| Property Name | Value |
|--------------------------|---------------------------------|
| genai.locator.config-url | config_url (from VCAP_SERVICES) |
| genai.locator.api-base | api_base (from VCAP_SERVICES) |
| genai.locator.api-key | api_key (from VCAP_SERVICES) |

Please see the Sample Apps below for more information.

### Sample Apps

Sample apps using this library are available at TODO.
25 changes: 25 additions & 0 deletions java-cfenv-boot-tanzu-genai/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id 'io.pivotal.cfenv.java-conventions'
}

description = 'Java CF Env Tanzu GenAI'

dependencies {
api project(':java-cfenv-boot')
api "org.springframework.ai:spring-ai-openai:${springAiVersion}"
implementation("org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}")

testImplementation project(':java-cfenv-test-support')
testImplementation "junit:junit"
testImplementation "org.jmockit:jmockit:${jmockitVersion}"

testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
}

tasks.named('jar') {
manifest {
attributes 'Automatic-Module-Name': 'io.pivotal.cfenv.boot.genai'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.pivotal.cfenv.boot.genai;

import java.util.Map;

import io.pivotal.cfenv.core.CfCredentials;
import io.pivotal.cfenv.core.CfService;
import io.pivotal.cfenv.spring.boot.CfEnvProcessor;
import io.pivotal.cfenv.spring.boot.CfEnvProcessorProperties;

/**
* Retrieve GenAI on Tanzu Platform properties from {@link CfCredentials} and
* set {@literal genai.locator.*} Boot properties.
*
* @author Gareth Evans
**/
public class CfGenaiProcessor implements CfEnvProcessor {

@Override
public boolean accept(CfService service) {
boolean isGenAIService = service.existsByTagIgnoreCase("genai") || service.existsByLabelStartsWith("genai");
// we only want to process service instances that are generated from Tanzu Platform 10.2 or later
return (isGenAIService && service.getCredentials().getMap().containsKey("endpoint"));
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
Map<String, Object> endpoint = (Map<String, Object>)cfCredentials.getMap().get("endpoint");

properties.put("genai.locator.config-url", endpoint.get("config_url"));
properties.put("genai.locator.api-key", endpoint.get("api_key"));
properties.put("genai.locator.api-base", endpoint.get( "api_base"));
}

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder()
.propertyPrefixes("genai.locator")
.serviceName("Tanzu GenAI Locator").build();
}
}
Loading