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

feat(openai): include raw data in embedQuery method #6924

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CarlosSLoureiro
Copy link

I would like to contribute with this small feature because it is a need I have and perhaps others may have as well.

We have the option to obtain the full response data from OpenAI in completion methods such as withStructuredOutput, for example, but we don't have it in this embedding generation method. I need to obtain the data on the number of tokens sent without necessarily having another library estimate this data for me.

Here’s an example:

image

Additionally, this adjustment will not cause any changes to the existing interface unless we explicitly the includeRaw in the options param.

Copy link

vercel bot commented Oct 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Oct 8, 2024 3:02pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Oct 8, 2024 3:02pm

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. auto:improvement Medium size change to existing code to handle new use-cases labels Oct 2, 2024
@XStarlink
Copy link

Hi @CarlosSLoureiro , thanks for this very nice addition!

I was looking through the whole langchain-js github to see how openai embeddings were handled because like you I need to get the usages when I do embeddings:

const embeddings = await openaiEmbeddings.embedDocuments(texts)

I'd like to know the total cost of tokens to track my users' consumption in my saas.

Is it possible for you to add what you've done to the embedDocuments method? 🙏

@CarlosSLoureiro
Copy link
Author

Hi @XStarlink , that's a great suggestion, thanks. When I have some free time I'll make this adjustment and open another PR.

@langchain-ai langchain-ai locked as spam and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants