Skip to content

utils

dandy.llm.utils

get_estimated_token_count_for_prompt

Source code in dandy/llm/utils.py
def get_estimated_token_count_for_prompt(
        prompt: PromptOrStr,
        postfix_system_prompt: PromptOrStrOrNone = None
) -> int:

    return service_system_prompt(
        system_prompt=postfix_system_prompt
    ).estimated_token_count + service_user_prompt(prompt).estimated_token_count

get_image_mime_type_from_base64_string

Source code in dandy/llm/utils.py
def get_image_mime_type_from_base64_string(base64_string):
    SIGNATURES = {
        "JVBERi0": "application/pdf",
        "R0lGODdh": "image/gif",
        "R0lGODlh": "image/gif",
        "iVBORw0KGgo": "image/png",
        "/9j/": "image/jpg"
    }

    for signature in SIGNATURES:
        if base64_string.startswith(signature):
            return SIGNATURES[signature]

    return None