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

fix: handle OpenAI.CreateEmbeddingResponse.Usage instead of only Open… #484

Closed

Conversation

selbyk
Copy link
Contributor

@selbyk selbyk commented Dec 12, 2024

Problem

OpenAI embeddings.create not reporting prompt_tokens because the embeddings Usage type is different from CompletionsUsage

Changes

handle OpenAI.CreateEmbeddingResponse.Usage instead of only OpenAI.CompletionsUsage

Release info Sub-libraries affected

Bump level

  • Major
  • Minor
  • Patch

Libraries affected

  • All of them?
  • langfuse
  • langfuse-node

Changelog notes

  • Fixed token usage reporting for embeddings

Important

Fixes token usage reporting for OpenAI embeddings by handling OpenAI.CreateEmbeddingResponse.Usage in parseUsage and wrapMethod.

  • Behavior:
    • Fixes token usage reporting for OpenAI embeddings by handling OpenAI.CreateEmbeddingResponse.Usage in parseUsage in parseOpenAI.ts.
    • Updates wrapMethod in traceMethod.ts to support OpenAI.CreateEmbeddingResponse.Usage.
  • Functions:
    • Modifies hasCompletionUsage in parseOpenAI.ts to check for OpenAI.CreateEmbeddingResponse.Usage.
    • Updates wrapMethod to handle both OpenAI.CompletionUsage and OpenAI.CreateEmbeddingResponse.Usage for streaming responses.
  • Misc:
    • Adjusts completionTokens handling in parseUsage to default to 0 if not present.

This description was created by Ellipsis for 7cbb60c. It will automatically update as commits are pushed.

Copy link

vercel bot commented Dec 12, 2024

@selbyk is attempting to deploy a commit to the langfuse Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Dec 12, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: Experimental PR review

PR Summary

Modified OpenAI usage parsing to correctly handle token reporting for both completion and embedding responses, fixing missing prompt tokens in embedding responses.

  • Updated type handling in langfuse/src/openai/traceMethod.ts to support both OpenAI.CompletionUsage and OpenAI.CreateEmbeddingResponse.Usage
  • Added type guard hasCompletionUsage in langfuse/src/openai/parseOpenAI.ts to handle optional completion_tokens
  • Modified usage parsing logic to default completion_tokens to 0 for embedding responses

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@selbyk
Copy link
Contributor Author

selbyk commented Dec 13, 2024

Closing because PR #486 addresses this issue in a better way.

@hassiebp, could you take a look at my other PR #483 as well when you get a chance? We're patching it in at the moment, but I hate relying on internal patches to libraries

I really appreciate the quick attention to the usage issue (unless you had already happened to grab that ticket off your backlog by coincidence!)

Happy Friday, and have a good weekend++

@selbyk selbyk closed this Dec 13, 2024
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

Successfully merging this pull request may close these issues.

2 participants