From 7953560303ad82f13f3d4c910db1193da21b11d7 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 23 Feb 2024 17:21:10 +0100 Subject: Improve readme, add smartphone guide --- docs/client.md | 41 +++++++++++++++++++++++++++++++-------- docs/guides/phone.jpeg | Bin 0 -> 13405 bytes docs/guides/phone.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/guides/phone.png | Bin 0 -> 90405 bytes docs/guides/phone2.jpeg | Bin 0 -> 21714 bytes docs/waterfall.jpeg | Bin 0 -> 8246 bytes 6 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 docs/guides/phone.jpeg create mode 100644 docs/guides/phone.md create mode 100644 docs/guides/phone.png create mode 100644 docs/guides/phone2.jpeg create mode 100644 docs/waterfall.jpeg (limited to 'docs') diff --git a/docs/client.md b/docs/client.md index 7d3cad11..fe02dc92 100644 --- a/docs/client.md +++ b/docs/client.md @@ -1,4 +1,4 @@ -### G4F - Client API (Beta Version) +### G4F - Client API #### Introduction @@ -39,7 +39,7 @@ client = Client( ## Configuration -You can set an "api_key" for your provider in client. +You can set an "api_key" for your provider in the client. And you also have the option to define a proxy for all outgoing requests: ```python @@ -108,13 +108,35 @@ response = client.images.create_variation( image_url = response.data[0].url ``` - -#### Visual Examples - Original / Variant: [![Original Image](/docs/cat.jpeg)](/docs/client.md) [![Variant Image](/docs/cat.webp)](/docs/client.md) +#### Use a list of providers with RetryProvider + +```python +from g4f.client import Client +from g4f.Provider import RetryProvider, Phind, FreeChatgpt, Liaobots + +import g4f.debug +g4f.debug.logging = True + +client = Client( + provider=RetryProvider([Phind, FreeChatgpt, Liaobots], shuffle=False) +) +response = client.chat.completions.create( + model="", + messages=[{"role": "user", "content": "Hello"}], +) +print(response.choices[0].message.content) +``` + +``` +Using RetryProvider provider +Using Phind provider +How can I assist you today? +``` + #### Advanced example using GeminiProVision ```python @@ -128,13 +150,16 @@ client = Client( response = client.chat.completions.create( model="gemini-pro-vision", messages=[{"role": "user", "content": "What are on this image?"}], - image=open("docs/cat.jpeg", "rb") + image=open("docs/waterfall.jpeg", "rb") ) print(response.choices[0].message.content) ``` -**Question:** What are on this image? +![Waterfall](/docs/waterfall.jpeg) +``` +User: What are on this image? +``` ``` - A cat is sitting on a window sill looking at a bird outside the window. +Bot: There is a waterfall in the middle of a jungle. There is a rainbow over... ``` [Return to Home](/) \ No newline at end of file diff --git a/docs/guides/phone.jpeg b/docs/guides/phone.jpeg new file mode 100644 index 00000000..0cc57b14 Binary files /dev/null and b/docs/guides/phone.jpeg differ diff --git a/docs/guides/phone.md b/docs/guides/phone.md new file mode 100644 index 00000000..2d3ec032 --- /dev/null +++ b/docs/guides/phone.md @@ -0,0 +1,50 @@ +### Guide: Running the G4F GUI on Your Smartphone + +Running Python applications on your smartphone is possible with specialized apps like Pydroid. This tutorial will walk you through the process using an Android smartphone with Pydroid. Note that the steps may vary slightly for iPhone users due to differences in app names and ownership. + +

+ On the first screenshot is Pydroid and on the second is the Web UI in a browser +

+ +

+ + +

+ +1. **Install Pydroid from the Google Play Store:** + - Navigate to the Google Play Store and search for "Pydroid 3 - IDE for Python 3" or use the following link: [Pydroid 3 - IDE for Python 3](https://play.google.com/store/apps/details/Pydroid_3_IDE_for_Python_3). + +2. **Install the Pydroid Repository Plugin:** + - To enhance functionality, install the Pydroid repository plugin. Find it on the Google Play Store or use this link: [Pydroid Repository Plugin](https://play.google.com/store/apps/details?id=ru.iiec.pydroid3.quickinstallrepo). + +3. **Adjust App Settings:** + - 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: + ``` + pip install g4f flask pillow beautifulsoup4 + ``` + +5. **Create a New Python Script:** + - Within Pydroid, create a new Python script and input the following content: + ```python + from g4f import set_cookies + + set_cookies(".bing.com", { + "_U": "cookie value" + }) + + from g4f.gui import run_gui + + run_gui("0.0.0.0", 8080, debug=True) + ``` + Replace `"cookie value"` with your actual cookie value from Bing if you intend to create images using Bing. + +6. **Execute the Script:** + - Run the script by clicking on the play button or selecting the option to execute it. + +7. **Access the GUI:** + - Wait for the server to start, and once it's running, open the GUI using the URL provided in the output. [http://localhost:8080/chat/](http://localhost:8080/chat/) + +By following these steps, you can successfully run the G4F GUI on your smartphone using Pydroid, allowing you to create and interact with graphical interfaces directly from your device. \ No newline at end of file diff --git a/docs/guides/phone.png b/docs/guides/phone.png new file mode 100644 index 00000000..543b7817 Binary files /dev/null and b/docs/guides/phone.png differ diff --git a/docs/guides/phone2.jpeg b/docs/guides/phone2.jpeg new file mode 100644 index 00000000..77b6ec01 Binary files /dev/null and b/docs/guides/phone2.jpeg differ diff --git a/docs/waterfall.jpeg b/docs/waterfall.jpeg new file mode 100644 index 00000000..897e72db Binary files /dev/null and b/docs/waterfall.jpeg differ -- cgit v1.2.3