summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-24 01:31:17 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-24 01:31:17 +0100
commit775a0c43a0856f57dbd847a73b9d20b7cddb5063 (patch)
treee0f7071a2f359ad37ec7ce762b89194d4ba92e19
parentSet default values for generation config (diff)
downloadgpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar.gz
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar.bz2
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar.lz
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar.xz
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.tar.zst
gpt4free-775a0c43a0856f57dbd847a73b9d20b7cddb5063.zip
-rw-r--r--README.md97
-rw-r--r--docs/client.md3
-rw-r--r--docs/guides/create_provider.md62
-rw-r--r--docs/guides/help_me.md106
-rw-r--r--docs/guides/phone.jpegbin13405 -> 0 bytes
-rw-r--r--docs/guides/phone.md4
-rw-r--r--g4f/Provider/GeminiPro.py19
-rw-r--r--g4f/__init__.py2
8 files changed, 205 insertions, 88 deletions
diff --git a/README.md b/README.md
index 17aaaeb4..4966620c 100644
--- a/README.md
+++ b/README.md
@@ -19,18 +19,20 @@ pip install -U g4f
docker pull hlohaus789/g4f
```
-## ๐Ÿ†• What's New ๐Ÿš€
-- How do I use my smartphone๐Ÿ“ฑ to run g4f? [/docs/guides/phone](/docs/guides/phone.md)
+## ๐Ÿ†• What's New
+- Guide: How do I use my smartphone๐Ÿ“ฑto run g4f?
+ - [/docs/guides/phone](/docs/guides/phone.md)
+- New: How can AI help me ๐Ÿ’with writing code?
+ - [/docs/guides/help_me](/docs/guides/help_me.md)
- Join our Telegram Channel: [t.me/g4f_channel](https://telegram.me/g4f_channel)
- Join our Discord Group: [discord.gg/XfybzPXPH5](https://discord.gg/XfybzPXPH5)
-## Site Takedown
+##๐Ÿ”ป Site Takedown
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 ; )
-## Feedback
+##๐Ÿš€ Feedback and Todo
You can always leave some feedback here: https://forms.gle/FeWV9RLEedfdkmFN6
-## To do
As per the survey, here is a list of improvements to come
- [x] update the repository to include the new openai library syntax (ex: `Openai()` class) | completed, use `g4f.client.Client`
- [ ] golang implementation
@@ -51,13 +53,13 @@ As per the survey, here is a list of improvements to come
- [Quick start](#quick-start)
+ [Use python](#use-python)
- [Prerequisites](#prerequisites)
- - [Install using PyPI package:](#install-using-pypi-package-)
- - [Install from source:](#install-from-source-)
- - [Install using Docker:](#install-using-docker-)
+ - [Install using PyPI package:](#install-using-pypi-package)
+ - [Install from source:](#install-from-source)
+ - [Install using Docker:](#install-using-docker)
- [๐Ÿ’ก Usage](#-usage)
- * [The Web UI](#the-web-ui)
* [Text Generation](#text-generation)
* [Image Generation](#text-generation)
+ * [Web UI](#web-ui)
* [Interference API](#interference-api)
* [Configuration](#configuration)
- [๐Ÿš€ Providers and Models](#-providers-and-models)
@@ -67,8 +69,8 @@ As per the survey, here is a list of improvements to come
* [Models](#models)
- [๐Ÿ”— Related GPT4Free Projects](#-related-gpt4free-projects)
- [๐Ÿค Contribute](#-contribute)
- + [Create Provider with AI Tool](#create-provider-with-ai-tool)
- + [Create Provider](#create-provider)
+ + [How do i create a new Provider?](#guide-how-do-i-create-a-new-provider)
+ + [How can AI help me with writing code?](#guide-how-can-ai-help-me-with-writing-code)
- [๐Ÿ™Œ Contributors](#-contributors)
- [ยฉ๏ธ Copyright](#-copyright)
- [โญ Star History](#-star-history)
@@ -158,15 +160,13 @@ response = client.images.generate(
image_url = response.data[0].url
```
-**Result:**
[![Image with cat](/docs/cat.jpeg)](/docs/client.md)
-**See also:**
-
-- Documentation for the new Client API: [/docs/client](/docs/client.md)
-- Documentation for the leagcy API: [/docs/leagcy](/docs/leagcy.md)
+**Full Documentation for Python API**
+- New Client API like the OpenAI Python library: [/docs/client](/docs/client.md)
+- Leagcy API with python modules: [/docs/leagcy](/docs/leagcy.md)
#### Web UI
@@ -425,72 +425,19 @@ set G4F_PROXY=http://host:port
## ๐Ÿค Contribute
-#### Create Provider with AI Tool
-
-Call in your terminal the `create_provider.py` script:
-```bash
-python etc/tool/create_provider.py
-```
-1. Enter your name for the new provider.
-2. Copy and paste the `cURL` command from your browser developer tools.
-3. Let the AI โ€‹โ€‹create the provider for you.
-4. Customize the provider according to your needs.
-
-#### Create Provider
-
-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!
-2. Create a new file in [g4f/Provider](./g4f/Provider) with the name of the Provider
-3. Implement a class that extends [BaseProvider](./g4f/Provider/base_provider.py).
-
-```py
-from __future__ import annotations
-
-from ..typing import AsyncResult, Messages
-from .base_provider import AsyncGeneratorProvider
-
-class HogeService(AsyncGeneratorProvider):
- url = "https://chat-gpt.com"
- working = True
- supports_gpt_35_turbo = True
-
- @classmethod
- async def create_async_generator(
- cls,
- model: str,
- messages: Messages,
- proxy: str = None,
- **kwargs
- ) -> AsyncResult:
- yield ""
-```
-
-4. Here, you can adjust the settings, for example, if the website does support streaming, set `supports_stream` to `True`...
-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
-6. Add the Provider Name in [`g4f/Provider/__init__.py`](./g4f/Provider/__init__.py)
-
-```py
-from .HogeService import HogeService
+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.
-__all__ = [
- HogeService,
-]
-```
+###### Guide: How do i create a new Provider?
-7. You are done !, test the provider by calling it:
+ - Read: [/docs/guides/create_provider](/docs/guides/create_provider.md)
-```py
-import g4f
+###### Guide: How can AI help me with writing code?
-response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.PROVIDERNAME,
- messages=[{"role": "user", "content": "test"}], stream=g4f.Provider.PROVIDERNAME.supports_stream)
-
-for message in response:
- print(message, flush=True, end='')
-```
+ - Read: [/docs/guides/help_me](/docs/guides/help_me.md)
## ๐Ÿ™Œ Contributors
-A list of the contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
+A list of all contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
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)
Top 1 Contributor: [@hlohaus](https://github.com/hlohaus)
diff --git a/docs/client.md b/docs/client.md
index fe02dc92..31440027 100644
--- a/docs/client.md
+++ b/docs/client.md
@@ -154,10 +154,11 @@ response = client.chat.completions.create(
)
print(response.choices[0].message.content)
```
-![Waterfall](/docs/waterfall.jpeg)
```
User: What are on this image?
```
+![Waterfall](/docs/waterfall.jpeg)
+
```
Bot: There is a waterfall in the middle of a jungle. There is a rainbow over...
```
diff --git a/docs/guides/create_provider.md b/docs/guides/create_provider.md
new file mode 100644
index 00000000..e2e1ab6a
--- /dev/null
+++ b/docs/guides/create_provider.md
@@ -0,0 +1,62 @@
+#### Create Provider with AI Tool
+
+Call in your terminal the `create_provider` script:
+```bash
+python -m etc.tool.create_provider
+```
+1. Enter your name for the new provider.
+2. Copy and paste the `cURL` command from your browser developer tools.
+3. Let the AI โ€‹โ€‹create the provider for you.
+4. Customize the provider according to your needs.
+
+#### Create Provider
+
+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!
+2. Create a new file in [g4f/Provider](/g4f/Provider) with the name of the Provider
+3. Implement a class that extends [BaseProvider](/g4f/providers/base_provider.py).
+
+```py
+from __future__ import annotations
+
+from ..typing import AsyncResult, Messages
+from .base_provider import AsyncGeneratorProvider
+
+class HogeService(AsyncGeneratorProvider):
+ url = "https://chat-gpt.com"
+ working = True
+ supports_gpt_35_turbo = True
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncResult:
+ yield ""
+```
+
+4. Here, you can adjust the settings, for example, if the website does support streaming, set `supports_stream` to `True`...
+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
+6. Add the Provider Import in [`g4f/Provider/__init__.py`](./g4f/Provider/__init__.py)
+
+```py
+from .HogeService import HogeService
+
+__all__ = [
+ HogeService,
+]
+```
+
+7. You are done !, test the provider by calling it:
+
+```py
+import g4f
+
+response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.PROVIDERNAME,
+ messages=[{"role": "user", "content": "test"}], stream=g4f.Provider.PROVIDERNAME.supports_stream)
+
+for message in response:
+ print(message, flush=True, end='')
+``` \ No newline at end of file
diff --git a/docs/guides/help_me.md b/docs/guides/help_me.md
new file mode 100644
index 00000000..1a56a74a
--- /dev/null
+++ b/docs/guides/help_me.md
@@ -0,0 +1,106 @@
+### Guide: How can AI help me with writing code?
+
+๐Ÿค– 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. ๐Ÿ˜Ž
+
+- Language Agnostic? No Problem! Rewrite Code with Ease
+- Improving Written Code: Polish Your Code Like a Pro
+- Demystifying the Unreadable: Deobfuscating Unreadable Code
+- Custom Functions: Your AI-Powered Genie in a Bottle
+
+So you can streamline your coding process, improve code quality, and enhance productivity.
+
+#### 1. Rewriting Code from One Language to Another
+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:
+
+**Prompt:**
+```
+Rewrite this JavaScript code to Python code. Use the aiohttp package:
+```
+```javascript
+async function fetch_data(url) {
+ const response = await fetch(url);
+ const data = await response.json();
+ return data;
+}
+```
+
+**AI Response:**
+```python
+import aiohttp
+
+async def fetch_data(url):
+ async with aiohttp.ClientSession() as session:
+ async with session.get(url) as response:
+ data = await response.json()
+ return data
+```
+
+#### 2. Improving Written Code
+You can ask the AI to enhance your code by adding comments, docstrings, and type hints for better readability and maintainability.
+
+**Example Usage:**
+```
+Improve this Python code, add Google docstrings and type hints.
+Responses with the complete code and don't use placeholders.
+Keep the comments:
+```
+```python
+def calculate_area(radius):
+ # Calculate the area of a circle
+ return 3.14 * radius ** 2
+```
+
+**AI Response:**
+```python
+def calculate_area(radius: float) -> float:
+ """Calculate the area of a circle.
+
+ Args:
+ radius (float): The radius of the circle.
+
+ Returns:
+ float: The area of the circle.
+ """
+ return 3.14 * radius ** 2
+```
+
+#### 3. Deobfuscating Unreadable Code
+AI can help in making obfuscated or unreadable code more understandable and maintainable.
+
+**Example Usage:**
+```
+Deobfuscate this JavaScript code. Improve the readability:
+```
+
+```javascript
+(function() {
+ var a = 'Hello', b = 'World';
+ console.log(a + ' ' + b);
+})();
+```
+
+**AI Response:**
+```javascript
+(function() {
+ var greeting = 'Hello';
+ var subject = 'World';
+ console.log(greeting + ' ' + subject);
+})();
+```
+
+#### 4. Writing Custom Functions
+You can also ask the AI to generate custom functions or help you with specific coding issues.
+
+**Example Usage:**
+```
+Write a function that returns the sum of two numbers.
+```
+
+**AI Response:**
+```python
+def add_numbers(a, b):
+ """Add two numbers together."""
+ return a + b
+```
+
+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! ๐Ÿ‘ทโ€โ™‚๏ธ \ No newline at end of file
diff --git a/docs/guides/phone.jpeg b/docs/guides/phone.jpeg
deleted file mode 100644
index 0cc57b14..00000000
--- a/docs/guides/phone.jpeg
+++ /dev/null
Binary files differ
diff --git a/docs/guides/phone.md b/docs/guides/phone.md
index 2d3ec032..60a09e9d 100644
--- a/docs/guides/phone.md
+++ b/docs/guides/phone.md
@@ -21,9 +21,9 @@ Running Python applications on your smartphone is possible with specialized apps
- 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.
4. **Install Required Packages:**
- - Open Pip within the Pydroid app and install the necessary packages by executing the following commands:
+ - Open Pip within the Pydroid app and install this necessary packages:
```
- pip install g4f flask pillow beautifulsoup4
+ g4f flask pillow beautifulsoup4
```
5. **Create a New Python Script:**
diff --git a/g4f/Provider/GeminiPro.py b/g4f/Provider/GeminiPro.py
index b296f253..e1738dc8 100644
--- a/g4f/Provider/GeminiPro.py
+++ b/g4f/Provider/GeminiPro.py
@@ -7,7 +7,7 @@ from aiohttp import ClientSession
from ..typing import AsyncResult, Messages, ImageType
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from ..image import to_bytes, is_accepted_format
-
+from ..errors import MissingAuthError
class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
url = "https://ai.google.dev"
@@ -29,7 +29,8 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
) -> AsyncResult:
model = "gemini-pro-vision" if not model and image else model
model = cls.get_model(model)
- api_key = api_key if api_key else kwargs.get("access_token")
+ if not api_key:
+ raise MissingAuthError('Missing "api_key" for auth')
headers = {
"Content-Type": "application/json",
}
@@ -53,13 +54,13 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
})
data = {
"contents": contents,
- # "generationConfig": {
- # "stopSequences": kwargs.get("stop"),
- # "temperature": kwargs.get("temperature"),
- # "maxOutputTokens": kwargs.get("max_tokens"),
- # "topP": kwargs.get("top_p"),
- # "topK": kwargs.get("top_k"),
- # }
+ "generationConfig": {
+ "stopSequences": kwargs.get("stop"),
+ "temperature": kwargs.get("temperature"),
+ "maxOutputTokens": kwargs.get("max_tokens"),
+ "topP": kwargs.get("top_p"),
+ "topK": kwargs.get("top_k"),
+ }
}
async with session.post(url, params={"key": api_key}, json=data, proxy=proxy) as response:
if not response.ok:
diff --git a/g4f/__init__.py b/g4f/__init__.py
index 6716c727..5df942ae 100644
--- a/g4f/__init__.py
+++ b/g4f/__init__.py
@@ -42,7 +42,7 @@ def get_model_and_provider(model : Union[Model, str],
if debug.version_check:
debug.version_check = False
version.utils.check_version()
-
+
if isinstance(provider, str):
if " " in provider:
provider_list = [ProviderUtils.convert[p] for p in provider.split() if p in ProviderUtils.convert]