XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Fix load .har files, add hardir to docker, add docs

fd92918b
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

6 个文件 +38 -15
Modified .gitignore +2 -1
@@ -53,4 +53,5 @@ info.txt
53 53 local.py
54 54 *.gguf
55 55 image.py
56 .buildozer
56 .buildozer
57 hardir
Modified README.md +25 -10
@@ -89,7 +89,7 @@ As per the survey, here is a list of improvements to come
89 89
90 90 ```sh
91 91 docker pull hlohaus789/g4f
92 docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" hlohaus789/g4f:latest
92 docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" -v ${PWD}/hardir:/app/hardir hlohaus789/g4f:latest
93 93 ```
94 94 3. Open the included client on: [http://localhost:8080/chat/](http://localhost:8080/chat/)
95 95 or set the API base in your client to: [http://localhost:1337/v1](http://localhost:1337/v1)
@@ -218,9 +218,12 @@ See: [/docs/interference](/docs/interference.md)
218 218
219 219 ### Configuration
220 220
221 ##### Cookies / Access Token
221 #### Cookies
222 222
223 For generating images with Bing and for the OpenAI Chat you need cookies or a token from your browser session. From Bing you need the "_U" cookie and from OpenAI you need the "access_token". You can pass the cookies / the access token in the create function or you use the `set_cookies` setter before you run G4F:
223 You need cookies for BingCreateImages and the Gemini Provider.
224 From Bing you need the "_U" cookie and from Gemini you need the "__Secure-1PSID" cookie.
225 Sometimes you doesn't need the "__Secure-1PSID" cookie, but some other auth cookies.
226 You can pass the cookies in the create function or you use the `set_cookies` setter before you run G4F:
224 227
225 228 ```python
226 229 from g4f.cookies import set_cookies
@@ -228,20 +231,32 @@ from g4f.cookies import set_cookies
228 231 set_cookies(".bing.com", {
229 232 "_U": "cookie value"
230 233 })
231 set_cookies("chat.openai.com", {
232 "access_token": "token value"
233 })
234 234 set_cookies(".google.com", {
235 235 "__Secure-1PSID": "cookie value"
236 236 })
237
238 237 ...
239 238 ```
240 239
241 Alternatively, G4F reads the cookies with `browser_cookie3` from your browser
242 or it starts a browser instance with selenium `webdriver` for logging in.
240 #### .HAR File for OpenaiChat Provider
241
242 ##### Generating a .HAR File
243
244 To utilize the OpenaiChat provider, a .har file is required from https://chat.openai.com/. Follow the steps below to create a valid .har file:
245
246 1. Navigate to https://chat.openai.com/ using your preferred web browser and log in with your credentials.
247 2. Access the Developer Tools in your browser. This can typically be done by right-clicking the page and selecting "Inspect," or by pressing F12 or Ctrl+Shift+I (Cmd+Option+I on a Mac).
248 3. With the Developer Tools open, switch to the "Network" tab.
249 4. Reload the website to capture the loading process within the Network tab.
250 5. Initiate an action in the chat which can be capture in the .har file.
251 6. Right-click any of the network activities listed and select "Save all as HAR with content" to export the .har file.
252
253 ##### Storing the .HAR File
254
255 - Place the exported .har file in the `./hardir` directory if you are using Docker. Alternatively, you can store it in any preferred location within your current working directory.
256
257 Note: Ensure that your .har file is stored securely, as it may contain sensitive information.
243 258
244 ##### Using Proxy
259 #### Using Proxy
245 260
246 261 If you want to hide or change your IP address for the providers, you can set a proxy globally via an environment variable:
247 262
Modified docker/Dockerfile +8 -1
@@ -81,7 +81,14 @@ WORKDIR $G4F_DIR
81 81 COPY requirements.txt $G4F_DIR
82 82
83 83 # Upgrade pip for the latest features and install the project's Python dependencies.
84 RUN pip install --break-system-packages --upgrade pip && pip install --break-system-packages -r requirements.txt
84 RUN pip install --break-system-packages --upgrade pip \
85 && pip install --break-system-packages -r requirements.txt
86
87 # Install selenium driver and uninstall webdriver
88 RUN pip install --break-system-packages \
89 undetected-chromedriver selenium-wire \
90 && pip uninstall -y --break-system-packages \
91 webdriver plyer
85 92
86 93 # Copy the entire package into the container.
87 94 ADD --chown=$G4F_USER:$G4F_USER g4f $G4F_DIR/g4f
Modified g4f/Provider/needs_auth/OpenaiChat.py +1 -1
@@ -403,7 +403,7 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
403 403 "conversation_id": conversation_id,
404 404 "parent_message_id": parent_id,
405 405 "model": model,
406 "history_and_training_disabled": history_disabled and not auto_continue,
406 "history_and_training_disabled": history_disabled and not auto_continue and not return_conversation,
407 407 "websocket_request_id": websocket_request_id
408 408 }
409 409 if action != "continue":
Modified g4f/Provider/openai/har_file.py +2 -2
@@ -41,9 +41,9 @@ def readHAR():
41 41 if not harPath:
42 42 raise RuntimeError("No .har file found")
43 43 for path in harPath:
44 with open(path, 'r') as file:
44 with open(path, 'rb') as file:
45 45 try:
46 harFile = json.load(file)
46 harFile = json.loads(file.read())
47 47 except json.JSONDecodeError:
48 48 # Error: not a HAR file!
49 49 continue
Added hardir/.gitkeep +0 -0
此文件没有可显示的逐行差异。