From b268771baa4ddceee220da70c24fa9b8d93bedba Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 17 Nov 2023 05:22:45 +0100 Subject: Update Readme --- README.md | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 058a605b..9f0494f9 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3