xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
60.01k stars 13.22k forks source link

Model Selection Error with Direct Provider Specification #1872

Closed nullstreak closed 4 months ago

nullstreak commented 4 months ago

Certain models throw an error when a provider is specified directly, despite functioning correctly when the same model is executed randomly via the RetryProvider.

To reproduce the issue, consider the following example:

from g4f.client import Client
import g4f

client = Client()
response = client.chat.completions.create(
    messages=[{'role':'user', 'content': 'test'}], 
    model=g4f.models.mistral_7b,
    provider=g4f.Provider.HuggingChat,
    stream=True,
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content or "", end="")

This code snippet yields the following error:

g4f.errors.ModelNotSupportedError: Model is not supported: mistralai/Mistral-7B-Instruct-v0.1 in: HuggingChat

However, when we comment out the provider=g4f.Provider.HuggingChat line and run the code multiple times, allowing the RetryProvider to randomly select the HuggingChat provider, the model functions as expected.

hlohaus commented 4 months ago

You can only use the models that the provider supports. If you want to run a provider with its default model, you can pass g4f.models.default.

github-actions[bot] commented 4 months ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] commented 4 months ago

Closing due to inactivity.