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

Fix openai#embed method #555

Merged
merged 3 commits into from
Apr 4, 2024
Merged

Fix openai#embed method #555

merged 3 commits into from
Apr 4, 2024

Conversation

andreibondarev
Copy link
Collaborator

No description provided.

@andreibondarev andreibondarev marked this pull request as ready for review April 3, 2024 14:18
@andreibondarev
Copy link
Collaborator Author

andreibondarev commented Apr 3, 2024

@prdanelli Would you please give this a proper review and test?

@prdanelli
Copy link
Contributor

prdanelli commented Apr 4, 2024

Andrei, I can confirm it works as intended - we are able to specify the dimensions as a param to the embed method:

irb(main):003> client.llm
=>
#<Langchain::LLM::OpenAI:0x0000000113ef69b0
 @client=
  #<OpenAI::Client:0x0000000113ef6348
   @access_token="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",
   @api_type=nil,
   @api_version="v1",
   @extra_headers={},
   @faraday_middleware=nil,
   @organization_id=nil,
   @request_timeout=120,
   @uri_base="https://api.openai.com/">,
 @defaults=
  {:n=>1,
   :temperature=>0.0,
   :chat_completion_model_name=>"gpt-3.5-turbo",
   :embeddings_model_name=>"text-embedding-3-small",
   :dimension=>512}>

irb(main):004> vs = client.llm.embed(text: "cat").embedding
irb(main):005> vs.count
=> 1536
irb(main):006> vs = client.llm.embed(text: "cat", dimensions: 512).embedding
irb(main):007> vs.count
=> 512
irb(main):008> vs = client.llm.embed(text: "cat", dimensions: 999).embedding
irb(main):009> vs.count
=> 999

It looks as though the default is no longer respected when the LLM instance is created:

Langchain::LLM::OpenAI.new(
      api_key: ENV["OPEN_AI_SECRET_KEY"],
      default_options: {
        embeddings_model_name: "text-embedding-3-small",
        dimension: 512,
      }
    )

But that might be one for another day. Thank you again for jumping on this so quickly, its very much appreciated - I'm sorry I wasn't able to add the PR myself.

@andreibondarev andreibondarev merged commit a350a25 into main Apr 4, 2024
7 checks passed
@andreibondarev andreibondarev deleted the fix-openai#embed branch April 4, 2024 14:38
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.

Dimension sizes not being correctly passed to OpenAI after original code removed in later PR
2 participants