You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
At packages/core/src/generate.ts When the imageModelProvider did not match modelProvider, the code iteratively checked for API keys in a fallback chain. It stopped at the first available key (e.g., FAL_API_KEY), even if it belonged to the wrong provider. As a result, the selected API key could be incorrect (e.g., returning and using a key from FAL instead key from Venice).
To Reproduce
Set imageModelProvider to VENICE in the character configuration.
Provide both FAL_API_KEY and VENICE_API_KEY in .env(or any other relevant key combination).
When requesting an image generation observe that the code selects FAL_API_KEY instead of VENICE_API_KEY.
Expected behavior
If a specific imageModelProvider is set, the code should return the matching API key for that provider if it exists. If no specific provider key is found, the code should then try the fallback chain in sequence.
Fix
const apiKey = runtime.imageModelProvider === runtime.modelProvider ? runtime.token : (() => { // First try to match the specific provider switch (runtime.imageModelProvider) { case ModelProviderName.HEURIST: return runtime.getSetting("HEURIST_API_KEY"); case ModelProviderName.TOGETHER: return runtime.getSetting("TOGETHER_API_KEY"); case ModelProviderName.FAL: return runtime.getSetting("FAL_API_KEY"); case ModelProviderName.OPENAI: return runtime.getSetting("OPENAI_API_KEY"); case ModelProviderName.VENICE: return runtime.getSetting("VENICE_API_KEY"); default: // If no specific match, try the fallback chain return (runtime.getSetting("HEURIST_API_KEY") ?? runtime.getSetting("TOGETHER_API_KEY") ?? runtime.getSetting("FAL_API_KEY") ?? runtime.getSetting("OPENAI_API_KEY") ?? runtime.getSetting("VENICE_API_KEY"); } })();
This fix updates the logic to first attempt to retrieve the API key from the specifically selected imageModelProvider. If that is not present, it will proceed down the fallback chain. This ensures that if an an image model api key is set, it is correctly chosen over other existing keys which are higher in the selection list, like FAL_API_KEY.
PS: Solution is implemented and tested, creating bug report for tracked pull request.
The text was updated successfully, but these errors were encountered:
Describe the bug
At packages/core/src/generate.ts When the
imageModelProvider
did not matchmodelProvider
, the code iteratively checked for API keys in a fallback chain. It stopped at the first available key (e.g., FAL_API_KEY), even if it belonged to the wrong provider. As a result, the selected API key could be incorrect (e.g., returning and using a key from FAL instead key from Venice).To Reproduce
Expected behavior
If a specific imageModelProvider is set, the code should return the matching API key for that provider if it exists. If no specific provider key is found, the code should then try the fallback chain in sequence.
Fix
const apiKey = runtime.imageModelProvider === runtime.modelProvider ? runtime.token : (() => { // First try to match the specific provider switch (runtime.imageModelProvider) { case ModelProviderName.HEURIST: return runtime.getSetting("HEURIST_API_KEY"); case ModelProviderName.TOGETHER: return runtime.getSetting("TOGETHER_API_KEY"); case ModelProviderName.FAL: return runtime.getSetting("FAL_API_KEY"); case ModelProviderName.OPENAI: return runtime.getSetting("OPENAI_API_KEY"); case ModelProviderName.VENICE: return runtime.getSetting("VENICE_API_KEY"); default: // If no specific match, try the fallback chain return (runtime.getSetting("HEURIST_API_KEY") ?? runtime.getSetting("TOGETHER_API_KEY") ?? runtime.getSetting("FAL_API_KEY") ?? runtime.getSetting("OPENAI_API_KEY") ?? runtime.getSetting("VENICE_API_KEY"); } })();
This fix updates the logic to first attempt to retrieve the API key from the specifically selected imageModelProvider. If that is not present, it will proceed down the fallback chain. This ensures that if an an image model api key is set, it is correctly chosen over other existing keys which are higher in the selection list, like FAL_API_KEY.
PS: Solution is implemented and tested, creating bug report for tracked pull request.
The text was updated successfully, but these errors were encountered: