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

[BUG] UNSUPPORTED MEDIA TYPE for EmbedderOpenAICompatibleConfig #723

Open
piperino11 opened this issue Feb 17, 2024 · 4 comments
Open

[BUG] UNSUPPORTED MEDIA TYPE for EmbedderOpenAICompatibleConfig #723

piperino11 opened this issue Feb 17, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@piperino11
Copy link

I created a flask server to use SentenceTransformer("multi-qa-MiniLM-L6-cos-v1")

with EmbedderOpenAICompatibleConfig

I can't handle requests with error "POST /v1/embeddings HTTP/1.1" 415 -

In particular on the cat side I have the error
File "/app/cat/factory/custom_embedder.py", line 59, in embed_documents
ret.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 759, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '415 UNSUPPORTED MEDIA TYPE' for url 'http://server:port/v1/embeddings'

The specification on the content-type of the Header seems to be missing or am I wrong?

@piperino11 piperino11 added the bug Something isn't working label Feb 17, 2024
@valentimarco
Copy link
Collaborator

hi, thanks for this bug report.
We encounter many issue with the OpenAICompatibleConfig, so needs a refactor!
Stay turn in discord for more updates,

Again, thanks for the report!

@piperino11
Copy link
Author

piperino11 commented Feb 22, 2024

@valentimarco Here are the corrections I made locally and now it works:
in cheshire-cat/core/cat/factory/custom_embedder.py:

` def embed_documents(self, texts: List[str]) -> List[List[float]]:
payload = json.dumps({"input": texts})
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}

    ret = httpx.post(self.url, data=payload, timeout=None,headers=headers)
    ret.raise_for_status()
    return  [e['embedding'] for e in ret.json()['data']]


def embed_query(self, text: str) -> List[float]:
    payload = json.dumps({"input": text})
    headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
    ret = httpx.post(self.url, data=payload, timeout=None,headers=headers)
    ret.raise_for_status()
    return ret.json()['data'][0]['embedding']`

@valentimarco
Copy link
Collaborator

@piperino11 would you like to open a PR? Would be great and we can move it on the fix of the all OpenAIcompatible class

@pieroit
Copy link
Member

pieroit commented May 5, 2024

@piperino11 please check if the issue is still present in develop, should have been fixed already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants