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

Local LLM with LM Studio Server: Error in POST payload when using langchain_openai.OpenAIEmbeddings for embedding API. #21318

Open
5 tasks done
relusion opened this issue May 6, 2024 · 4 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations

Comments

@relusion
Copy link

relusion commented May 6, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

# this code works just fine with local deployed embedding model with LM Studio server with OPENAI API.
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8999/v1", api_key="lm-studio")

def get_embeddings(texts, model="nomic-ai/nomic-embed-text-v1.5-GGUF"):
    texts = [text.replace("\n", " ") for text in texts]
    return client.embeddings.create(input=texts, model=model).data

print(get_embeddings(["how to find out how LLM applications are performing in real-world scenarios?"]))

This is what I see on the server side and the server returns embedding data back to the code:

[2024-05-06 13:51:34.227] [INFO] Received POST request to /v1/embeddings with body:
{
  "input": [
    "how to find out how LLM applications are performing in real-world scenarios?"
  ],
  "model": "nomic-ai/nomic-embed-text-v1.5-GGUF",
  "encoding_format": "base64"
}
#however if I switch to OpenAIEmbeddings, this code does not work
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(openai_api_key="sk-1234", base_url="http://localhost:8999/v1", model="nomic-ai/nomic-embed-text-v1.5-GGUF")
test = embeddings.embed_query("how to find out how LLM applications are performing in real-world scenarios?")
# this is what I see on the server side:
[2024-05-06 13:52:08.629] [INFO] Received POST request to /v1/embeddings with body:
{
  "input": [
    [
      5269,
      311,
      1505,
      704,
      1268,
      445,
      11237,
      8522,
      527,
      16785,
      304,
      1972,
      31184,
      26350,
      30
    ]
  ],
  "model": "nomic-ai/nomic-embed-text-v1.5-GGUF",
  "encoding_format": "base64"
}

Error Message and Stack Trace (if applicable)

Error on the server side:
[ERROR] 'input' field must be a string or an array of strings

Description

I encountered an issue with the langchain_openai library where using OpenAIEmbeddings to embed a text query results in a malformed POST request payload to the API endpoint. Below is a comparison of the expected and actual requests.

System Info

System Information

OS: Windows
OS Version: 10.0.22631
Python Version: 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]

Package Information

langchain_core: 0.1.50
langchain: 0.1.17
langchain_community: 0.0.36
langsmith: 0.1.54
langchain_chroma: 0.1.0
langchain_openai: 0.1.6
langchain_text_splitters: 0.0.1

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langgraph
langserve

@dosubot dosubot bot added 🔌: openai Primarily related to OpenAI integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels May 6, 2024
@relusion
Copy link
Author

relusion commented May 6, 2024

An observation:
Setting check_embedding_ctx_length to False fixes the problem.

OpenAIEmbeddings(check_embedding_ctx_length=False, openai_api_key="sk-1234", base_url="http://localhost:8999/v1",model="nomic-ai/nomic-embed-text-v1.5-GGUF")

@vickybiswas
Copy link

I have the same issue, and it is not recognizing the suggested parameter
Embeddings.create() got an unexpected keyword argument 'check_embedding_ctx_length'

@ticoAg
Copy link

ticoAg commented May 18, 2024

I have the same issue, and it is not recognizing the suggested parameter Embeddings.create() got an unexpected keyword argument 'check_embedding_ctx_length'

upgrade package and check usage

from langchain_openai import OpenAIEmbeddings
model = OpenAIEmbeddings(model="Your embed model", check_embedding_ctx_length=False)
response = model.embed_query("Hello world")
print(response)

@Trinkes
Copy link

Trinkes commented Jun 20, 2024

hey @ticoAg, thanks for the suggestion!
The check_embedding_ctx_length=False worked for me but is this going to be fixed? It sounds like a compatibility issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations
Projects
None yet
Development

No branches or pull requests

4 participants