返回提交历史
Modified
.github/workflows/build-packages.yml
+15
-0
Modified
g4f/__main__.py
+3
-8
Modified
g4f/cli/__init__.py
+9
-5
Modified
g4f/cli/client.py
+7
-4
Modified
g4f/version.py
+1
-1
Deleted
g4f_cli.py
+0
-8
Deleted
test.py
+0
-43
XFEstudio/gpt4free
Update build
ae985be2
代码差异
7 个文件
+35
-69
@@ -37,6 +37,21 @@ jobs:
37
37
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
38
38
echo "Building version: ${G4F_VERSION}"
39
39
40
cat > g4f_cli.py << EOF
41
#!/usr/bin/env python3
42
"""
43
Entry point for g4f CLI executable builds
44
"""
45
46
import g4f.debug
47
g4f.debug.version_check = False
48
g4f.debug.version = "${{ needs.prepare.outputs.version }}"
49
50
if __name__ == "__main__":
51
from g4f.cli import main
52
main()
53
EOF
54
40
55
# PyPI Package
41
56
build-pypi:
42
57
runs-on: ubuntu-latest
@@ -1,9 +1,4 @@
1
from __future__ import annotations
1
from g4f.cli import main
2
2
3
from .cli import get_api_parser, run_api_args
4
5
parser = get_api_parser()
6
args = parser.parse_args()
7
if args.gui is None:
8
args.gui = True
9
run_api_args(args)
3
if __name__ == "__main__":
4
main()
@@ -1,5 +1,6 @@
1
1
from __future__ import annotations
2
2
3
import sys
3
4
import argparse
4
5
from argparse import ArgumentParser
5
6
from .client import get_parser, run_client_args
@@ -13,7 +14,8 @@ def get_api_parser():
13
14
api_parser.add_argument("--bind", default=None, help="The bind string. (Default: 0.0.0.0:1337)")
14
15
api_parser.add_argument("--port", "-p", default=None, help="Change the port of the server.")
15
16
api_parser.add_argument("--debug", "-d", action="store_true", help="Enable verbose logging.")
16
api_parser.add_argument("--gui", "-g", default=None, action="store_true", help="Start also the gui.")
17
api_parser.add_argument("--gui", "-g", default=None, action="store_true", help="(deprecated)")
18
api_parser.add_argument("--no-gui", "-ng", default=False, action="store_true", help="Start without the gui.")
17
19
api_parser.add_argument("--model", default=None, help="Default model for chat completion. (incompatible with --reload and --workers)")
18
20
api_parser.add_argument("--provider", choices=[provider.__name__ for provider in Provider.__providers__ if provider.working],
19
21
default=None, help="Default provider for chat completion. (incompatible with --reload and --workers)")
@@ -48,7 +50,7 @@ def run_api_args(args):
48
50
media_provider=args.media_provider,
49
51
proxy=args.proxy,
50
52
model=args.model,
51
gui=args.gui,
53
gui=not args.no_gui,
52
54
demo=args.demo,
53
55
timeout=args.timeout,
54
56
)
@@ -82,7 +84,9 @@ def main():
82
84
elif args.mode == "client":
83
85
run_client_args(args)
84
86
else:
85
parser.print_help()
86
exit(1)
87
raise argparse.ArgumentError(None, "No valid mode specified. Use 'api', 'gui', or 'client'.")
87
88
except argparse.ArgumentError:
88
run_client_args(get_parser().parse_args())
89
try:
90
run_client_args(get_parser(exit_on_error=False).parse_args(), exit_on_error=False)
91
except argparse.ArgumentError:
92
run_api_args(get_api_parser().parse_args())
@@ -190,10 +190,11 @@ def save_content(content, media: Optional[MediaResponse], filepath: str, allowed
190
190
print("\nUnable to save content.", file=sys.stderr)
191
191
return False
192
192
193
def get_parser():
193
def get_parser(exit_on_error=True):
194
194
parser = argparse.ArgumentParser(
195
195
description="G4F CLI client with conversation history",
196
formatter_class=argparse.ArgumentDefaultsHelpFormatter
196
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
197
exit_on_error=exit_on_error
197
198
)
198
199
parser.add_argument('-d', '--debug', action='store_true', help="Verbose debug")
199
200
parser.add_argument('-p', '--provider', default=None,
@@ -270,7 +271,7 @@ async def run_args(input_val, args):
270
271
sys.exit(1)
271
272
272
273
273
def run_client_args(args):
274
def run_client_args(args, exit_on_error=True):
274
275
input_txt = ""
275
276
media = []
276
277
rest = 0
@@ -317,9 +318,11 @@ def run_client_args(args):
317
318
else:
318
319
val = input_txt.strip()
319
320
320
if not val:
321
if exit_on_error and not val:
321
322
print("No input provided. Use -h.", file=sys.stderr)
322
323
sys.exit(1)
324
elif not val:
325
raise argparse.ArgumentError(None, "No input provided. Use -h for help.")
323
326
324
327
asyncio.run(run_args(val, args))
325
328
@@ -67,7 +67,7 @@ def get_git_version() -> str | None:
67
67
text=True,
68
68
stderr=PIPE
69
69
).strip()
70
except CalledProcessError:
70
except (CalledProcessError, FileNotFoundError):
71
71
return None
72
72
73
73
@@ -1,8 +0,0 @@
1
#!/usr/bin/env python3
2
"""
3
Entry point for g4f CLI executable builds
4
"""
5
6
if __name__ == "__main__":
7
from g4f.cli import main
8
main()
@@ -1,43 +0,0 @@
1
import asyncio
2
from pathlib import Path
3
from g4f.client import AsyncClient
4
from g4f.Provider import HuggingSpace, Azure
5
from g4f.cookies import read_cookie_files
6
7
# Load cookies and authentication environment variables needed by providers
8
read_cookie_files()
9
10
# Initialize asynchronous client to interact with providers
11
client = AsyncClient()
12
13
# Define an async function that creates an image variation using the HuggingSpace provider
14
async def main_with_hugging_space():
15
# Call create_variation with an image path, provider, model, prompt and desired response format
16
result = await client.images.create_variation(
17
image=Path("g4f.dev/docs/images/strawberry.jpg"), # Path to input image
18
provider=HuggingSpace, # Provider to use
19
model="flux-kontext-dev", # Model name for HuggingSpace
20
prompt="Change color to black and white", # Variation prompt
21
response_format="url" # Return URL to generated image
22
)
23
print(result) # Print the URL or result returned by the provider
24
25
# Define an async function that creates an image variation using the Azure provider
26
async def main_with_azure():
27
result = await client.images.create_variation(
28
image=Path("g4f.dev/docs/images/strawberry.jpg"),
29
provider=Azure,
30
model="flux-kontext",
31
prompt="Add text 'Hello World' in the center",
32
response_format="url"
33
)
34
print(result) # Print the returned URL or response
35
36
# Run the Azure image variation example asynchronously
37
asyncio.run(main_with_azure())
38
39
# Import helper function to get directory used for cookies and related files
40
from g4f.cookies import get_cookies_dir
41
42
# Print the directory currently used for storing cookies
43
print(get_cookies_dir())