-
Notifications
You must be signed in to change notification settings - Fork 45.8k
feat(platform/backend): auto discover credentials in all block modules #10028
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
Closed
Swiftyos
wants to merge
3
commits into
dev
from
swiftyos/add-provider-metadata-and-update-credential-functions
Closed
Changes from all commits
Commits
Show all changes
3 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
Empty file.
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
Empty file.
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
Empty file.
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
Empty file.
Empty file.
Empty file.
Empty file.
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
Empty file.
Empty file.
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
Empty file.
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
Empty file.
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from typing import Type | ||
|
||
from pydantic import SecretStr | ||
|
||
from backend.blocks.ai_music_generator import AIMusicGeneratorBlock | ||
from backend.blocks.ai_shortform_video_block import AIShortformVideoCreatorBlock | ||
from backend.blocks.ideogram import IdeogramModelBlock | ||
|
@@ -20,19 +22,49 @@ | |
from backend.blocks.text_to_speech_block import UnrealTextToSpeechBlock | ||
from backend.data.block import Block | ||
from backend.data.cost import BlockCost, BlockCostType | ||
from backend.integrations.credentials_store import ( | ||
anthropic_credentials, | ||
did_credentials, | ||
groq_credentials, | ||
ideogram_credentials, | ||
jina_credentials, | ||
llama_api_credentials, | ||
open_router_credentials, | ||
openai_credentials, | ||
replicate_credentials, | ||
revid_credentials, | ||
unreal_credentials, | ||
from backend.data.model import APIKeyCredentials | ||
from backend.integrations.credentials_store import discover_default_credentials | ||
|
||
_DEFAULTS = {c.provider: c for c in discover_default_credentials()} | ||
|
||
|
||
def _fallback(provider: str) -> APIKeyCredentials: | ||
return APIKeyCredentials( | ||
id="", provider=provider, api_key=SecretStr(""), title="", expires_at=None | ||
) | ||
|
||
|
||
anthropic_credentials: APIKeyCredentials = _DEFAULTS.get("anthropic") or _fallback( | ||
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. This doesn’t do what we want. We should do this similar to getting avail blocks |
||
"anthropic" | ||
) | ||
did_credentials: APIKeyCredentials = _DEFAULTS.get("d_id") or _fallback("d_id") | ||
groq_credentials: APIKeyCredentials = _DEFAULTS.get("groq") or _fallback("groq") | ||
ideogram_credentials: APIKeyCredentials = _DEFAULTS.get("ideogram") or _fallback( | ||
"ideogram" | ||
) | ||
jina_credentials: APIKeyCredentials = _DEFAULTS.get("jina") or _fallback("jina") | ||
llama_api_credentials: APIKeyCredentials = _DEFAULTS.get("llama_api") or _fallback( | ||
"llama_api" | ||
) | ||
open_router_credentials: APIKeyCredentials = _DEFAULTS.get("open_router") or _fallback( | ||
"open_router" | ||
) | ||
openai_credentials: APIKeyCredentials = _DEFAULTS.get("openai") or _fallback("openai") | ||
replicate_credentials: APIKeyCredentials = _DEFAULTS.get("replicate") or _fallback( | ||
"replicate" | ||
) | ||
revid_credentials: APIKeyCredentials = _DEFAULTS.get("revid") or _fallback("revid") | ||
unreal_credentials: APIKeyCredentials = _DEFAULTS.get("unreal") or _fallback("unreal") | ||
|
||
for name in list(locals().keys()): | ||
if name.endswith("_credentials") and locals()[name] is None: | ||
locals()[name] = APIKeyCredentials( | ||
id="", | ||
provider=name.removesuffix("_credentials"), | ||
api_key=SecretStr(""), | ||
title="", | ||
expires_at=None, | ||
) | ||
|
||
# =============== Configure the cost for each LLM Model call =============== # | ||
|
||
|
@@ -111,7 +143,7 @@ | |
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "anthropic" | ||
if MODEL_METADATA[model].provider == "anthropic" and anthropic_credentials | ||
] | ||
# OpenAI Models | ||
+ [ | ||
|
@@ -128,7 +160,7 @@ | |
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "openai" | ||
if MODEL_METADATA[model].provider == "openai" and openai_credentials | ||
] | ||
# Groq Models | ||
+ [ | ||
|
@@ -141,7 +173,7 @@ | |
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "groq" | ||
if MODEL_METADATA[model].provider == "groq" and groq_credentials | ||
] | ||
# Open Router Models | ||
+ [ | ||
|
@@ -158,7 +190,7 @@ | |
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "open_router" | ||
if MODEL_METADATA[model].provider == "open_router" and open_router_credentials | ||
] | ||
# Llama API Models | ||
+ [ | ||
|
@@ -175,7 +207,7 @@ | |
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "llama_api" | ||
if MODEL_METADATA[model].provider == "llama_api" and llama_api_credentials | ||
] | ||
) | ||
|
||
|
Oops, something went wrong.
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.
We should not have a fallback here