Skip to content
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

Ability to track costs without using langchain or openai #671

Open
agamm opened this issue May 8, 2024 · 3 comments
Open

Ability to track costs without using langchain or openai #671

agamm opened this issue May 8, 2024 · 3 comments

Comments

@agamm
Copy link

agamm commented May 8, 2024

Feature request

I have a project using llm calls that are abstracted away. I'd love to be able to add costs metadata to the RunTree object with something like: tokencost manually.

Motivation

This is what I'm currently doing:

 rt = RunTree(
        run_type="llm",
        name=f"LLM Call - {model}",
        inputs={"messages": chat_messages},
        extra={
            "metadata": {
                "input_size": count_message_tokens(chat_messages, model),
                "input_price": calculate_prompt_cost(chat_messages, model),
                "output_size": count_string_tokens(response, model),
                "output_price": calculate_completion_cost(response, model),
            }
        },
    )
    rt.end(...)
    rt.post()

This doesn't aggregate the whole run costs or shows the data nicely either.

@hinthornw
Copy link
Collaborator

@agamm
Copy link
Author

agamm commented May 8, 2024

Yeah but how do I add that to the RunTree instance? I can't use the tracable decorator with the library that I'm using.

@hinthornw
Copy link
Collaborator

hinthornw commented May 8, 2024

Also out of curiosity - what motivates using the run trees directly instead of the @traceable or trace helpers?

The output format is the same as in the docs. outputs would contain an openai-compatible format, inputs contain messages, and if you want to add custom usage, you add that to extra directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants