The g4f api cannot specify a provider! How to solve this? #2333
-
The g4f api cannot specify a provider! How to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
After looking into the code, I found out how to control which provider the api uses! You're going to have to manually open models.py located somewhere in your g4f folder, usually located in the following locations: System-Wide: Current User: Open it in notepad or whatever default text editor you use and then scroll towards "Text" section near the top, there you'll see For example, if I wanted to remove ChatGptEs when using g4f api with gpt-4o, I'll edit it out like this:
You can customize the list if it supports the given model, otherwise just remove what you don't want the api to use! |
Beta Was this translation helpful? Give feedback.
-
@Perfecttoor Also you can define one or multiple providers in the "provider" parameter: import requests
import json
from g4f.image import to_data_uri
from g4f.requests.raise_for_status import raise_for_status
url = "http://localhost:8080/v1/chat/completions"
body = {
"model": "",
"provider": "You OpenaiAccount",
"messages": [
{"role": "user", "content": "what are on this image?"}
],
"images": [
[to_data_uri(open("docs/images/cat.jpeg", "rb")), "cat.jpeg"]
]
}
response = requests.post(url, json=body, headers={"g4f-api-key": "secret"})
raise_for_status(response)
print(response.json()) |
Beta Was this translation helpful? Give feedback.
After looking into the code, I found out how to control which provider the api uses!
You're going to have to manually open models.py located somewhere in your g4f folder, usually located in the following locations:
System-Wide:
C:\Python[Version]\Lib\site-packages\g4f\models.py
Current User:
C:\Users[user]\AppData\Local\Programs\Python\Python[Version]\Lib\site-packages\g4f\models.py
Open it in notepad or whatever default text editor you use and then scroll towards "Text" section near the top, there you'll see
various models with a "best_provider" list, look at the list of providers and remove anything you don't want to use for the given
ChatGPT Model you're using.
For example, if I wanted…