返回提交历史
Modified
README.md
+22
-75
Modified
docs/client.md
+2
-1
Added
docs/guides/create_provider.md
+62
-0
Added
docs/guides/help_me.md
+106
-0
Deleted
docs/guides/phone.jpeg
+0
-0
Modified
docs/guides/phone.md
+2
-2
Modified
g4f/Provider/GeminiPro.py
+10
-9
Modified
g4f/__init__.py
+1
-1
XFEstudio/gpt4free
Add help me coding guide Add MissingAuthError in GeminiPro
775a0c43
代码差异
8 个文件
+205
-88
@@ -19,18 +19,20 @@ pip install -U g4f
19
19
docker pull hlohaus789/g4f
20
20
```
21
21
22
## 🆕 What's New 🚀
23
- How do I use my smartphone📱 to run g4f? [/docs/guides/phone](/docs/guides/phone.md)
22
## 🆕 What's New
23
- Guide: How do I use my smartphone📱to run g4f?
24
- [/docs/guides/phone](/docs/guides/phone.md)
25
- New: How can AI help me 💁with writing code?
26
- [/docs/guides/help_me](/docs/guides/help_me.md)
24
27
- Join our Telegram Channel: [t.me/g4f_channel](https://telegram.me/g4f_channel)
25
28
- Join our Discord Group: [discord.gg/XfybzPXPH5](https://discord.gg/XfybzPXPH5)
26
29
27
## Site Takedown
30
##🔻 Site Takedown
28
31
Is your site on this repository and you want to take it down ? email takedown@g4f.ai with proof it is yours and it will be removed as fast as possible. - to prevent reproduction please secure your api ; )
29
32
30
## Feedback
33
##🚀 Feedback and Todo
31
34
You can always leave some feedback here: https://forms.gle/FeWV9RLEedfdkmFN6
32
35
33
## To do
34
36
As per the survey, here is a list of improvements to come
35
37
- [x] update the repository to include the new openai library syntax (ex: `Openai()` class) | completed, use `g4f.client.Client`
36
38
- [ ] golang implementation
@@ -51,13 +53,13 @@ As per the survey, here is a list of improvements to come
51
53
- [Quick start](#quick-start)
52
54
+ [Use python](#use-python)
53
55
- [Prerequisites](#prerequisites)
54
- [Install using PyPI package:](#install-using-pypi-package-)
55
- [Install from source:](#install-from-source-)
56
- [Install using Docker:](#install-using-docker-)
56
- [Install using PyPI package:](#install-using-pypi-package)
57
- [Install from source:](#install-from-source)
58
- [Install using Docker:](#install-using-docker)
57
59
- [💡 Usage](#-usage)
58
* [The Web UI](#the-web-ui)
59
60
* [Text Generation](#text-generation)
60
61
* [Image Generation](#text-generation)
62
* [Web UI](#web-ui)
61
63
* [Interference API](#interference-api)
62
64
* [Configuration](#configuration)
63
65
- [🚀 Providers and Models](#-providers-and-models)
@@ -67,8 +69,8 @@ As per the survey, here is a list of improvements to come
67
69
* [Models](#models)
68
70
- [🔗 Related GPT4Free Projects](#-related-gpt4free-projects)
69
71
- [🤝 Contribute](#-contribute)
70
+ [Create Provider with AI Tool](#create-provider-with-ai-tool)
71
+ [Create Provider](#create-provider)
72
+ [How do i create a new Provider?](#guide-how-do-i-create-a-new-provider)
73
+ [How can AI help me with writing code?](#guide-how-can-ai-help-me-with-writing-code)
72
74
- [🙌 Contributors](#-contributors)
73
75
- [©️ Copyright](#-copyright)
74
76
- [⭐ Star History](#-star-history)
@@ -158,15 +160,13 @@ response = client.images.generate(
158
160
image_url = response.data[0].url
159
161
```
160
162
161
**Result:**
162
163
163
164
[](/docs/client.md)
164
165
165
**See also:**
166
167
- Documentation for the new Client API: [/docs/client](/docs/client.md)
168
- Documentation for the leagcy API: [/docs/leagcy](/docs/leagcy.md)
166
**Full Documentation for Python API**
169
167
168
- New Client API like the OpenAI Python library: [/docs/client](/docs/client.md)
169
- Leagcy API with python modules: [/docs/leagcy](/docs/leagcy.md)
170
170
171
171
#### Web UI
172
172
@@ -425,72 +425,19 @@ set G4F_PROXY=http://host:port
425
425
426
426
## 🤝 Contribute
427
427
428
#### Create Provider with AI Tool
429
430
Call in your terminal the `create_provider.py` script:
431
```bash
432
python etc/tool/create_provider.py
433
```
434
1. Enter your name for the new provider.
435
2. Copy and paste the `cURL` command from your browser developer tools.
436
3. Let the AI create the provider for you.
437
4. Customize the provider according to your needs.
438
439
#### Create Provider
440
441
1. Check out the current [list of potential providers](https://github.com/zukixa/cool-ai-stuff#ai-chat-websites), or find your own provider source!
442
2. Create a new file in [g4f/Provider](./g4f/Provider) with the name of the Provider
443
3. Implement a class that extends [BaseProvider](./g4f/Provider/base_provider.py).
444
445
```py
446
from __future__ import annotations
447
448
from ..typing import AsyncResult, Messages
449
from .base_provider import AsyncGeneratorProvider
450
451
class HogeService(AsyncGeneratorProvider):
452
url = "https://chat-gpt.com"
453
working = True
454
supports_gpt_35_turbo = True
455
456
@classmethod
457
async def create_async_generator(
458
cls,
459
model: str,
460
messages: Messages,
461
proxy: str = None,
462
**kwargs
463
) -> AsyncResult:
464
yield ""
465
```
466
467
4. Here, you can adjust the settings, for example, if the website does support streaming, set `supports_stream` to `True`...
468
5. Write code to request the provider in `create_async_generator` and `yield` the response, _even if_ it's a one-time response, do not hesitate to look at other providers for inspiration
469
6. Add the Provider Name in [`g4f/Provider/__init__.py`](./g4f/Provider/__init__.py)
470
471
```py
472
from .HogeService import HogeService
428
We welcome contributions from the community. Whether you're adding new providers or features, or simply fixing typos and making small improvements, your input is valued. Creating a pull request is all it takes – our co-pilot will handle the code review process. Once all changes have been addressed, we'll merge the pull request into the main branch and release the updates at a later time.
473
429
474
__all__ = [
475
HogeService,
476
]
477
```
430
###### Guide: How do i create a new Provider?
478
431
479
7. You are done !, test the provider by calling it:
432
- Read: [/docs/guides/create_provider](/docs/guides/create_provider.md)
480
433
481
```py
482
import g4f
434
###### Guide: How can AI help me with writing code?
483
435
484
response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.PROVIDERNAME,
485
messages=[{"role": "user", "content": "test"}], stream=g4f.Provider.PROVIDERNAME.supports_stream)
486
487
for message in response:
488
print(message, flush=True, end='')
489
```
436
- Read: [/docs/guides/help_me](/docs/guides/help_me.md)
490
437
491
438
## 🙌 Contributors
492
439
493
A list of the contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
440
A list of all contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
494
441
The [`Vercel.py`](https://github.com/xtekky/gpt4free/blob/main/g4f/Provider/Vercel.py) file contains code from [vercel-llm-api](https://github.com/ading2210/vercel-llm-api) by [@ading2210](https://github.com/ading2210), which is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
495
442
Top 1 Contributor: [@hlohaus](https://github.com/hlohaus)
496
443
@@ -154,10 +154,11 @@ response = client.chat.completions.create(
154
154
)
155
155
print(response.choices[0].message.content)
156
156
```
157

158
157
```
159
158
User: What are on this image?
160
159
```
160

161
161
162
```
162
163
Bot: There is a waterfall in the middle of a jungle. There is a rainbow over...
163
164
```
@@ -0,0 +1,62 @@
1
#### Create Provider with AI Tool
2
3
Call in your terminal the `create_provider` script:
4
```bash
5
python -m etc.tool.create_provider
6
```
7
1. Enter your name for the new provider.
8
2. Copy and paste the `cURL` command from your browser developer tools.
9
3. Let the AI create the provider for you.
10
4. Customize the provider according to your needs.
11
12
#### Create Provider
13
14
1. Check out the current [list of potential providers](https://github.com/zukixa/cool-ai-stuff#ai-chat-websites), or find your own provider source!
15
2. Create a new file in [g4f/Provider](/g4f/Provider) with the name of the Provider
16
3. Implement a class that extends [BaseProvider](/g4f/providers/base_provider.py).
17
18
```py
19
from __future__ import annotations
20
21
from ..typing import AsyncResult, Messages
22
from .base_provider import AsyncGeneratorProvider
23
24
class HogeService(AsyncGeneratorProvider):
25
url = "https://chat-gpt.com"
26
working = True
27
supports_gpt_35_turbo = True
28
29
@classmethod
30
async def create_async_generator(
31
cls,
32
model: str,
33
messages: Messages,
34
proxy: str = None,
35
**kwargs
36
) -> AsyncResult:
37
yield ""
38
```
39
40
4. Here, you can adjust the settings, for example, if the website does support streaming, set `supports_stream` to `True`...
41
5. Write code to request the provider in `create_async_generator` and `yield` the response, _even if_ it's a one-time response, do not hesitate to look at other providers for inspiration
42
6. Add the Provider Import in [`g4f/Provider/__init__.py`](./g4f/Provider/__init__.py)
43
44
```py
45
from .HogeService import HogeService
46
47
__all__ = [
48
HogeService,
49
]
50
```
51
52
7. You are done !, test the provider by calling it:
53
54
```py
55
import g4f
56
57
response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.PROVIDERNAME,
58
messages=[{"role": "user", "content": "test"}], stream=g4f.Provider.PROVIDERNAME.supports_stream)
59
60
for message in response:
61
print(message, flush=True, end='')
62
```
@@ -0,0 +1,106 @@
1
### Guide: How can AI help me with writing code?
2
3
🤖 Ever dreamt of writing code at lightning speed, effortlessly crafting clean, bug-free functionalities? Welcome to the age of AI-powered coding, where your imagination merges seamlessly with the machine's precision. This guide unveils 4 powerful ways AI can become your secret weapon in the coding world, saving you time, resources, and frustration. 😎
4
5
- Language Agnostic? No Problem! Rewrite Code with Ease
6
- Improving Written Code: Polish Your Code Like a Pro
7
- Demystifying the Unreadable: Deobfuscating Unreadable Code
8
- Custom Functions: Your AI-Powered Genie in a Bottle
9
10
So you can streamline your coding process, improve code quality, and enhance productivity.
11
12
#### 1. Rewriting Code from One Language to Another
13
You can leverage AI to translate code from one programming language to another. For instance, you can easily convert JavaScript code to Python using the following approach:
14
15
**Prompt:**
16
```
17
Rewrite this JavaScript code to Python code. Use the aiohttp package:
18
```
19
```javascript
20
async function fetch_data(url) {
21
const response = await fetch(url);
22
const data = await response.json();
23
return data;
24
}
25
```
26
27
**AI Response:**
28
```python
29
import aiohttp
30
31
async def fetch_data(url):
32
async with aiohttp.ClientSession() as session:
33
async with session.get(url) as response:
34
data = await response.json()
35
return data
36
```
37
38
#### 2. Improving Written Code
39
You can ask the AI to enhance your code by adding comments, docstrings, and type hints for better readability and maintainability.
40
41
**Example Usage:**
42
```
43
Improve this Python code, add Google docstrings and type hints.
44
Responses with the complete code and don't use placeholders.
45
Keep the comments:
46
```
47
```python
48
def calculate_area(radius):
49
# Calculate the area of a circle
50
return 3.14 * radius ** 2
51
```
52
53
**AI Response:**
54
```python
55
def calculate_area(radius: float) -> float:
56
"""Calculate the area of a circle.
57
58
Args:
59
radius (float): The radius of the circle.
60
61
Returns:
62
float: The area of the circle.
63
"""
64
return 3.14 * radius ** 2
65
```
66
67
#### 3. Deobfuscating Unreadable Code
68
AI can help in making obfuscated or unreadable code more understandable and maintainable.
69
70
**Example Usage:**
71
```
72
Deobfuscate this JavaScript code. Improve the readability:
73
```
74
75
```javascript
76
(function() {
77
var a = 'Hello', b = 'World';
78
console.log(a + ' ' + b);
79
})();
80
```
81
82
**AI Response:**
83
```javascript
84
(function() {
85
var greeting = 'Hello';
86
var subject = 'World';
87
console.log(greeting + ' ' + subject);
88
})();
89
```
90
91
#### 4. Writing Custom Functions
92
You can also ask the AI to generate custom functions or help you with specific coding issues.
93
94
**Example Usage:**
95
```
96
Write a function that returns the sum of two numbers.
97
```
98
99
**AI Response:**
100
```python
101
def add_numbers(a, b):
102
"""Add two numbers together."""
103
return a + b
104
```
105
106
These are just a few ways AI can revolutionize your coding experience. As AI technology continues to evolve, the possibilities are endless. So, embrace the future, unlock the power of AI, and watch your coding potential soar! 👷♂️
二进制文件已变更,无法进行逐行预览。
@@ -21,9 +21,9 @@ Running Python applications on your smartphone is possible with specialized apps
21
21
- In the app settings for Pydroid, disable power-saving mode and ensure that the option to pause when not in use is also disabled. This ensures uninterrupted operation of your Python scripts.
22
22
23
23
4. **Install Required Packages:**
24
- Open Pip within the Pydroid app and install the necessary packages by executing the following commands:
24
- Open Pip within the Pydroid app and install this necessary packages:
25
25
```
26
pip install g4f flask pillow beautifulsoup4
26
g4f flask pillow beautifulsoup4
27
27
```
28
28
29
29
5. **Create a New Python Script:**
@@ -7,7 +7,7 @@ from aiohttp import ClientSession
7
7
from ..typing import AsyncResult, Messages, ImageType
8
8
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
9
9
from ..image import to_bytes, is_accepted_format
10
10
from ..errors import MissingAuthError
11
11
12
12
class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
13
13
url = "https://ai.google.dev"
@@ -29,7 +29,8 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
29
29
) -> AsyncResult:
30
30
model = "gemini-pro-vision" if not model and image else model
31
31
model = cls.get_model(model)
32
api_key = api_key if api_key else kwargs.get("access_token")
32
if not api_key:
33
raise MissingAuthError('Missing "api_key" for auth')
33
34
headers = {
34
35
"Content-Type": "application/json",
35
36
}
@@ -53,13 +54,13 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
53
54
})
54
55
data = {
55
56
"contents": contents,
56
# "generationConfig": {
57
# "stopSequences": kwargs.get("stop"),
58
# "temperature": kwargs.get("temperature"),
59
# "maxOutputTokens": kwargs.get("max_tokens"),
60
# "topP": kwargs.get("top_p"),
61
# "topK": kwargs.get("top_k"),
62
# }
57
"generationConfig": {
58
"stopSequences": kwargs.get("stop"),
59
"temperature": kwargs.get("temperature"),
60
"maxOutputTokens": kwargs.get("max_tokens"),
61
"topP": kwargs.get("top_p"),
62
"topK": kwargs.get("top_k"),
63
}
63
64
}
64
65
async with session.post(url, params={"key": api_key}, json=data, proxy=proxy) as response:
65
66
if not response.ok:
@@ -42,7 +42,7 @@ def get_model_and_provider(model : Union[Model, str],
42
42
if debug.version_check:
43
43
debug.version_check = False
44
44
version.utils.check_version()
45
45
46
46
if isinstance(provider, str):
47
47
if " " in provider:
48
48
provider_list = [ProviderUtils.convert[p] for p in provider.split() if p in ProviderUtils.convert]