-
Notifications
You must be signed in to change notification settings - Fork 63
chore: support the new genai 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
Open
garethjevans
wants to merge
1
commit into
pivotal-cf:main
Choose a base branch
from
garethjevans:support-new-endpoint-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -28,13 +28,18 @@ | |
* | ||
* @author Stuart Charlton | ||
* @author Ed King | ||
* @author Gareth Evans | ||
**/ | ||
public class GenAIEmbeddingCfEnvProcessor implements CfEnvProcessor { | ||
|
||
@Override | ||
public boolean accept(CfService service) { | ||
boolean isGenAIService = service.existsByTagIgnoreCase("genai") || service.existsByLabelStartsWith("genai"); | ||
if (isGenAIService) { | ||
boolean endpointFormat = service.getCredentials().getMap().containsKey("endpoint"); | ||
if (endpointFormat) { | ||
return true; | ||
} | ||
ArrayList<String> modelCapabilities = (ArrayList<String>) service.getCredentials().getMap().get("model_capabilities"); | ||
return modelCapabilities.contains("embedding"); | ||
} | ||
|
@@ -46,9 +51,17 @@ public boolean accept(CfService service) { | |
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")); | ||
boolean endpointFormat = cfCredentials.getMap().containsKey("endpoint"); | ||
if (endpointFormat) { | ||
Map<String, String> endpoint = (Map<String, String>)cfCredentials.getMap().get("endpoint"); | ||
properties.put("spring.ai.openai.embedding.base-url", endpoint.get("api_base") + "/openai"); | ||
properties.put("spring.ai.openai.embedding.api-key", endpoint.get("api_key")); | ||
properties.put("spring.ai.openai.embedding.options.model", "tanzu://embedding"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note as above, this will always try to configure an embedding model, even when there is none. |
||
} else { | ||
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 | ||
|
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
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
20 changes: 20 additions & 0 deletions
20
...-boot/src/test/resources/io/pivotal/cfenv/spring/boot/test-genai-endpoint-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 |
---|---|---|
@@ -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": [] | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/test/resources/io/pivotal/cfenv/spring/boot/test-genai-endpoint-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,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": [] | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this logic will always set the
spring.ai.openai.chat.*
properties for all bindings that contain theendpoint
key, even if there is no chat-capable model behind the endpoint? Is that a problem? I guess that if an app were to make a chat request, it would receive some sort of 404 model not found response, which maybe is fine?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this would only be an issue if the app / spring ai attempts to test connectivity to all configured models at startup 🤔