Skip to content

Anthropic

fastagency.studio.models.llms.anthropic.Anthropic #

Bases: Model

api_key instance-attribute #

api_key: AnthropicAPIKeyRef

api_type class-attribute instance-attribute #

api_type: Literal['anthropic'] = 'anthropic'

base_url class-attribute instance-attribute #

base_url: URL = URL(url='https://api.anthropic.com/v1')

model class-attribute instance-attribute #

model: AnthropicModels = 'claude-3-5-sonnet-20240620'

name instance-attribute #

name: str

temperature class-attribute instance-attribute #

temperature: float = 0.8

create_autogen async classmethod #

create_autogen(
    model_id: UUID, user_id: UUID, **kwargs: Any
) -> dict[str, Any]
Source code in fastagency/studio/models/llms/anthropic.py
@classmethod
async def create_autogen(
    cls, model_id: UUID, user_id: UUID, **kwargs: Any
) -> dict[str, Any]:
    my_model: Anthropic = await cls.from_db(model_id)

    api_key_model: AnthropicAPIKey = (
        await my_model.api_key.get_data_model().from_db(my_model.api_key.uuid)
    )

    api_key = await api_key_model.create_autogen(my_model.api_key.uuid, user_id)

    config_list = [
        {
            "model": my_model.model,
            "api_key": api_key,
            "base_url": str(my_model.base_url),
            "api_type": my_model.api_type,
        }
    ]

    llm_config = {
        "config_list": config_list,
        "temperature": my_model.temperature,
    }

    return llm_config

from_db async classmethod #

from_db(model_id: UUID) -> T
Source code in fastagency/studio/models/base.py
@classmethod
async def from_db(cls: type[T], model_id: UUID) -> T:
    my_model_dict = await DefaultDB.backend().find_model(model_id)
    my_model = cls(**my_model_dict["json_str"])

    return my_model

get_reference_model classmethod #

get_reference_model() -> Type[ObjectReference]
Source code in fastagency/studio/models/base.py
@classmethod
def get_reference_model(cls) -> "Type[ObjectReference]":
    if cls._reference_model is None:
        raise ValueError("reference model not set")
    return cls._reference_model