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

Error when call generateObjectV2 #469

Closed
darwintree opened this issue Nov 21, 2024 · 2 comments
Closed

Error when call generateObjectV2 #469

darwintree opened this issue Nov 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@darwintree
Copy link
Contributor

Describe the bug

If generateObjectV2 is used, the passed modelClass is not processed appropriately and would produce a bug.

trimTokens receive the parameters models which is expected to be strings like gpt-4o. However, in generateObjectV2, modelClass, which is supposed to be small, "medium" or "large" is provided.

context = await trimTokens(context, max_context_length, modelClass);
export function trimTokens(context, maxTokens, model) {
    // Count tokens and truncate context if necessary
    const encoding = encoding_for_model(model as TiktokenModel);
    let tokens = encoding.encode(context);
    const textDecoder = new TextDecoder();
    if (tokens.length > maxTokens) {
        tokens = tokens.reverse().slice(maxTokens).reverse();

        context = textDecoder.decode(encoding.decode(tokens));
    }
    return context;
}

Screenshots

image

Additional context

@darwintree darwintree added the bug Something isn't working label Nov 21, 2024
@darwintree
Copy link
Contributor Author

A relating PR is created #445

@monilpat
Copy link
Collaborator

Feel free to close this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants