-
Notifications
You must be signed in to change notification settings - Fork 44.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into kpczerwinski/open-1999-credentials-system-ux-…
…improvements
- Loading branch information
Showing
4 changed files
with
250 additions
and
216 deletions.
There are no files selected for viewing
This file contains 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
194 changes: 194 additions & 0 deletions
194
autogpt_platform/backend/backend/data/block_cost_config.py
This file contains 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,194 @@ | ||
from typing import Type | ||
|
||
from autogpt_libs.supabase_integration_credentials_store.store import ( | ||
anthropic_credentials, | ||
did_credentials, | ||
groq_credentials, | ||
ideogram_credentials, | ||
jina_credentials, | ||
openai_credentials, | ||
replicate_credentials, | ||
revid_credentials, | ||
) | ||
|
||
from backend.blocks.ai_shortform_video_block import AIShortformVideoCreatorBlock | ||
from backend.blocks.ideogram import IdeogramModelBlock | ||
from backend.blocks.jina.search import SearchTheWebBlock | ||
from backend.blocks.llm import ( | ||
MODEL_METADATA, | ||
AIConversationBlock, | ||
AIStructuredResponseGeneratorBlock, | ||
AITextGeneratorBlock, | ||
AITextSummarizerBlock, | ||
LlmModel, | ||
) | ||
from backend.blocks.replicate_flux_advanced import ReplicateFluxAdvancedModelBlock | ||
from backend.blocks.search import ExtractWebsiteContentBlock | ||
from backend.blocks.talking_head import CreateTalkingAvatarVideoBlock | ||
from backend.data.block import Block | ||
from backend.data.cost import BlockCost, BlockCostType | ||
|
||
# =============== Configure the cost for each LLM Model call =============== # | ||
|
||
MODEL_COST: dict[LlmModel, int] = { | ||
LlmModel.O1_PREVIEW: 16, | ||
LlmModel.O1_MINI: 4, | ||
LlmModel.GPT4O_MINI: 1, | ||
LlmModel.GPT4O: 3, | ||
LlmModel.GPT4_TURBO: 10, | ||
LlmModel.GPT3_5_TURBO: 1, | ||
LlmModel.CLAUDE_3_5_SONNET: 4, | ||
LlmModel.CLAUDE_3_HAIKU: 1, | ||
LlmModel.LLAMA3_8B: 1, | ||
LlmModel.LLAMA3_70B: 1, | ||
LlmModel.MIXTRAL_8X7B: 1, | ||
LlmModel.GEMMA_7B: 1, | ||
LlmModel.GEMMA2_9B: 1, | ||
LlmModel.LLAMA3_1_405B: 1, | ||
LlmModel.LLAMA3_1_70B: 1, | ||
LlmModel.LLAMA3_1_8B: 1, | ||
LlmModel.OLLAMA_LLAMA3_8B: 1, | ||
LlmModel.OLLAMA_LLAMA3_405B: 1, | ||
} | ||
|
||
for model in LlmModel: | ||
if model not in MODEL_COST: | ||
raise ValueError(f"Missing MODEL_COST for model: {model}") | ||
|
||
|
||
LLM_COST = ( | ||
[ | ||
BlockCost( | ||
cost_type=BlockCostType.RUN, | ||
cost_filter={ | ||
"model": model, | ||
"api_key": None, # Running LLM with user own API key is free. | ||
}, | ||
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
] | ||
+ [ | ||
BlockCost( | ||
cost_type=BlockCostType.RUN, | ||
cost_filter={ | ||
"model": model, | ||
"credentials": { | ||
"id": anthropic_credentials.id, | ||
"provider": anthropic_credentials.provider, | ||
"type": anthropic_credentials.type, | ||
}, | ||
}, | ||
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "anthropic" | ||
] | ||
+ [ | ||
BlockCost( | ||
cost_type=BlockCostType.RUN, | ||
cost_filter={ | ||
"model": model, | ||
"credentials": { | ||
"id": openai_credentials.id, | ||
"provider": openai_credentials.provider, | ||
"type": openai_credentials.type, | ||
}, | ||
}, | ||
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "openai" | ||
] | ||
+ [ | ||
BlockCost( | ||
cost_type=BlockCostType.RUN, | ||
cost_filter={ | ||
"model": model, | ||
"credentials": {"id": groq_credentials.id}, | ||
}, | ||
cost_amount=cost, | ||
) | ||
for model, cost in MODEL_COST.items() | ||
if MODEL_METADATA[model].provider == "groq" | ||
] | ||
+ [ | ||
BlockCost( | ||
# Default cost is running LlmModel.GPT4O. | ||
cost_amount=MODEL_COST[LlmModel.GPT4O], | ||
cost_filter={"api_key": None}, | ||
), | ||
] | ||
) | ||
|
||
# =============== This is the exhaustive list of cost for each Block =============== # | ||
|
||
BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = { | ||
AIConversationBlock: LLM_COST, | ||
AITextGeneratorBlock: LLM_COST, | ||
AIStructuredResponseGeneratorBlock: LLM_COST, | ||
AITextSummarizerBlock: LLM_COST, | ||
CreateTalkingAvatarVideoBlock: [ | ||
BlockCost( | ||
cost_amount=15, | ||
cost_filter={ | ||
"credentials": { | ||
"id": did_credentials.id, | ||
"provider": did_credentials.provider, | ||
"type": did_credentials.type, | ||
} | ||
}, | ||
) | ||
], | ||
SearchTheWebBlock: [ | ||
BlockCost( | ||
cost_amount=1, | ||
cost_filter={ | ||
"credentials": { | ||
"id": jina_credentials.id, | ||
"provider": jina_credentials.provider, | ||
"type": jina_credentials.type, | ||
} | ||
}, | ||
) | ||
], | ||
ExtractWebsiteContentBlock: [ | ||
BlockCost(cost_amount=1, cost_filter={"raw_content": False}) | ||
], | ||
IdeogramModelBlock: [ | ||
BlockCost( | ||
cost_amount=1, | ||
cost_filter={ | ||
"credentials": { | ||
"id": ideogram_credentials.id, | ||
"provider": ideogram_credentials.provider, | ||
"type": ideogram_credentials.type, | ||
} | ||
}, | ||
) | ||
], | ||
AIShortformVideoCreatorBlock: [ | ||
BlockCost( | ||
cost_amount=10, | ||
cost_filter={ | ||
"credentials": { | ||
"id": revid_credentials.id, | ||
"provider": revid_credentials.provider, | ||
"type": revid_credentials.type, | ||
} | ||
}, | ||
) | ||
], | ||
ReplicateFluxAdvancedModelBlock: [ | ||
BlockCost( | ||
cost_amount=10, | ||
cost_filter={ | ||
"credentials": { | ||
"id": replicate_credentials.id, | ||
"provider": replicate_credentials.provider, | ||
"type": replicate_credentials.type, | ||
} | ||
}, | ||
) | ||
], | ||
} |
This file contains 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,32 @@ | ||
from enum import Enum | ||
from typing import Any, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from backend.data.block import BlockInput | ||
|
||
|
||
class BlockCostType(str, Enum): | ||
RUN = "run" # cost X credits per run | ||
BYTE = "byte" # cost X credits per byte | ||
SECOND = "second" # cost X credits per second | ||
|
||
|
||
class BlockCost(BaseModel): | ||
cost_amount: int | ||
cost_filter: BlockInput | ||
cost_type: BlockCostType | ||
|
||
def __init__( | ||
self, | ||
cost_amount: int, | ||
cost_type: BlockCostType = BlockCostType.RUN, | ||
cost_filter: Optional[BlockInput] = None, | ||
**data: Any, | ||
) -> None: | ||
super().__init__( | ||
cost_amount=cost_amount, | ||
cost_filter=cost_filter or {}, | ||
cost_type=cost_type, | ||
**data, | ||
) |
Oops, something went wrong.