Skip to content

chore: make the genai processor more lenient against the new endpoint format #297

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

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author Stuart Charlton
* @author Ed King
* @author Gareth Evans
**/
public class GenAIChatCfEnvProcessor implements CfEnvProcessor {

Expand All @@ -36,7 +37,7 @@ public boolean accept(CfService service) {
boolean isGenAIService = service.existsByTagIgnoreCase("genai") || service.existsByLabelStartsWith("genai");
if (isGenAIService) {
ArrayList<String> modelCapabilities = (ArrayList<String>) service.getCredentials().getMap().get("model_capabilities");
return modelCapabilities.contains("chat");
return (modelCapabilities != null && modelCapabilities.contains("chat"));
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author Stuart Charlton
* @author Ed King
* @author Gareth Evans
**/
public class GenAIEmbeddingCfEnvProcessor implements CfEnvProcessor {

Expand All @@ -36,7 +37,7 @@ public boolean accept(CfService service) {
boolean isGenAIService = service.existsByTagIgnoreCase("genai") || service.existsByLabelStartsWith("genai");
if (isGenAIService) {
ArrayList<String> modelCapabilities = (ArrayList<String>) service.getCredentials().getMap().get("model_capabilities");
return modelCapabilities.contains("embedding");
return (modelCapabilities != null && modelCapabilities.contains("embedding"));
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* @author Stuart Charlton
* @author Ed King
* @author Gareth Evans
*/
public class GenAIChatCfEnvProcessorTests extends AbstractCfEnvTests {

Expand All @@ -48,4 +49,21 @@ public void testGenAIBootPropertiesWithChatModelCapability() {
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.transcription.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.speech.options.model")).isNull();
}

@Test
public void testGenAIBootPropertiesWithChatModelCapabilityEndpointFormat() {
String TEST_GENAI_JSON_FILE = "test-genai-endpoint-chat-model.json";

mockVcapServices(getServicesPayload(readTestDataFile(TEST_GENAI_JSON_FILE)));

assertThat(getEnvironment().getProperty("spring.ai.openai.api-key")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.chat.base-url")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.chat.api-key")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.chat.options.model")).isNull();

assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.image.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.transcription.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.speech.options.model")).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* @author Stuart Charlton
* @author Ed King
* @author Gareth Evans
*/
public class GenAIEmbeddingCfEnvProcessorTests extends AbstractCfEnvTests {

Expand All @@ -48,4 +49,22 @@ public void testGenAIBootPropertiesWithEmbeddingModelCapability() {
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.transcription.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.speech.options.model")).isNull();
}

@Test
public void testGenAIBootPropertiesWithEmbeddingModelCapabilityEndpointFormat() {
String TEST_GENAI_JSON_FILE = "test-genai-endpoint-embedding-model.json";

mockVcapServices(getServicesPayload(readTestDataFile(TEST_GENAI_JSON_FILE)));

assertThat(getEnvironment().getProperty("spring.ai.openai.api-key")).isNull();

assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.base-url")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.api-key")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.options.model")).isNull();

assertThat(getEnvironment().getProperty("spring.ai.openai.chat.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.image.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.transcription.options.model")).isNull();
assertThat(getEnvironment().getProperty("spring.ai.openai.audio.speech.options.model")).isNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"credentials": {
"endpoint": {
"api_base": "https://genai-proxy.tpcf.io/test",
"api_key": "sk-KW5kiNOKDd_1dFxsAjpVa",
"config_url": "https://genai-proxy.tpcf.io/test/config/v1/endpoint"
}
},
"instance_name": "genai",
"label": "genai",
"name": "genai",
"plan": "meta-llama/Meta-Llama-3-8B",
"provider": null,
"syslog_drain_url": null,
"tags": [
"genai",
"llm"
],
"volume_mounts": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"credentials": {
"endpoint": {
"api_base": "https://genai-proxy.tpcf.io/test",
"api_key": "sk-KW5kiNOKDd_1dFxsAjpVa",
"config_url": "https://genai-proxy.tpcf.io/test/config/v1/endpoint"
}
},
"instance_name": "genai",
"label": "genai",
"name": "genai",
"plan": "mixedbread-ai/mxbai-embed-large-v1",
"provider": null,
"syslog_drain_url": null,
"tags": [
"genai",
"llm"
],
"volume_mounts": []
}