Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Sep 18, 2025

Important

Adds support for OpenAI's embeddings API to Langfuse, including synchronous and asynchronous operations, with comprehensive test coverage.

  • Behavior:
    • Adds OpenAiDefinition entries for synchronous and asynchronous embedding operations in langfuse/openai.py.
    • Uses "OpenAI-embedding" as default operation name for embeddings.
    • Extracts prompts from input parameter for embeddings.
    • Parses embedding-specific parameters like dimensions and encoding_format.
    • Creates observations with type "embedding".
    • Extracts embedding-specific response data (dimensions and count).
  • Test Coverage:
    • Adds test_openai_embeddings, test_openai_embeddings_multiple_inputs, and test_async_openai_embeddings in tests/test_openai.py.
    • Tests validate observation type, input/output handling, usage statistics, and metadata preservation for embeddings.

This description was created by Ellipsis for b65d602. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Summary

Updated On: 2025-09-18 15:43:55 UTC

This PR adds comprehensive support for OpenAI's embeddings API to the Langfuse integration. The changes span both the core integration logic and test coverage to handle embeddings as a distinct type of operation alongside existing chat completions and text completions.

Core Integration Changes:
The implementation adds two new OpenAiDefinition entries for synchronous and asynchronous embedding operations, following the established pattern used for other OpenAI APIs. The wrapper logic has been extended with conditional handling based on resource.type == "embedding" throughout the codebase to accommodate the different input/output structure of embeddings compared to chat/completion APIs.

Key behavioral differences for embeddings include:

  • Uses "OpenAI-embedding" as the default operation name instead of "OpenAI-generation"
  • Extracts prompts from the input parameter rather than messages or prompt
  • Parses embedding-specific model parameters like dimensions and encoding_format instead of chat parameters like temperature
  • Creates observations with type "embedding" rather than "generation"
  • Extracts embedding-specific response data (dimensions and count) rather than text completion data

Test Coverage:
Three comprehensive test functions validate the integration: test_openai_embeddings for basic single-input operations, test_openai_embeddings_multiple_inputs for batch processing, and test_async_openai_embeddings for asynchronous operations. The tests verify proper observation type tracking, input/output handling, usage statistics, and metadata preservation.

The implementation maintains backward compatibility with existing functionality while extending the Langfuse integration to cover embeddings, which are essential for vector search, semantic similarity, and RAG applications.

Confidence score: 4/5

  • This PR appears safe to merge with good architectural consistency
  • Score reflects well-structured conditional logic and comprehensive test coverage
  • Pay close attention to the conditional branching logic in langfuse/openai.py

Copy link
Contributor

@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.

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@hassiebp hassiebp merged commit f809baf into main Sep 18, 2025
11 checks passed
@hassiebp hassiebp deleted the add-openai-embedding-support branch September 18, 2025 16:56
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