-
Notifications
You must be signed in to change notification settings - Fork 62
Incorporate model capabilities into GenAICfEnvProcessor #273
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
anthonydahanne
merged 2 commits into
pivotal-cf:main
from
teddyking:genai-model-capabilities
Aug 14, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
java-cfenv-boot/src/main/java/io/pivotal/cfenv/spring/boot/GenAIEmbeddingCfEnvProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright 2024 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.spring.boot; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Map; | ||
|
|
||
| import io.pivotal.cfenv.core.CfCredentials; | ||
| import io.pivotal.cfenv.core.CfService; | ||
|
|
||
| /** | ||
| * Retrieve GenAI on Tanzu Platform properties from {@link CfCredentials} and | ||
| * set {@literal spring.ai.openai.embedding} | ||
| * Boot properties. | ||
| * | ||
| * @author Stuart Charlton | ||
| * @author Ed King | ||
| **/ | ||
| public class GenAIEmbeddingCfEnvProcessor implements CfEnvProcessor { | ||
|
|
||
| @Override | ||
| 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 false; | ||
| } | ||
|
|
||
| @Override | ||
| public void process(CfCredentials cfCredentials, Map<String, Object> properties) { | ||
| properties.put("spring.ai.openai.api-key", "redundant"); | ||
|
|
||
| properties.put("spring.ai.openai.embedding.base-url", cfCredentials.getString("api_base")); | ||
| properties.put("spring.ai.openai.embedding.api-key", cfCredentials.getString("api_key")); | ||
| properties.put("spring.ai.openai.embedding.options.model", cfCredentials.getString("model_name")); | ||
| } | ||
|
|
||
| @Override | ||
| public CfEnvProcessorProperties getProperties() { | ||
| return CfEnvProcessorProperties.builder() | ||
| .propertyPrefixes("spring.ai.openai.embedding") | ||
| .serviceName("GenAI on Tanzu Platform (embedding)") | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
java-cfenv-boot/src/test/java/io/pivotal/cfenv/spring/boot/GenAICfEnvProcessorTests.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
java-cfenv-boot/src/test/java/io/pivotal/cfenv/spring/boot/GenAIChatCfEnvProcessorTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright 2024 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.spring.boot; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import io.pivotal.cfenv.test.AbstractCfEnvTests; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * @author Stuart Charlton | ||
| * @author Ed King | ||
| */ | ||
| public class GenAIChatCfEnvProcessorTests extends AbstractCfEnvTests { | ||
|
|
||
| @Test | ||
| public void testGenAIBootPropertiesWithChatModelCapability() { | ||
| String TEST_GENAI_JSON_FILE = "test-genai-chat-model.json"; | ||
|
|
||
| String EXPECTED_URI_FROM_JSON_FILE = "https://genai-proxy.tpcf.io"; | ||
| String EXPECTED_TOKEN_FROM_JSON_FILE = "sk-KW5kiNOKDd_1dFxsAjpVa"; | ||
| String EXPECTED_MODEL_FROM_JSON_FILE = "meta-llama/Meta-Llama-3-8B"; | ||
|
|
||
| mockVcapServices(getServicesPayload(readTestDataFile(TEST_GENAI_JSON_FILE))); | ||
|
|
||
| assertThat(getEnvironment().getProperty("spring.ai.openai.api-key")).isEqualTo("redundant"); | ||
|
|
||
| assertThat(getEnvironment().getProperty("spring.ai.openai.chat.base-url")).isEqualTo(EXPECTED_URI_FROM_JSON_FILE); | ||
| assertThat(getEnvironment().getProperty("spring.ai.openai.chat.api-key")).isEqualTo(EXPECTED_TOKEN_FROM_JSON_FILE); | ||
| assertThat(getEnvironment().getProperty("spring.ai.openai.chat.options.model")).isEqualTo(EXPECTED_MODEL_FROM_JSON_FILE); | ||
|
|
||
| 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(); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...nv-boot/src/test/java/io/pivotal/cfenv/spring/boot/GenAIEmbeddingCfEnvProcessorTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright 2024 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.spring.boot; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import io.pivotal.cfenv.test.AbstractCfEnvTests; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * @author Stuart Charlton | ||
| * @author Ed King | ||
| */ | ||
| public class GenAIEmbeddingCfEnvProcessorTests extends AbstractCfEnvTests { | ||
|
|
||
| @Test | ||
| public void testGenAIBootPropertiesWithEmbeddingModelCapability() { | ||
| String TEST_GENAI_JSON_FILE = "test-genai-embedding-model.json"; | ||
|
|
||
| String EXPECTED_URI_FROM_JSON_FILE = "https://genai-proxy.tpcf.io"; | ||
| String EXPECTED_TOKEN_FROM_JSON_FILE = "sk-KW5kiNOKDd_1dFxsAjpVa"; | ||
| String EXPECTED_MODEL_FROM_JSON_FILE = "mixedbread-ai/mxbai-embed-large-v1"; | ||
|
|
||
| mockVcapServices(getServicesPayload(readTestDataFile(TEST_GENAI_JSON_FILE))); | ||
|
|
||
| assertThat(getEnvironment().getProperty("spring.ai.openai.api-key")).isEqualTo("redundant"); | ||
|
|
||
| assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.base-url")).isEqualTo(EXPECTED_URI_FROM_JSON_FILE); | ||
| assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.api-key")).isEqualTo(EXPECTED_TOKEN_FROM_JSON_FILE); | ||
| assertThat(getEnvironment().getProperty("spring.ai.openai.embedding.options.model")).isEqualTo(EXPECTED_MODEL_FROM_JSON_FILE); | ||
|
|
||
| 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(); | ||
| } | ||
| } |
14 changes: 11 additions & 3 deletions
14
...al/cfenv/spring/boot/test-genai-info.json → ...nv/spring/boot/test-genai-chat-model.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,25 @@ | ||
| { | ||
| "credentials": { | ||
| "api_base": "https://genai-proxy.tpcf.io", | ||
| "api_key": "sk-KW5kiNOKDd_1dFxsAjpVa" | ||
| "api_key": "sk-KW5kiNOKDd_1dFxsAjpVa", | ||
| "model_name": "meta-llama/Meta-Llama-3-8B", | ||
| "model_aliases": [ | ||
| "llama3" | ||
| ], | ||
| "model_capabilities": [ | ||
| "chat", | ||
| "tools" | ||
| ] | ||
| }, | ||
| "instance_name": "genai", | ||
| "label": "genai", | ||
| "name": "genai", | ||
| "plan": "shared", | ||
| "plan": "meta-llama/Meta-Llama-3-8B", | ||
| "provider": null, | ||
| "syslog_drain_url": null, | ||
| "tags": [ | ||
| "genai", | ||
| "llm" | ||
| ], | ||
| "volume_mounts": [] | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...fenv-boot/src/test/resources/io/pivotal/cfenv/spring/boot/test-genai-embedding-model.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "credentials": { | ||
| "api_base": "https://genai-proxy.tpcf.io", | ||
| "api_key": "sk-KW5kiNOKDd_1dFxsAjpVa", | ||
| "model_name": "mixedbread-ai/mxbai-embed-large-v1", | ||
| "model_aliases": [ | ||
| "mxbai" | ||
| ], | ||
| "model_capabilities": [ | ||
| "embedding" | ||
| ] | ||
| }, | ||
| "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": [] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.