diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-11-17 05:22:45 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-11-17 05:22:45 +0100 |
commit | b268771baa4ddceee220da70c24fa9b8d93bedba (patch) | |
tree | 56c228467146039b48c5d291e3c03d291a07fcca | |
parent | Remove virtualdisplay and add headless mode (diff) | |
download | gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar.gz gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar.bz2 gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar.lz gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar.xz gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.tar.zst gpt4free-b268771baa4ddceee220da70c24fa9b8d93bedba.zip |
-rw-r--r-- | README.md | 39 |
1 files changed, 36 insertions, 3 deletions
@@ -243,6 +243,41 @@ for message in response: print(message) ``` +##### 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, + Phind, + PerplexityAi, +) + +options = ChromeOptions() +options.add_argument("--incognito"); +browser = Chrome(options=options, headless=True) +for idx in range(10): + response = g4f.ChatCompletion.create( + model=g4f.models.default, + provider=g4f.Provider.Phind, + messages=[{"role": "user", "content": "Suggest me a name."}], + browser=browser + ) + print(f"{idx}:", response) +browser.quit() +``` + ##### Cookies Required Cookies are essential for the proper functioning of some service providers. It is imperative to maintain an active session, typically achieved by logging into your account. @@ -253,18 +288,16 @@ When running the g4f package locally, the package automatically retrieves cookie import g4f from g4f.Provider import ( - Bard, Bing, HuggingChat, OpenAssistant, - OpenaiChat, ) # Usage response = g4f.ChatCompletion.create( model=g4f.models.default, messages=[{"role": "user", "content": "Hello"}], - provider=Bard, + provider=Bing, #cookies=g4f.get_cookies(".google.com"), cookies={"cookie_name": "value", "cookie_name2": "value2"}, auth=True |