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

Huggingface /generate in path to model is not expected #1727

Open
nastyabakhshieva opened this issue Nov 12, 2024 · 2 comments
Open

Huggingface /generate in path to model is not expected #1727

nastyabakhshieva opened this issue Nov 12, 2024 · 2 comments

Comments

@nastyabakhshieva
Copy link

Bug description
I was experimenting on Spring AI and was looking for a free model for ChatApi implementation. Upon investigation I found I can use HuggingFace microsoft/Phi-3-mini-4k-instruct model. So, I added the following dependency in my project and started to investigate:

// POM version is 1.0.0-M3
implementation 'org.springframework.ai:spring-ai-huggingface-spring-boot-starter'

Similarly, I added in application yaml:

spring:
  ai:
    huggingface:
      chat:
        api-key: hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        url: https://api-inference.huggingface.co/models/microsoft/Phi-3-mini-4k-instruct

Once done, I called HuggingfaceChatModel

Unfortunately, The following exception was received:

org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found: "{"error":"Model microsoft/Phi-3-mini-4k-instruct/generate does not exist"}"

What I found is that, /generate postfix is appended in the code & hardcoded in org.springframework.ai.huggingface.api.TextGenerationInferenceApi#generateWithHttpInfo, line 83
Whereas, with postman everything works as expected as per hugging face documentation - https://huggingface.co/docs/api-inference/tasks/text-generation?code=curl

Environment
Java version - 21
Build tool - gradle 8.3
Spring AI version - 1.0.0-M3

Steps to reproduce
Just a simple ChatClient setup with hugging face model provided along with access key generated in hugging face account

Expected behavior
/generate is not hardcoded hence can put whatever url is needed

Minimal Complete Reproducible example
I can't put my access key here, but all you need to do is

  1. Create a simple project
  2. Add huggingface-ai dependency
  3. Define hugging face url & access key in application properties file
  4. Call the ChatClient
@jitokim
Copy link
Contributor

jitokim commented Nov 13, 2024

I removed the path from the generated client file using the openapi.json and ran it because of this issue.

It seems like I might need to get the latest version of the OpenAPI file from Hugging Face. (I haven’t fully analyzed it yet.)

As a temporary workaround, it works if remove the path in the URI component builder for the path.

ilayaperumalg pushed a commit that referenced this issue Nov 14, 2024
   - Update GenerateResponse content schema type to array at openapi.json
   - Use CompatGenerateRequest instead of GenerateRequest for the TextGenerationInference API Request

Signed-off-by: jitokim <[email protected]>
@jitokim
Copy link
Contributor

jitokim commented Nov 16, 2024

@nastyabakhshieva Hi, thanks for reporting issue.
The PR for Hugging Face has been merged, and also #1733
Now you can close this issue. 😃

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

No branches or pull requests

2 participants