From cbfa5ee7e9a5e224a032f19dfc770f6208d14b29 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 24 Feb 2024 02:07:01 +0100 Subject: Fix some typos --- README.md | 8 +-- docs/guides/phone.md | 2 +- docs/leagcy.md | 200 --------------------------------------------------- docs/legacy.md | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 205 deletions(-) delete mode 100644 docs/leagcy.md create mode 100644 docs/legacy.md diff --git a/README.md b/README.md index 4966620c..59ad89f3 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,10 @@ docker pull hlohaus789/g4f - 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 and Todo +## 🚀 Feedback and Todo You can always leave some feedback here: https://forms.gle/FeWV9RLEedfdkmFN6 As per the survey, here is a list of improvements to come @@ -58,7 +58,7 @@ As per the survey, here is a list of improvements to come - [Install using Docker:](#install-using-docker) - [💡 Usage](#-usage) * [Text Generation](#text-generation) - * [Image Generation](#text-generation) + * [Image Generation](#image-generation) * [Web UI](#web-ui) * [Interference API](#interference-api) * [Configuration](#configuration) @@ -166,7 +166,7 @@ image_url = response.data[0].url **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) +- Legacy API with python modules: [/docs/legacy](/docs/legacy.md) #### Web UI diff --git a/docs/guides/phone.md b/docs/guides/phone.md index 60a09e9d..ae9865cd 100644 --- a/docs/guides/phone.md +++ b/docs/guides/phone.md @@ -21,7 +21,7 @@ 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 this necessary packages: + - Open Pip within the Pydroid app and install these necessary packages: ``` g4f flask pillow beautifulsoup4 ``` diff --git a/docs/leagcy.md b/docs/leagcy.md deleted file mode 100644 index e8808381..00000000 --- a/docs/leagcy.md +++ /dev/null @@ -1,200 +0,0 @@ -### G4F - Leagcy API - -#### ChatCompletion - -```python -import g4f - -g4f.debug.logging = True # Enable debug logging -g4f.debug.version_check = False # Disable automatic version checking -print(g4f.Provider.Bing.params) # Print supported args for Bing - -# Using automatic a provider for the given model -## Streamed completion -response = g4f.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[{"role": "user", "content": "Hello"}], - stream=True, -) -for message in response: - print(message, flush=True, end='') - -## Normal response -response = g4f.ChatCompletion.create( - model=g4f.models.gpt_4, - messages=[{"role": "user", "content": "Hello"}], -) # Alternative model setting - -print(response) -``` - -##### Completion - -```python -import g4f - -allowed_models = [ - 'code-davinci-002', - 'text-ada-001', - 'text-babbage-001', - 'text-curie-001', - 'text-davinci-002', - 'text-davinci-003' -] - -response = g4f.Completion.create( - model='text-davinci-003', - prompt='say this is a test' -) - -print(response) -``` - -##### Providers - -```python -import g4f - -# Print all available providers -print([ - provider.__name__ - for provider in g4f.Provider.__providers__ - if provider.working -]) - -# Execute with a specific provider -response = g4f.ChatCompletion.create( - model="gpt-3.5-turbo", - provider=g4f.Provider.Aichat, - messages=[{"role": "user", "content": "Hello"}], - stream=True, -) -for message in response: - print(message) -``` - - -##### Image Upload & Generation - -Image upload and generation are supported by three main providers: - -- **Bing & Other GPT-4 Providers:** Utilizes Microsoft's Image Creator. -- **Google Gemini:** Available for free accounts with IP addresses outside Europe. -- **OpenaiChat with GPT-4:** Accessible for users with a Plus subscription. - -```python -import g4f - -# Setting up the request for image creation -response = g4f.ChatCompletion.create( - model=g4f.models.default, # Using the default model - provider=g4f.Provider.Gemini, # Specifying the provider as Gemini - messages=[{"role": "user", "content": "Create an image like this"}], - image=open("images/g4f.png", "rb"), # Image input can be a data URI, bytes, PIL Image, or IO object - image_name="g4f.png" # Optional: specifying the filename -) - -# Displaying the response -print(response) - -from g4f.image import ImageResponse - -# Get image links from response -for chunk in g4f.ChatCompletion.create( - model=g4f.models.default, # Using the default model - provider=g4f.Provider.OpenaiChat, # Specifying the provider as OpenaiChat - messages=[{"role": "user", "content": "Create images with dogs"}], - access_token="...", # Need a access token from a plus user - stream=True, - ignore_stream=True -): - if isinstance(chunk, ImageResponse): - print(chunk.images) # Print generated image links - print(chunk.alt) # Print used prompt for image generation -``` - -##### Using Browser - -Some providers using a browser to bypass the bot protection. They using the selenium webdriver to control the browser. The browser settings and the login data are saved in a custom directory. If the headless mode is enabled, the browser windows are loaded invisibly. For performance reasons, it is recommended to reuse the browser instances and close them yourself at the end: - -```python -import g4f -from undetected_chromedriver import Chrome, ChromeOptions -from g4f.Provider import ( - Bard, - Poe, - AItianhuSpace, - MyShell, - PerplexityAi, -) - -options = ChromeOptions() -options.add_argument("--incognito"); -webdriver = Chrome(options=options, headless=True) -for idx in range(10): - response = g4f.ChatCompletion.create( - model=g4f.models.default, - provider=g4f.Provider.MyShell, - messages=[{"role": "user", "content": "Suggest me a name."}], - webdriver=webdriver - ) - print(f"{idx}:", response) -webdriver.quit() -``` - -##### Async Support - -To enhance speed and overall performance, execute providers asynchronously. The total execution time will be determined by the duration of the slowest provider's execution. - -```python -import g4f -import asyncio - -_providers = [ - g4f.Provider.Aichat, - g4f.Provider.ChatBase, - g4f.Provider.Bing, - g4f.Provider.GptGo, - g4f.Provider.You, - g4f.Provider.Yqcloud, -] - -async def run_provider(provider: g4f.Provider.BaseProvider): - try: - response = await g4f.ChatCompletion.create_async( - model=g4f.models.default, - messages=[{"role": "user", "content": "Hello"}], - provider=provider, - ) - print(f"{provider.__name__}:", response) - except Exception as e: - print(f"{provider.__name__}:", e) - -async def run_all(): - calls = [ - run_provider(provider) for provider in _providers - ] - await asyncio.gather(*calls) - -asyncio.run(run_all()) -``` - -##### Proxy and Timeout Support - -All providers support specifying a proxy and increasing timeout in the create functions. - -```python -import g4f - -response = g4f.ChatCompletion.create( - model=g4f.models.default, - messages=[{"role": "user", "content": "Hello"}], - proxy="http://host:port", - # or socks5://user:pass@host:port - timeout=120, # in secs -) - -print(f"Result:", response) -``` - -[Return to Home](/) \ No newline at end of file diff --git a/docs/legacy.md b/docs/legacy.md new file mode 100644 index 00000000..d5cd5a36 --- /dev/null +++ b/docs/legacy.md @@ -0,0 +1,200 @@ +### G4F - Legacy API + +#### ChatCompletion + +```python +import g4f + +g4f.debug.logging = True # Enable debug logging +g4f.debug.version_check = False # Disable automatic version checking +print(g4f.Provider.Bing.params) # Print supported args for Bing + +# Using automatic a provider for the given model +## Streamed completion +response = g4f.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "Hello"}], + stream=True, +) +for message in response: + print(message, flush=True, end='') + +## Normal response +response = g4f.ChatCompletion.create( + model=g4f.models.gpt_4, + messages=[{"role": "user", "content": "Hello"}], +) # Alternative model setting + +print(response) +``` + +##### Completion + +```python +import g4f + +allowed_models = [ + 'code-davinci-002', + 'text-ada-001', + 'text-babbage-001', + 'text-curie-001', + 'text-davinci-002', + 'text-davinci-003' +] + +response = g4f.Completion.create( + model='text-davinci-003', + prompt='say this is a test' +) + +print(response) +``` + +##### Providers + +```python +import g4f + +# Print all available providers +print([ + provider.__name__ + for provider in g4f.Provider.__providers__ + if provider.working +]) + +# Execute with a specific provider +response = g4f.ChatCompletion.create( + model="gpt-3.5-turbo", + provider=g4f.Provider.Aichat, + messages=[{"role": "user", "content": "Hello"}], + stream=True, +) +for message in response: + print(message) +``` + + +##### Image Upload & Generation + +Image upload and generation are supported by three main providers: + +- **Bing & Other GPT-4 Providers:** Utilizes Microsoft's Image Creator. +- **Google Gemini:** Available for free accounts with IP addresses outside Europe. +- **OpenaiChat with GPT-4:** Accessible for users with a Plus subscription. + +```python +import g4f + +# Setting up the request for image creation +response = g4f.ChatCompletion.create( + model=g4f.models.default, # Using the default model + provider=g4f.Provider.Gemini, # Specifying the provider as Gemini + messages=[{"role": "user", "content": "Create an image like this"}], + image=open("images/g4f.png", "rb"), # Image input can be a data URI, bytes, PIL Image, or IO object + image_name="g4f.png" # Optional: specifying the filename +) + +# Displaying the response +print(response) + +from g4f.image import ImageResponse + +# Get image links from response +for chunk in g4f.ChatCompletion.create( + model=g4f.models.default, # Using the default model + provider=g4f.Provider.OpenaiChat, # Specifying the provider as OpenaiChat + messages=[{"role": "user", "content": "Create images with dogs"}], + access_token="...", # Need a access token from a plus user + stream=True, + ignore_stream=True +): + if isinstance(chunk, ImageResponse): + print(chunk.images) # Print generated image links + print(chunk.alt) # Print used prompt for image generation +``` + +##### Using Browser + +Some providers using a browser to bypass the bot protection. They using the selenium webdriver to control the browser. The browser settings and the login data are saved in a custom directory. If the headless mode is enabled, the browser windows are loaded invisibly. For performance reasons, it is recommended to reuse the browser instances and close them yourself at the end: + +```python +import g4f +from undetected_chromedriver import Chrome, ChromeOptions +from g4f.Provider import ( + Bard, + Poe, + AItianhuSpace, + MyShell, + PerplexityAi, +) + +options = ChromeOptions() +options.add_argument("--incognito"); +webdriver = Chrome(options=options, headless=True) +for idx in range(10): + response = g4f.ChatCompletion.create( + model=g4f.models.default, + provider=g4f.Provider.MyShell, + messages=[{"role": "user", "content": "Suggest me a name."}], + webdriver=webdriver + ) + print(f"{idx}:", response) +webdriver.quit() +``` + +##### Async Support + +To enhance speed and overall performance, execute providers asynchronously. The total execution time will be determined by the duration of the slowest provider's execution. + +```python +import g4f +import asyncio + +_providers = [ + g4f.Provider.Aichat, + g4f.Provider.ChatBase, + g4f.Provider.Bing, + g4f.Provider.GptGo, + g4f.Provider.You, + g4f.Provider.Yqcloud, +] + +async def run_provider(provider: g4f.Provider.BaseProvider): + try: + response = await g4f.ChatCompletion.create_async( + model=g4f.models.default, + messages=[{"role": "user", "content": "Hello"}], + provider=provider, + ) + print(f"{provider.__name__}:", response) + except Exception as e: + print(f"{provider.__name__}:", e) + +async def run_all(): + calls = [ + run_provider(provider) for provider in _providers + ] + await asyncio.gather(*calls) + +asyncio.run(run_all()) +``` + +##### Proxy and Timeout Support + +All providers support specifying a proxy and increasing timeout in the create functions. + +```python +import g4f + +response = g4f.ChatCompletion.create( + model=g4f.models.default, + messages=[{"role": "user", "content": "Hello"}], + proxy="http://host:port", + # or socks5://user:pass@host:port + timeout=120, # in secs +) + +print(f"Result:", response) +``` + +[Return to Home](/) \ No newline at end of file -- cgit v1.2.3