XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Add Replicate Provider Fix Bug in OpenaiChat and MetaAI Add read cookie and .har files Use factory for api app

3a23e81d
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

14 个文件 +303 -174
Modified .gitignore +1 -0
@@ -55,6 +55,7 @@ local.py
55 55 image.py
56 56 .buildozer
57 57 hardir
58 har_and_cookies
58 59 node_modules
59 60 models
60 61 projects/windows/g4f
Modified README.md +94 -53
@@ -91,7 +91,7 @@ As per the survey, here is a list of improvements to come
91 91
92 92 ```sh
93 93 docker pull hlohaus789/g4f
94 docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" -v ${PWD}/hardir:/app/hardir hlohaus789/g4f:latest
94 docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" -v ${PWD}/hardir:/app/har_and_cookies hlohaus789/g4f:latest
95 95 ```
96 96
97 97 3. **Access the Client:**
@@ -217,10 +217,11 @@ Access with: http://localhost:1337/v1
217 217
218 218 #### Cookies
219 219
220 You need cookies for BingCreateImages and the Gemini Provider.
221 From Bing you need the "_U" cookie and from Gemini you need the "__Secure-1PSID" cookie.
222 Sometimes you doesn't need the "__Secure-1PSID" cookie, but some other auth cookies.
223 You can pass the cookies in the create function or you use the `set_cookies` setter before you run G4F:
220 Cookies are essential for using Meta AI and Microsoft Designer to create images.
221 Additionally, cookies are required for the Google Gemini and WhiteRabbitNeo Provider.
222 From Bing, ensure you have the "_U" cookie, and from Google, all cookies starting with "__Secure-1PSID" are needed.
223
224 You can pass these cookies directly to the create function or set them using the `set_cookies` method before running G4F:
224 225
225 226 ```python
226 227 from g4f.cookies import set_cookies
@@ -228,10 +229,25 @@ from g4f.cookies import set_cookies
228 229 set_cookies(".bing.com", {
229 230 "_U": "cookie value"
230 231 })
232
231 233 set_cookies(".google.com", {
232 234 "__Secure-1PSID": "cookie value"
233 235 })
234 ...
236 ```
237
238 Alternatively, you can place your .har and cookie files in the `/har_and_cookies` directory. To export a cookie file, use the EditThisCookie extension available on the Chrome Web Store: [EditThisCookie Extension](https://chromewebstore.google.com/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg).
239
240 You can also create .har files to capture cookies. If you need further assistance, refer to the next section.
241
242 ```bash
243 python -m g4f.cli api --debug
244 ```
245 ```
246 Read .har file: ./har_and_cookies/you.com.har
247 Cookies added: 10 from .you.com
248 Read cookie file: ./har_and_cookies/google.json
249 Cookies added: 16 from .google.com
250 Starting server... [g4f v-0.0.0] (debug)
235 251 ```
236 252
237 253 #### .HAR File for OpenaiChat Provider
@@ -249,7 +265,7 @@ To utilize the OpenaiChat provider, a .har file is required from https://chat.op
249 265
250 266 ##### Storing the .HAR File
251 267
252 - Place the exported .har file in the `./hardir` directory if you are using Docker. Alternatively, you can store it in any preferred location within your current working directory.
268 - Place the exported .har file in the `./har_and_cookies` directory if you are using Docker. Alternatively, you can store it in any preferred location within your current working directory.
253 269
254 270 Note: Ensure that your .har file is stored securely, as it may contain sensitive information.
255 271
@@ -273,13 +289,13 @@ set G4F_PROXY=http://host:port
273 289
274 290 | Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
275 291 | ------ | ------- | ------- | ----- | ------ | ------ | ---- |
276 | [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
277 | [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
278 | [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
279 | [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
292 | [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
293 | [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ❌ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
294 | [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
295 | [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌+✔️ |
280 296 | [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
281 297 | [beta.theb.ai](https://beta.theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
282 | [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
298 | [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
283 299
284 300 ## Best OpenSource Models
285 301 While we wait for gpt-5, here is a list of new models that are at least better than gpt-3.5-turbo. **Some are better than gpt-4**. Expect this list to grow.
@@ -296,19 +312,24 @@ While we wait for gpt-5, here is a list of new models that are at least better t
296 312 | Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
297 313 | ------ | ------- | ------- | ----- | ------ | ------ | ---- |
298 314 | [chat3.aiyunos.top](https://chat3.aiyunos.top/) | `g4f.Provider.AItianhuSpace` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
299 | [chatforai.store](https://chatforai.store) | `g4f.Provider.ChatForAi` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
300 | [chatgpt4online.org](https://chatgpt4online.org) | `g4f.Provider.Chatgpt4Online` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
301 | [chatgpt-free.cc](https://www.chatgpt-free.cc) | `g4f.Provider.ChatgptNext` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
302 | [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
303 | [flowgpt.com](https://flowgpt.com/chat) | `g4f.Provider.FlowGpt` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
304 | [freegptsnav.aifree.site](https://freegptsnav.aifree.site) | `g4f.Provider.FreeGpt` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
305 | [gpttalk.ru](https://gpttalk.ru) | `g4f.Provider.GptTalkRu` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
306 | [koala.sh](https://koala.sh) | `g4f.Provider.Koala` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
315 | [chat10.aichatos.xyz](https://chat10.aichatos.xyz) | `g4f.Provider.Aichatos` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
316 | [chatforai.store](https://chatforai.store) | `g4f.Provider.ChatForAi` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
317 | [chatgpt4online.org](https://chatgpt4online.org) | `g4f.Provider.Chatgpt4Online` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
318 | [chatgpt-free.cc](https://www.chatgpt-free.cc) | `g4f.Provider.ChatgptNext` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
319 | [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
320 | [f1.cnote.top](https://f1.cnote.top) | `g4f.Provider.Cnote` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
321 | [duckduckgo.com](https://duckduckgo.com/duckchat) | `g4f.Provider.DuckDuckGo` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
322 | [ecosia.org](https://www.ecosia.org) | `g4f.Provider.Ecosia` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
323 | [feedough.com](https://www.feedough.com) | `g4f.Provider.Feedough` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
324 | [flowgpt.com](https://flowgpt.com/chat) | `g4f.Provider.FlowGpt` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
325 | [freegptsnav.aifree.site](https://freegptsnav.aifree.site) | `g4f.Provider.FreeGpt` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
326 | [gpttalk.ru](https://gpttalk.ru) | `g4f.Provider.GptTalkRu` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
327 | [koala.sh](https://koala.sh) | `g4f.Provider.Koala` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
307 328 | [app.myshell.ai](https://app.myshell.ai/chat) | `g4f.Provider.MyShell` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
308 329 | [perplexity.ai](https://www.perplexity.ai) | `g4f.Provider.PerplexityAi` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
309 330 | [poe.com](https://poe.com) | `g4f.Provider.Poe` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
310 331 | [talkai.info](https://talkai.info) | `g4f.Provider.TalkAi` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
311 | [chat.vercel.ai](https://chat.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
332 | [chat.vercel.ai](https://chat.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
312 333 | [aitianhu.com](https://www.aitianhu.com) | `g4f.Provider.AItianhu` | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
313 334 | [chatgpt.bestim.org](https://chatgpt.bestim.org) | `g4f.Provider.Bestim` | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
314 335 | [chatbase.co](https://www.chatbase.co) | `g4f.Provider.ChatBase` | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
@@ -328,48 +349,68 @@ While we wait for gpt-5, here is a list of new models that are at least better t
328 349
329 350 | Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
330 351 | ------ | ------- | ------- | ----- | ------ | ------ | ---- |
331 | [openchat.team](https://openchat.team) | `g4f.Provider.Aura` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
332 | [bard.google.com](https://bard.google.com) | `g4f.Provider.Bard` | ❌ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
352 | [openchat.team](https://openchat.team) | `g4f.Provider.Aura` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
353 | [blackbox.ai](https://www.blackbox.ai) | `g4f.Provider.Blackbox` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
354 | [cohereforai-c4ai-command-r-plus.hf.space](https://cohereforai-c4ai-command-r-plus.hf.space) | `g4f.Provider.Cohere` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
333 355 | [deepinfra.com](https://deepinfra.com) | `g4f.Provider.DeepInfra` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
334 | [free.chatgpt.org.uk](https://free.chatgpt.org.uk) | `g4f.Provider.FreeChatgpt` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
356 | [free.chatgpt.org.uk](https://free.chatgpt.org.uk) | `g4f.Provider.FreeChatgpt` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
335 357 | [gemini.google.com](https://gemini.google.com) | `g4f.Provider.Gemini` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
336 358 | [ai.google.dev](https://ai.google.dev) | `g4f.Provider.GeminiPro` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
337 359 | [gemini-chatbot-sigma.vercel.app](https://gemini-chatbot-sigma.vercel.app) | `g4f.Provider.GeminiProChat` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
360 | [developers.sber.ru](https://developers.sber.ru/gigachat) | `g4f.Provider.GigaChat` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
361 | [console.groq.com](https://console.groq.com/playground) | `g4f.Provider.Groq` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
338 362 | [huggingface.co](https://huggingface.co/chat) | `g4f.Provider.HuggingChat` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
339 363 | [huggingface.co](https://huggingface.co/chat) | `g4f.Provider.HuggingFace` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
340 | [llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama2` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
364 | [llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
365 | [meta.ai](https://www.meta.ai) | `g4f.Provider.MetaAI` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌+✔️ |
366 | [openrouter.ai](https://openrouter.ai) | `g4f.Provider.OpenRouter` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
341 367 | [labs.perplexity.ai](https://labs.perplexity.ai) | `g4f.Provider.PerplexityLabs` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
342 | [pi.ai](https://pi.ai/talk) | `g4f.Provider.Pi` | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
343 | [theb.ai](https://theb.ai) | `g4f.Provider.ThebApi` | ❌ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
344 | [open-assistant.io](https://open-assistant.io/chat) | `g4f.Provider.OpenAssistant` | ❌ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ✔️ |
368 | [pi.ai](https://pi.ai/talk) | `g4f.Provider.Pi` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
369 | [replicate.com](https://replicate.com) | `g4f.Provider.ReplicateImage` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
370 | [theb.ai](https://theb.ai) | `g4f.Provider.ThebApi` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
371 | [whiterabbitneo.com](https://www.whiterabbitneo.com) | `g4f.Provider.WhiteRabbitNeo` | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
372 | [bard.google.com](https://bard.google.com) | `g4f.Provider.Bard` | ❌ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ✔️ |
345 373
346 374 ### Models
347 375
348 | Model | Base Provider | Provider | Website |
349 |-----------------------------| ------------- | -------- | ------- |
350 | gpt-3.5-turbo | OpenAI | 5+ Providers | [openai.com](https://openai.com/) |
351 | gpt-4 | OpenAI | 2+ Providers | [openai.com](https://openai.com/) |
352 | gpt-4-turbo | OpenAI | g4f.Provider.Bing | [openai.com](https://openai.com/) |
353 | Llama-2-7b-chat-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
354 | Llama-2-13b-chat-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
355 | Llama-2-70b-chat-hf | Meta | 3+ Providers | [llama.meta.com](https://llama.meta.com/) |
356 | Meta-Llama-3-8b | Meta | 3+ Providers | [llama.meta.com](https://llama.meta.com/) |
357 | Meta-Llama-3-70b | Meta | 3+ Providers | [llama.meta.com](https://llama.meta.com/) |
358 | CodeLlama-34b-Instruct-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
359 | CodeLlama-70b-Instruct-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
360 | Mixtral-8x7B-Instruct-v0.1 | Huggingface | 4+ Providers | [huggingface.co](https://huggingface.co/) |
361 | Mistral-7B-Instruct-v0.1 | Huggingface | 4+ Providers | [huggingface.co](https://huggingface.co/) |
362 | dolphin-2.6-mixtral-8x7b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
363 | lzlv_70b_fp16_hf | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
364 | airoboros-70b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
365 | airoboros-l2-70b-gpt4-1.4.1 | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
366 | openchat_3.5 | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
367 | gemini | Google | g4f.Provider.Gemini | [gemini.google.com](https://gemini.google.com/) |
368 | gemini-pro | Google | 2+ Providers | [gemini.google.com](https://gemini.google.com/) |
369 | claude-v2 | Anthropic | 1+ Providers | [anthropic.com](https://www.anthropic.com/) |
370 | claude-3-opus | Anthropic | g4f.Provider.You | [anthropic.com](https://www.anthropic.com/) |
371 | claude-3-sonnet | Anthropic | g4f.Provider.You | [anthropic.com](https://www.anthropic.com/) |
372 | pi | Inflection | g4f.Provider.Pi | [inflection.ai](https://inflection.ai/) |
376 | Model | Base Provider | Provider | Website |
377 | ----- | ------------- | -------- | ------- |
378 | gpt-3.5-turbo | OpenAI | 8+ Providers | [openai.com](https://openai.com/) |
379 | gpt-4 | OpenAI | 2+ Providers | [openai.com](https://openai.com/) |
380 | gpt-4-turbo | OpenAI | g4f.Provider.Bing | [openai.com](https://openai.com/) |
381 | Llama-2-7b-chat-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
382 | Llama-2-13b-chat-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
383 | Llama-2-70b-chat-hf | Meta | 3+ Providers | [llama.meta.com](https://llama.meta.com/) |
384 | Meta-Llama-3-8b-instruct | Meta | 1+ Providers | [llama.meta.com](https://llama.meta.com/) |
385 | Meta-Llama-3-70b-instruct | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
386 | CodeLlama-34b-Instruct-hf | Meta | g4f.Provider.HuggingChat | [llama.meta.com](https://llama.meta.com/) |
387 | CodeLlama-70b-Instruct-hf | Meta | 2+ Providers | [llama.meta.com](https://llama.meta.com/) |
388 | Mixtral-8x7B-Instruct-v0.1 | Huggingface | 4+ Providers | [huggingface.co](https://huggingface.co/) |
389 | Mistral-7B-Instruct-v0.1 | Huggingface | 3+ Providers | [huggingface.co](https://huggingface.co/) |
390 | Mistral-7B-Instruct-v0.2 | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
391 | zephyr-orpo-141b-A35b-v0.1 | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
392 | dolphin-2.6-mixtral-8x7b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
393 | gemini | Google | g4f.Provider.Gemini | [gemini.google.com](https://gemini.google.com/) |
394 | gemini-pro | Google | 2+ Providers | [gemini.google.com](https://gemini.google.com/) |
395 | claude-v2 | Anthropic | 1+ Providers | [anthropic.com](https://www.anthropic.com/) |
396 | claude-3-opus | Anthropic | g4f.Provider.You | [anthropic.com](https://www.anthropic.com/) |
397 | claude-3-sonnet | Anthropic | g4f.Provider.You | [anthropic.com](https://www.anthropic.com/) |
398 | lzlv_70b_fp16_hf | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
399 | airoboros-70b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
400 | openchat_3.5 | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
401 | pi | Inflection | g4f.Provider.Pi | [inflection.ai](https://inflection.ai/) |
402
403 ### Image Models
404
405 | Label | Provider | Model | Website |
406 | ----- | -------- | ----- | ------- |
407 | Microsoft Designer | Bing | dall-e | [bing.com](https://www.bing.com/images/create) |
408 | OpenAI ChatGPT | Openai | dall-e | [chat.openai.com](https://chat.openai.com) |
409 | You.com | You | dall-e | [you.com](https://you.com) |
410 | DeepInfraImage | DeepInfra | stability-ai/sdxl | [deepinfra.com](https://deepinfra.com) |
411 | ReplicateImage | Replicate | stability-ai/sdxl | [replicate.com](https://replicate.com) |
412 | Gemini | Gemini | gemini | [gemini.google.com](https://gemini.google.com) |
413 | Meta AI | MetaAI | meta | [meta.ai](https://www.meta.ai) |
373 414
374 415 ## 🔗 Powered by gpt4free
375 416
Modified g4f/Provider/MetaAI.py +1 -1
@@ -89,7 +89,7 @@ class MetaAI(AsyncGeneratorProvider):
89 89 headers = {}
90 90 headers = {
91 91 'content-type': 'application/x-www-form-urlencoded',
92 'cookie': format_cookies(cookies),
92 'cookie': format_cookies(self.cookies),
93 93 'origin': 'https://www.meta.ai',
94 94 'referer': 'https://www.meta.ai/',
95 95 'x-asbd-id': '129477',
Added g4f/Provider/Replicate.py +84 -0
@@ -0,0 +1,84 @@
1 from __future__ import annotations
2
3 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
4 from .helper import format_prompt, filter_none
5 from ..typing import AsyncResult, Messages
6 from ..requests import raise_for_status
7 from ..requests.aiohttp import StreamSession
8 from ..errors import ResponseError, MissingAuthError
9
10 class Replicate(AsyncGeneratorProvider, ProviderModelMixin):
11 url = "https://replicate.com"
12 working = True
13 default_model = "meta/meta-llama-3-70b-instruct"
14
15 @classmethod
16 async def create_async_generator(
17 cls,
18 model: str,
19 messages: Messages,
20 api_key: str = None,
21 proxy: str = None,
22 timeout: int = 180,
23 system_prompt: str = None,
24 max_new_tokens: int = None,
25 temperature: float = None,
26 top_p: float = None,
27 top_k: float = None,
28 stop: list = None,
29 extra_data: dict = {},
30 headers: dict = {
31 "accept": "application/json",
32 },
33 **kwargs
34 ) -> AsyncResult:
35 model = cls.get_model(model)
36 if cls.needs_auth and api_key is None:
37 raise MissingAuthError("api_key is missing")
38 if api_key is not None:
39 headers["Authorization"] = f"Bearer {api_key}"
40 api_base = "https://api.replicate.com/v1/models/"
41 else:
42 api_base = "https://replicate.com/api/models/"
43 async with StreamSession(
44 proxy=proxy,
45 headers=headers,
46 timeout=timeout
47 ) as session:
48 data = {
49 "stream": True,
50 "input": {
51 "prompt": format_prompt(messages),
52 **filter_none(
53 system_prompt=system_prompt,
54 max_new_tokens=max_new_tokens,
55 temperature=temperature,
56 top_p=top_p,
57 top_k=top_k,
58 stop_sequences=",".join(stop) if stop else None
59 ),
60 **extra_data
61 },
62 }
63 url = f"{api_base.rstrip('/')}/{model}/predictions"
64 async with session.post(url, json=data) as response:
65 message = "Model not found" if response.status == 404 else None
66 await raise_for_status(response, message)
67 result = await response.json()
68 if "id" not in result:
69 raise ResponseError(f"Invalid response: {result}")
70 async with session.get(result["urls"]["stream"], headers={"Accept": "text/event-stream"}) as response:
71 await raise_for_status(response)
72 event = None
73 async for line in response.iter_lines():
74 if line.startswith(b"event: "):
75 event = line[7:]
76 if event == b"done":
77 break
78 elif event == b"output":
79 if line.startswith(b"data: "):
80 new_text = line[6:].decode()
81 if new_text:
82 yield new_text
83 else:
84 yield "\n"
Modified g4f/Provider/__init__.py +1 -1
@@ -9,7 +9,6 @@ from .deprecated import *
9 9 from .not_working import *
10 10 from .selenium import *
11 11 from .needs_auth import *
12 from .unfinished import *
13 12
14 13 from .Aichatos import Aichatos
15 14 from .Aura import Aura
@@ -46,6 +45,7 @@ from .MetaAI import MetaAI
46 45 from .MetaAIAccount import MetaAIAccount
47 46 from .PerplexityLabs import PerplexityLabs
48 47 from .Pi import Pi
48 from .Replicate import Replicate
49 49 from .ReplicateImage import ReplicateImage
50 50 from .Vercel import Vercel
51 51 from .WhiteRabbitNeo import WhiteRabbitNeo
Modified g4f/Provider/needs_auth/OpenaiChat.py +8 -7
@@ -340,9 +340,8 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
340 340 Raises:
341 341 RuntimeError: If an error occurs during processing.
342 342 """
343
344 343 async with StreamSession(
345 proxies={"all": proxy},
344 proxy=proxy,
346 345 impersonate="chrome",
347 346 timeout=timeout
348 347 ) as session:
@@ -364,26 +363,27 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
364 363 api_key = cls._api_key = None
365 364 cls._create_request_args()
366 365 if debug.logging:
367 print("OpenaiChat: Load default_model failed")
366 print("OpenaiChat: Load default model failed")
368 367 print(f"{e.__class__.__name__}: {e}")
369 368
370 369 arkose_token = None
371 370 if cls.default_model is None:
371 error = None
372 372 try:
373 373 arkose_token, api_key, cookies, headers = await getArkoseAndAccessToken(proxy)
374 374 cls._create_request_args(cookies, headers)
375 375 cls._set_api_key(api_key)
376 376 except NoValidHarFileError as e:
377 ...
377 error = e
378 378 if cls._api_key is None:
379 379 await cls.nodriver_access_token()
380 380 if cls._api_key is None and cls.needs_auth:
381 raise e
381 raise error
382 382 cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers))
383 383
384 384 async with session.post(
385 385 f"{cls.url}/backend-anon/sentinel/chat-requirements"
386 if not cls._api_key else
386 if cls._api_key is None else
387 387 f"{cls.url}/backend-api/sentinel/chat-requirements",
388 388 json={"conversation_mode_kind": "primary_assistant"},
389 389 headers=cls._headers
@@ -412,7 +412,8 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
412 412 print("OpenaiChat: Upload image failed")
413 413 print(f"{e.__class__.__name__}: {e}")
414 414
415 model = cls.get_model(model).replace("gpt-3.5-turbo", "text-davinci-002-render-sha")
415 model = cls.get_model(model)
416 model = "text-davinci-002-render-sha" if model == "gpt-3.5-turbo" else model
416 417 if conversation is None:
417 418 conversation = Conversation(conversation_id, str(uuid.uuid4()) if parent_id is None else parent_id)
418 419 else:
Deleted g4f/Provider/unfinished/Replicate.py +0 -78
@@ -1,78 +0,0 @@
1 from __future__ import annotations
2
3 import asyncio
4
5 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
6 from ..helper import format_prompt, filter_none
7 from ...typing import AsyncResult, Messages
8 from ...requests import StreamSession, raise_for_status
9 from ...image import ImageResponse
10 from ...errors import ResponseError, MissingAuthError
11
12 class Replicate(AsyncGeneratorProvider, ProviderModelMixin):
13 url = "https://replicate.com"
14 working = True
15 default_model = "mistralai/mixtral-8x7b-instruct-v0.1"
16 api_base = "https://api.replicate.com/v1/models/"
17
18 @classmethod
19 async def create_async_generator(
20 cls,
21 model: str,
22 messages: Messages,
23 api_key: str = None,
24 proxy: str = None,
25 timeout: int = 180,
26 system_prompt: str = None,
27 max_new_tokens: int = None,
28 temperature: float = None,
29 top_p: float = None,
30 top_k: float = None,
31 stop: list = None,
32 extra_data: dict = {},
33 headers: dict = {},
34 **kwargs
35 ) -> AsyncResult:
36 model = cls.get_model(model)
37 if api_key is None:
38 raise MissingAuthError("api_key is missing")
39 headers["Authorization"] = f"Bearer {api_key}"
40 async with StreamSession(
41 proxies={"all": proxy},
42 headers=headers,
43 timeout=timeout
44 ) as session:
45 data = {
46 "stream": True,
47 "input": {
48 "prompt": format_prompt(messages),
49 **filter_none(
50 system_prompt=system_prompt,
51 max_new_tokens=max_new_tokens,
52 temperature=temperature,
53 top_p=top_p,
54 top_k=top_k,
55 stop_sequences=",".join(stop) if stop else None
56 ),
57 **extra_data
58 },
59 }
60 url = f"{cls.api_base.rstrip('/')}/{model}/predictions"
61 async with session.post(url, json=data) as response:
62 await raise_for_status(response)
63 result = await response.json()
64 if "id" not in result:
65 raise ResponseError(f"Invalid response: {result}")
66 async with session.get(result["urls"]["stream"], headers={"Accept": "text/event-stream"}) as response:
67 await raise_for_status(response)
68 event = None
69 async for line in response.iter_lines():
70 if line.startswith(b"event: "):
71 event = line[7:]
72 elif event == b"output":
73 if line.startswith(b"data: "):
74 yield line[6:].decode()
75 elif not line.startswith(b"id: "):
76 continue#yield "+"+line.decode()
77 elif event == b"done":
78 break
Modified g4f/api/__init__.py +26 -20
@@ -1,3 +1,5 @@
1 from __future__ import annotations
2
1 3 import logging
2 4 import json
3 5 import uvicorn
@@ -8,14 +10,19 @@ from fastapi.exceptions import RequestValidationError
8 10 from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
9 11 from fastapi.encoders import jsonable_encoder
10 12 from pydantic import BaseModel
11 from typing import List, Union, Optional
13 from typing import Union, Optional
12 14
13 15 import g4f
14 16 import g4f.debug
15 17 from g4f.client import AsyncClient
16 18 from g4f.typing import Messages
17 19
18 app = FastAPI()
20 def create_app() -> FastAPI:
21 app = FastAPI()
22 api = Api(app)
23 api.register_routes()
24 api.register_validation_exception_handler()
25 return app
19 26
20 27 class ChatCompletionsConfig(BaseModel):
21 28 messages: Messages
@@ -29,16 +36,19 @@ class ChatCompletionsConfig(BaseModel):
29 36 web_search: Optional[bool] = None
30 37 proxy: Optional[str] = None
31 38
39 list_ignored_providers: list[str] = None
40
41 def set_list_ignored_providers(ignored: list[str]):
42 global list_ignored_providers
43 list_ignored_providers = ignored
44
32 45 class Api:
33 def __init__(self, list_ignored_providers: List[str] = None) -> None:
34 self.list_ignored_providers = list_ignored_providers
46 def __init__(self, app: FastAPI) -> None:
47 self.app = app
35 48 self.client = AsyncClient()
36
37 def set_list_ignored_providers(self, list: list):
38 self.list_ignored_providers = list
39 49
40 50 def register_validation_exception_handler(self):
41 @app.exception_handler(RequestValidationError)
51 @self.app.exception_handler(RequestValidationError)
42 52 async def validation_exception_handler(request: Request, exc: RequestValidationError):
43 53 details = exc.errors()
44 54 modified_details = []
@@ -54,17 +64,17 @@ class Api:
54 64 )
55 65
56 66 def register_routes(self):
57 @app.get("/")
67 @self.app.get("/")
58 68 async def read_root():
59 69 return RedirectResponse("/v1", 302)
60 70
61 @app.get("/v1")
71 @self.app.get("/v1")
62 72 async def read_root_v1():
63 73 return HTMLResponse('g4f API: Go to '
64 74 '<a href="/v1/chat/completions">chat/completions</a> '
65 75 'or <a href="/v1/models">models</a>.')
66 76
67 @app.get("/v1/models")
77 @self.app.get("/v1/models")
68 78 async def models():
69 79 model_list = dict(
70 80 (model, g4f.models.ModelUtils.convert[model])
@@ -78,7 +88,7 @@ class Api:
78 88 } for model_id, model in model_list.items()]
79 89 return JSONResponse(model_list)
80 90
81 @app.get("/v1/models/{model_name}")
91 @self.app.get("/v1/models/{model_name}")
82 92 async def model_info(model_name: str):
83 93 try:
84 94 model_info = g4f.models.ModelUtils.convert[model_name]
@@ -91,7 +101,7 @@ class Api:
91 101 except:
92 102 return JSONResponse({"error": "The model does not exist."})
93 103
94 @app.post("/v1/chat/completions")
104 @self.app.post("/v1/chat/completions")
95 105 async def chat_completions(config: ChatCompletionsConfig, request: Request = None, provider: str = None):
96 106 try:
97 107 config.provider = provider if config.provider is None else config.provider
@@ -103,7 +113,7 @@ class Api:
103 113 config.api_key = auth_header
104 114 response = self.client.chat.completions.create(
105 115 **config.dict(exclude_none=True),
106 ignored=self.list_ignored_providers
116 ignored=list_ignored_providers
107 117 )
108 118 except Exception as e:
109 119 logging.exception(e)
@@ -125,14 +135,10 @@ class Api:
125 135
126 136 return StreamingResponse(streaming(), media_type="text/event-stream")
127 137
128 @app.post("/v1/completions")
138 @self.app.post("/v1/completions")
129 139 async def completions():
130 140 return Response(content=json.dumps({'info': 'Not working yet.'}, indent=4), media_type="application/json")
131 141
132 api = Api()
133 api.register_routes()
134 api.register_validation_exception_handler()
135
136 142 def format_exception(e: Exception, config: ChatCompletionsConfig) -> str:
137 143 last_provider = g4f.get_last_provider(True)
138 144 return json.dumps({
@@ -156,4 +162,4 @@ def run_api(
156 162 host, port = bind.split(":")
157 163 if debug:
158 164 g4f.debug.logging = True
159 uvicorn.run("g4f.api:app", host=host, port=int(port), workers=workers, use_colors=use_colors)#
165 uvicorn.run("g4f.api:create_app", host=host, port=int(port), workers=workers, use_colors=use_colors, factory=True)#
Modified g4f/cli.py +23 -11
@@ -1,7 +1,11 @@
1 from __future__ import annotations
2
1 3 import argparse
2 4
3 5 from g4f import Provider
4 6 from g4f.gui.run import gui_parser, run_gui_args
7 from g4f.cookies import read_cookie_files
8 from g4f import debug
5 9
6 10 def main():
7 11 parser = argparse.ArgumentParser(description="Run gpt4free")
@@ -10,28 +14,36 @@ def main():
10 14 api_parser.add_argument("--bind", default="0.0.0.0:1337", help="The bind string.")
11 15 api_parser.add_argument("--debug", action="store_true", help="Enable verbose logging.")
12 16 api_parser.add_argument("--workers", type=int, default=None, help="Number of workers.")
13 api_parser.add_argument("--disable_colors", action="store_true", help="Don't use colors.")
17 api_parser.add_argument("--disable-colors", action="store_true", help="Don't use colors.")
18 api_parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files.")
14 19 api_parser.add_argument("--ignored-providers", nargs="+", choices=[provider for provider in Provider.__map__],
15 20 default=[], help="List of providers to ignore when processing request.")
16 21 subparsers.add_parser("gui", parents=[gui_parser()], add_help=False)
17 22
18 23 args = parser.parse_args()
19 24 if args.mode == "api":
20 import g4f.api
21 g4f.api.api.set_list_ignored_providers(
22 args.ignored_providers
23 )
24 g4f.api.run_api(
25 bind=args.bind,
26 debug=args.debug,
27 workers=args.workers,
28 use_colors=not args.disable_colors
29 )
25 run_api_args(args)
30 26 elif args.mode == "gui":
31 27 run_gui_args(args)
32 28 else:
33 29 parser.print_help()
34 30 exit(1)
35 31
32 def run_api_args(args):
33 if args.debug:
34 debug.logging = True
35 if not args.ignore_cookie_files:
36 read_cookie_files()
37 import g4f.api
38 g4f.api.set_list_ignored_providers(
39 args.ignored_providers
40 )
41 g4f.api.run_api(
42 bind=args.bind,
43 debug=args.debug,
44 workers=args.workers,
45 use_colors=not args.disable_colors
46 )
47
36 48 if __name__ == "__main__":
37 49 main()
Modified g4f/cookies.py +58 -0
@@ -2,6 +2,7 @@ from __future__ import annotations
2 2
3 3 import os
4 4 import time
5 import json
5 6
6 7 try:
7 8 from platformdirs import user_config_dir
@@ -38,6 +39,7 @@ def get_cookies(domain_name: str = '', raise_requirements_error: bool = True, si
38 39 Returns:
39 40 Dict[str, str]: A dictionary of cookie names and values.
40 41 """
42 global _cookies
41 43 if domain_name in _cookies:
42 44 return _cookies[domain_name]
43 45
@@ -46,6 +48,7 @@ def get_cookies(domain_name: str = '', raise_requirements_error: bool = True, si
46 48 return cookies
47 49
48 50 def set_cookies(domain_name: str, cookies: Cookies = None) -> None:
51 global _cookies
49 52 if cookies:
50 53 _cookies[domain_name] = cookies
51 54 elif domain_name in _cookies:
@@ -84,6 +87,61 @@ def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool
84 87 print(f"Error reading cookies from {cookie_fn.__name__} for {domain_name}: {e}")
85 88 return cookies
86 89
90 def read_cookie_files(dirPath: str = "./har_and_cookies"):
91 global _cookies
92 harFiles = []
93 cookieFiles = []
94 for root, dirs, files in os.walk(dirPath):
95 for file in files:
96 if file.endswith(".har"):
97 harFiles.append(os.path.join(root, file))
98 elif file.endswith(".json"):
99 cookieFiles.append(os.path.join(root, file))
100 _cookies = {}
101 for path in harFiles:
102 with open(path, 'rb') as file:
103 try:
104 harFile = json.load(file)
105 except json.JSONDecodeError:
106 # Error: not a HAR file!
107 continue
108 if debug.logging:
109 print("Read .har file:", path)
110 new_cookies = {}
111 for v in harFile['log']['entries']:
112 v_cookies = {}
113 for c in v['request']['cookies']:
114 if c['domain'] not in v_cookies:
115 v_cookies[c['domain']] = {}
116 v_cookies[c['domain']][c['name']] = c['value']
117 for domain, c in v_cookies.items():
118 _cookies[domain] = c
119 new_cookies[domain] = len(c)
120 if debug.logging:
121 for domain, new_values in new_cookies.items():
122 print(f"Cookies added: {new_values} from {domain}")
123 for path in cookieFiles:
124 with open(path, 'rb') as file:
125 try:
126 cookieFile = json.load(file)
127 except json.JSONDecodeError:
128 # Error: not a json file!
129 continue
130 if not isinstance(cookieFile, list):
131 continue
132 if debug.logging:
133 print("Read cookie file:", path)
134 new_cookies = {}
135 for c in cookieFile:
136 if isinstance(c, dict) and "domain" in c:
137 if c["domain"] not in new_cookies:
138 new_cookies[c["domain"]] = {}
139 new_cookies[c["domain"]][c["name"]] = c["value"]
140 for domain, new_values in new_cookies.items():
141 if debug.logging:
142 print(f"Cookies added: {len(new_values)} from {domain}")
143 _cookies[domain] = new_values
144
87 145 def _g4f(domain_name: str) -> list:
88 146 """
89 147 Load cookies from the 'g4f' browser (if exists).
Modified g4f/gui/__init__.py +0 -3
@@ -12,9 +12,6 @@ def run_gui(host: str = '0.0.0.0', port: int = 8080, debug: bool = False) -> Non
12 12 if import_error is not None:
13 13 raise MissingRequirementsError(f'Install "gui" requirements | pip install -U g4f[gui]\n{import_error}')
14 14
15 if debug:
16 from g4f import debug
17 debug.logging = True
18 15 config = {
19 16 'host' : host,
20 17 'port' : port,
Modified g4f/gui/gui_parser.py +1 -0
@@ -5,4 +5,5 @@ def gui_parser():
5 5 parser.add_argument("-host", type=str, default="0.0.0.0", help="hostname")
6 6 parser.add_argument("-port", type=int, default=8080, help="port")
7 7 parser.add_argument("-debug", action="store_true", help="debug mode")
8 parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files.")
8 9 return parser
Modified g4f/gui/run.py +6 -0
Renamed har_and_cookies/.gitkeep +0 -0