Skip to content

OpenAiUsage throws NullPointerException in EmbeddingModel #1152

@ThomasVitale

Description

@ThomasVitale

Bug description
The methods implemented by OpenAiUsage throw NullPointerException whenever one of the usage type is not reported by OpenAI. For example, that's the case with the "generation tokens" for Embedding models.

Environment
Spring AI: 1.0.0-SNAPSHOT

Steps to reproduce

  • Use the OpenAiEmbeddingModel to make a call to OpenAI
  • On the EmbeddingResponse, get the Usage and call the getGenerationTokens() method.
  • You'll get a NullPointerException.

Expected behavior
No NullPointerException when the usage tokens are not reported by the model provider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions