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

change embedding response object to list for openai compatibility #444

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

wirthual
Copy link
Collaborator

Description

Return list instead of embedding in response to be compatible with openai.

Respone definition from OpenAI see here

Related Issue

#371

Types of Change

  • Bug fix
  • New feature
  • Documentation update

Checklist

  • I have read the CONTRIBUTING guidelines.
  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My changes generate no new warnings.
  • I have updated the documentation accordingly.

Additional Notes

Maybe we need to add backwards compatibility if someone relies on the embedding field.

License

By submitting this PR, I confirm that my contribution is made under the terms of the MIT license.

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.

PR Summary

Changes the OpenAI embedding response object type from 'embedding' to 'list' to align with OpenAI's API specification, improving compatibility with external services like KubeAI.

  • Changed object field enum/const from 'embedding' to 'list' in /docs/assets/openapi.json OpenAIEmbeddingResult schema
  • Updated OpenAIEmbeddingResult class in /libs/infinity_emb/infinity_emb/fastapi_schemas/pymodels.py to use 'list' as object type
  • Added test file /libs/infinity_emb/tests/unit_test/fastapi_schemas/test_response.py to verify response object is 'list'
  • Potential backwards compatibility concerns for clients relying on 'embedding' value need consideration

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

Comment on lines 182 to 184
class OpenAIEmbeddingResult(BaseModel):
object: Literal["embedding"] = "embedding"
object: Literal["list"] = "list"
data: list[_EmbeddingObject]
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This is a breaking change that could affect existing clients. Consider adding a version flag or deprecation period to maintain backward compatibility.

Comment on lines +4 to +6
def test_embedding_response():
res = OpenAIEmbeddingResult(data=[], model="hi", usage={"prompt_tokens": 5, "total_tokens": 10})
assert res.model_dump()["object"] == "list"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: test only verifies object field, should also verify data, model and usage fields are present and correctly structured

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.18%. Comparing base (e2f601d) to head (3906fdf).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #444   +/-   ##
=======================================
  Coverage   79.18%   79.18%           
=======================================
  Files          41       41           
  Lines        3248     3248           
=======================================
  Hits         2572     2572           
  Misses        676      676           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wirthual wirthual merged commit c9a8404 into main Oct 28, 2024
36 checks passed
@wirthual wirthual deleted the rw/openai-return-list branch October 28, 2024 02:18
@michaelfeil
Copy link
Owner

Thanks! Seems like I missed that!

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.

3 participants