Skip to content

Cost calculation is always zero with fine-tuned OpenAI models #11715

@robatwilliams

Description

@robatwilliams

System Info

LangChain 0.0.240

but code on latest master has same issue

Who can help?

@agola11

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

Use a fine-tuned OpenAI model, named like "ft:gpt-2.5-turbo-0613:orgname@12abCDEF"

with get_openai_callback() as openai_callback:

openai_callback.total_cost

The cost is zero.

Expected behavior

The cost is returned.

The issue is in https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/callbacks/openai_info.py#L67

which expects fine-tuned models' names' to start with "ft-" (dash, should be colon)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions