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

XFEstudio/gpt4free

Update main.go

9fe75b01
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

7 个文件 +182 -436
Modified .gitignore +1 -226
@@ -16,229 +16,4 @@ g4f.exe
16 16 har_and_cookies
17 17 playground
18 18 .vscode
19 build/lib/g4f/__init__.py
20 build/lib/g4f/__main__.py
21 build/lib/g4f/config.py
22 build/lib/g4f/cookies.py
23 build/lib/g4f/debug.py
24 build/lib/g4f/errors.py
25 build/lib/g4f/files.py
26 build/lib/g4f/models.py
27 build/lib/g4f/tray.py
28 build/lib/g4f/typing.py
29 build/lib/g4f/version.py
30 build/lib/g4f/Provider/__init__.py
31 build/lib/g4f/Provider/base_provider.py
32 build/lib/g4f/Provider/BraveSearch.py
33 build/lib/g4f/Provider/ChatGptOss.py
34 build/lib/g4f/Provider/Cloudflare.py
35 build/lib/g4f/Provider/Copilot.py
36 build/lib/g4f/Provider/CopilotApp.py
37 build/lib/g4f/Provider/CopilotSession.py
38 build/lib/g4f/Provider/DeepAI.py
39 build/lib/g4f/Provider/DeepInfra.py
40 build/lib/g4f/Provider/helper.py
41 build/lib/g4f/Provider/OperaAria.py
42 build/lib/g4f/Provider/Perplexity.py
43 build/lib/g4f/Provider/PhindAi.py
44 build/lib/g4f/Provider/Pollinations.py
45 build/lib/g4f/Provider/PollinationsImage.py
46 build/lib/g4f/Provider/Quillbot.py
47 build/lib/g4f/Provider/Qwen.py
48 build/lib/g4f/Provider/TeachAnything.py
49 build/lib/g4f/Provider/Yqcloud.py
50 build/lib/g4f/Provider/Yupp.py
51 build/lib/g4f/Provider/audio/__init__.py
52 build/lib/g4f/Provider/audio/EdgeTTS.py
53 build/lib/g4f/Provider/audio/ElevenLabs.py
54 build/lib/g4f/Provider/audio/gTTS.py
55 build/lib/g4f/Provider/audio/MarkItDown.py
56 build/lib/g4f/Provider/audio/OpenAIFM.py
57 build/lib/g4f/Provider/audio/PollinationsAudio.py
58 build/lib/g4f/Provider/github/__init__.py
59 build/lib/g4f/Provider/github/copilotTokenProvider.py
60 build/lib/g4f/Provider/github/GithubCopilot.py
61 build/lib/g4f/Provider/github/githubOAuth2.py
62 build/lib/g4f/Provider/github/oauthFlow.py
63 build/lib/g4f/Provider/github/sharedTokenManager.py
64 build/lib/g4f/Provider/github/stubs.py
65 build/lib/g4f/Provider/glm/__init__.py
66 build/lib/g4f/Provider/glm/AliyunCaptcha.js.txt
67 build/lib/g4f/Provider/glm/captcha_solver.py
68 build/lib/g4f/Provider/hf_space/__init__.py
69 build/lib/g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py
70 build/lib/g4f/Provider/hf_space/BlackForestLabs_Flux1KontextDev.py
71 build/lib/g4f/Provider/hf_space/CohereForAI_C4AI_Command.py
72 build/lib/g4f/Provider/hf_space/raise_for_status.py
73 build/lib/g4f/Provider/hf_space/StabilityAI_SD35Large.py
74 build/lib/g4f/Provider/hf_space/utils.py
75 build/lib/g4f/Provider/local/__init__.py
76 build/lib/g4f/Provider/local/Local.py
77 build/lib/g4f/Provider/local/Ollama.py
78 build/lib/g4f/Provider/needs_auth/__init__.py
79 build/lib/g4f/Provider/needs_auth/AIBadgr.py
80 build/lib/g4f/Provider/needs_auth/Airforce.py
81 build/lib/g4f/Provider/needs_auth/Anthropic.py
82 build/lib/g4f/Provider/needs_auth/Antigravity.py
83 build/lib/g4f/Provider/needs_auth/Azure.py
84 build/lib/g4f/Provider/needs_auth/BingCreateImages.py
85 build/lib/g4f/Provider/needs_auth/BlackboxPro.py
86 build/lib/g4f/Provider/needs_auth/CablyAI.py
87 build/lib/g4f/Provider/needs_auth/Cerebras.py
88 build/lib/g4f/Provider/needs_auth/Claude.py
89 build/lib/g4f/Provider/needs_auth/Cohere.py
90 build/lib/g4f/Provider/needs_auth/CopilotAccount.py
91 build/lib/g4f/Provider/needs_auth/Custom.py
92 build/lib/g4f/Provider/needs_auth/DeepSeek.py
93 build/lib/g4f/Provider/needs_auth/FenayAI.py
94 build/lib/g4f/Provider/needs_auth/gemini_utils.py
95 build/lib/g4f/Provider/needs_auth/Gemini.py
96 build/lib/g4f/Provider/needs_auth/GeminiCLI.py
97 build/lib/g4f/Provider/needs_auth/GeminiPro.py
98 build/lib/g4f/Provider/needs_auth/GigaChat.py
99 build/lib/g4f/Provider/needs_auth/GithubCopilot.py
100 build/lib/g4f/Provider/needs_auth/GithubCopilotAPI.py
101 build/lib/g4f/Provider/needs_auth/GlhfChat.py
102 build/lib/g4f/Provider/needs_auth/Grok.py
103 build/lib/g4f/Provider/needs_auth/Groq.py
104 build/lib/g4f/Provider/needs_auth/LLMPlayground.py
105 build/lib/g4f/Provider/needs_auth/LMArena.py
106 build/lib/g4f/Provider/needs_auth/MetaAI.py
107 build/lib/g4f/Provider/needs_auth/MetaAIAccount.py
108 build/lib/g4f/Provider/needs_auth/MicrosoftDesigner.py
109 build/lib/g4f/Provider/needs_auth/Nvidia.py
110 build/lib/g4f/Provider/needs_auth/OpenaiAccount.py
111 build/lib/g4f/Provider/needs_auth/OpenaiAPI.py
112 build/lib/g4f/Provider/needs_auth/OpenaiChat.py
113 build/lib/g4f/Provider/needs_auth/OpenRouter.py
114 build/lib/g4f/Provider/needs_auth/PerplexityApi.py
115 build/lib/g4f/Provider/needs_auth/Pi.py
116 build/lib/g4f/Provider/needs_auth/Puter.py
117 build/lib/g4f/Provider/needs_auth/Reka.py
118 build/lib/g4f/Provider/needs_auth/Replicate.py
119 build/lib/g4f/Provider/needs_auth/ThebApi.py
120 build/lib/g4f/Provider/needs_auth/Together.py
121 build/lib/g4f/Provider/needs_auth/Video.py
122 build/lib/g4f/Provider/needs_auth/WhiteRabbitNeo.py
123 build/lib/g4f/Provider/needs_auth/xAI.py
124 build/lib/g4f/Provider/needs_auth/You.py
125 build/lib/g4f/Provider/needs_auth/bing/__init__.py
126 build/lib/g4f/Provider/needs_auth/bing/create_images.py
127 build/lib/g4f/Provider/needs_auth/deepseek/pow_solver.wasm
128 build/lib/g4f/Provider/needs_auth/hf/__init__.py
129 build/lib/g4f/Provider/needs_auth/hf/HuggingChat.py
130 build/lib/g4f/Provider/needs_auth/hf/HuggingFaceMedia.py
131 build/lib/g4f/Provider/needs_auth/hf/models.py
132 build/lib/g4f/Provider/needs_auth/mini_max/__init__.py
133 build/lib/g4f/Provider/needs_auth/mini_max/crypt.py
134 build/lib/g4f/Provider/needs_auth/mini_max/HailuoAI.py
135 build/lib/g4f/Provider/needs_auth/mini_max/MiniMax.py
136 build/lib/g4f/Provider/openai/__init__.py
137 build/lib/g4f/Provider/openai/crypt.py
138 build/lib/g4f/Provider/openai/har_file.py
139 build/lib/g4f/Provider/openai/models.py
140 build/lib/g4f/Provider/openai/new.py
141 build/lib/g4f/Provider/openai/proofofwork.py
142 build/lib/g4f/Provider/qwen/__init__.py
143 build/lib/g4f/Provider/qwen/cookie_generator.py
144 build/lib/g4f/Provider/qwen/fingerprint.py
145 build/lib/g4f/Provider/qwen/generate_ua.py
146 build/lib/g4f/Provider/qwen/oauthFlow.py
147 build/lib/g4f/Provider/qwen/QwenCode.py
148 build/lib/g4f/Provider/qwen/qwenContentGenerator.py
149 build/lib/g4f/Provider/qwen/qwenOAuth2.py
150 build/lib/g4f/Provider/qwen/sharedTokenManager.py
151 build/lib/g4f/Provider/qwen/stubs.py
152 build/lib/g4f/Provider/search/__init__.py
153 build/lib/g4f/Provider/search/CachedSearch.py
154 build/lib/g4f/Provider/search/DDGS.py
155 build/lib/g4f/Provider/search/GoogleSearch.py
156 build/lib/g4f/Provider/search/SearXNG.py
157 build/lib/g4f/Provider/search/YouTube.py
158 build/lib/g4f/Provider/template/__init__.py
159 build/lib/g4f/Provider/template/BackendApi.py
160 build/lib/g4f/Provider/template/OpenaiTemplate.py
161 build/lib/g4f/Provider/yupp/__init__.py
162 build/lib/g4f/Provider/yupp/constants.py
163 build/lib/g4f/Provider/yupp/models.py
164 build/lib/g4f/Provider/yupp/token_extractor.py
165 build/lib/g4f/api/__init__.py
166 build/lib/g4f/api/_logging.py
167 build/lib/g4f/api/_tokenizer.py
168 build/lib/g4f/api/run.py
169 build/lib/g4f/api/stubs.py
170 build/lib/g4f/api/tool_loop_detection.py
171 build/lib/g4f/cli/__init__.py
172 build/lib/g4f/cli/__main__.py
173 build/lib/g4f/cli/client.py
174 build/lib/g4f/client/__init__.py
175 build/lib/g4f/client/factory.py
176 build/lib/g4f/client/helper.py
177 build/lib/g4f/client/models.py
178 build/lib/g4f/client/service.py
179 build/lib/g4f/client/stubs.py
180 build/lib/g4f/client/types.py
181 build/lib/g4f/gui/__init__.py
182 build/lib/g4f/gui/gui_parser.py
183 build/lib/g4f/gui/run.py
184 build/lib/g4f/gui/webview.py
185 build/lib/g4f/gui/server/__init__.py
186 build/lib/g4f/gui/server/api.py
187 build/lib/g4f/gui/server/app.py
188 build/lib/g4f/gui/server/backend_api.py
189 build/lib/g4f/gui/server/config.py
190 build/lib/g4f/gui/server/crypto.py
191 build/lib/g4f/gui/server/internet.py
192 build/lib/g4f/gui/server/js_api.py
193 build/lib/g4f/gui/server/website.py
194 build/lib/g4f/image/__init__.py
195 build/lib/g4f/image/copy_images.py
196 build/lib/g4f/integration/__init__.py
197 build/lib/g4f/integration/langchain.py
198 build/lib/g4f/integration/pydantic_ai.py
199 build/lib/g4f/integration/markitdown/__init__.py
200 build/lib/g4f/integration/markitdown/_audio_converter.py
201 build/lib/g4f/integration/markitdown/_base_converter.py
202 build/lib/g4f/integration/markitdown/_image_converter.py
203 build/lib/g4f/integration/markitdown/_llm_caption.py
204 build/lib/g4f/integration/markitdown/_transcribe_audio.py
205 build/lib/g4f/integration/markitdown/_youtube_converter.py
206 build/lib/g4f/local/__init__.py
207 build/lib/g4f/locals/__init__.py
208 build/lib/g4f/locals/models.py
209 build/lib/g4f/locals/provider.py
210 build/lib/g4f/mcp/__init__.py
211 build/lib/g4f/mcp/__main__.py
212 build/lib/g4f/mcp/apply_patch.py
213 build/lib/g4f/mcp/pa_downloader.py
214 build/lib/g4f/mcp/pa_provider.py
215 build/lib/g4f/mcp/server.py
216 build/lib/g4f/mcp/tools.py
217 build/lib/g4f/providers/__init__.py
218 build/lib/g4f/providers/any_model_map.py
219 build/lib/g4f/providers/any_provider.py
220 build/lib/g4f/providers/asyncio.py
221 build/lib/g4f/providers/base_provider.py
222 build/lib/g4f/providers/cache.py
223 build/lib/g4f/providers/config_provider.py
224 build/lib/g4f/providers/create_images.py
225 build/lib/g4f/providers/helper.py
226 build/lib/g4f/providers/response.py
227 build/lib/g4f/providers/retry_provider.py
228 build/lib/g4f/providers/tool_support.py
229 build/lib/g4f/providers/types.py
230 build/lib/g4f/requests/__init__.py
231 build/lib/g4f/requests/aiohttp.py
232 build/lib/g4f/requests/cdp.py
233 build/lib/g4f/requests/curl_cffi.py
234 build/lib/g4f/requests/defaults.py
235 build/lib/g4f/requests/raise_for_status.py
236 build/lib/g4f/tools/__init__.py
237 build/lib/g4f/tools/auth.py
238 build/lib/g4f/tools/fetch_and_scrape.py
239 build/lib/g4f/tools/files.py
240 build/lib/g4f/tools/media.py
241 build/lib/g4f/tools/optimize_request.py
242 build/lib/g4f/tools/run_tools.py
243 build/lib/g4f/tools/token_optimizer.py
244 build/lib/g4f/tools/web_search.py
19 build
Deleted g4f-go/cli.go +0 -123
@@ -1,123 +0,0 @@
1 package main
2
3 import (
4 "context"
5 "fmt"
6 "os"
7 "path/filepath"
8 "strings"
9 )
10
11 // cli handles the `g4f-go <command>` interface. Anything unknown is forwarded
12 // to the embedded g4f CLI (so `g4f-go client "hello"` just works).
13 func printHelp() {
14 fmt.Printf(`g4f-go %s - gpt4free with embedded Python %s
15
16 Usage:
17 g4f-go <g4f args...> run gpt4free (e.g. g4f-go client "hello")
18 g4f-go api --port 8080 start the OpenAI-compatible API server
19 g4f-go gui launch the web GUI
20 g4f-go install g4f (re)install the g4f package into the embedded runtime
21 g4f-go status show runtime status
22 g4f-go help show this help
23 g4f-go --version show version
24
25 Environment:
26 G4F_PYTHON_ONLY=1 print the embedded python path and exit (for wrappers)
27 `, Version, PythonVer)
28 }
29
30 func cli(ctx context.Context, binDir, py string, args []string) int {
31 if len(args) == 0 {
32 printHelp()
33 return 0
34 }
35
36 switch args[0] {
37 case "help", "--help", "-h":
38 return cli(ctx, binDir, py, nil)
39 case "--version", "-v":
40 fmt.Printf("g4f-go %s (embedded CPython %s)\n", Version, PythonVer)
41 return 0
42 case "status":
43 exe := pythonExecutable(binDir)
44 stamp := filepath.Join(binDir, ".g4f-runtime", ".installed")
45 fmt.Printf("binary dir: %s\n", binDir)
46 fmt.Printf("python: %s\n", exe)
47 if _, err := os.Stat(exe); err == nil {
48 fmt.Println("runtime: extracted")
49 } else {
50 fmt.Println("runtime: not extracted (will extract on first run)")
51 }
52 if _, err := os.Stat(stamp); err == nil {
53 fmt.Println("g4f: installed")
54 } else {
55 fmt.Println("g4f: not installed (will install on first run)")
56 }
57 code, err := runPython(ctx, py, []string{"--version"})
58 if err != nil {
59 fmt.Fprintln(os.Stderr, "g4f-go:", err)
60 return 1
61 }
62 return code
63 case "install":
64 if len(args) < 2 {
65 fmt.Fprintln(os.Stderr, "usage: g4f-go install g4f")
66 return 2
67 }
68 code, err := runPython(ctx, py, []string{
69 "-m", "pip", "install", "--no-input", "--no-cache-dir", args[1],
70 })
71 if err != nil {
72 fmt.Fprintln(os.Stderr, "g4f-go:", err)
73 return 1
74 }
75 return code
76 case "bootstrap":
77 // Refresh the embedded package installation (e.g. after updating g4f-go).
78 code, err := runPython(ctx, py, []string{"-m", "pip", "install", "--no-input",
79 "--no-index", "--find-links", "wheels", "--no-cache-dir", "g4f"}, pipEnv(binDir)...)
80 if err != nil {
81 fmt.Fprintln(os.Stderr, "g4f-go:", err)
82 return 1
83 }
84 return code
85 }
86
87 if os.Getenv("G4F_PYTHON_ONLY") == "1" {
88 fmt.Println(py)
89 return 0
90 }
91
92 // Default: forward everything to the g4f module.
93 code, err := runPython(ctx, py, append([]string{"-m", "g4f"}, args...))
94 if err != nil {
95 fmt.Fprintln(os.Stderr, "g4f-go:", err)
96 return 1
97 }
98 return code
99 }
100
101 // normalizeArgs cleans leading `g4f-go` repeats (typos like `g4f-go g4f-go ...`).
102 func normalizeArgs(args []string) []string {
103 for len(args) > 0 && args[0] == "g4f-go" {
104 args = args[1:]
105 }
106 // A leading binary-name echo (e.g. argv[0]) is stripped by callers.
107 return args
108 }
109
110 // hasSubcommand reports whether args start with a known g4f-go subcommand.
111 func hasSubcommand(args []string) bool {
112 if len(args) == 0 {
113 return true
114 }
115 switch args[0] {
116 case "help", "--help", "-h", "--version", "-v", "status", "install", "bootstrap":
117 return true
118 }
119 if strings.HasPrefix(args[0], "-") {
120 return true
121 }
122 return false
123 }
Modified g4f-go/main.go +107 -18
@@ -6,23 +6,33 @@ import (
6 6 "os"
7 7 "os/signal"
8 8 "syscall"
9 "path/filepath"
10 "strings"
9 11 )
10 12
11 func main() {
12 module := "g4f"
13
14 switch {
15 case len(os.Args) == 1:
16 printHelp()
17 os.Exit(0)
18 case os.Args[1] == "--version" || os.Args[1] == "-v":
19 fmt.Printf("g4f-go %s (embedded CPython %s)\n", Version, PythonVer)
20 os.Exit(0)
21 case os.Args[1] == "help" || os.Args[1] == "--help" || os.Args[1] == "-h":
13 // main handles the `g4f-go <command>` interface. Anything unknown is forwarded
14 // to the embedded g4f CLI (so `g4f-go client "hello"` just works).
15 func printHelp() {
16 fmt.Printf(`g4f-go %s - gpt4free with embedded Python %s
17
18 Usage:
19 g4f-go <g4f args...> run gpt4free (e.g. g4f-go client "hello")
20 g4f-go api --port 8080 start the OpenAI-compatible API server
21 g4f-go gui launch the web GUI
22 g4f-go install g4f (re)install the g4f package into the embedded runtime
23 g4f-go status show runtime status
24 g4f-go help show this help
25 g4f-go --version show version
26
27 Environment:
28 G4F_PYTHON_ONLY=1 print the embedded python path and exit (for wrappers)
29 `, Version, PythonVer)
30 }
31
32 func main(ctx context.Context, binDir, py string, args []string) int {
33 if len(args) == 0 {
22 34 printHelp()
23 os.Exit(0)
24 case os.Args[1] == "install" || os.Args[1] == "uninstall":
25 module = "pip" // Fixed: Assign to the existing variable, don't redeclare
35 return 0
26 36 }
27 37
28 38 py, err := ensureRuntime()
@@ -34,11 +44,90 @@ func main() {
34 44 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
35 45 defer stop()
36 46
37 // Runs: python -m [module] [args...]
38 code, err := runPython(ctx, py, append([]string{"-m", module}, os.Args[1:]...))
47 switch args[0] {
48 case "help", "--help", "-h":
49 return main(ctx, binDir, py, nil)
50 case "--version", "-v":
51 fmt.Printf("g4f-go %s (embedded CPython %s)\n", Version, PythonVer)
52 return 0
53 case "status":
54 exe := pythonExecutable(binDir)
55 stamp := filepath.Join(binDir, ".g4f-runtime", ".installed")
56 fmt.Printf("binary dir: %s\n", binDir)
57 fmt.Printf("python: %s\n", exe)
58 if _, err := os.Stat(exe); err == nil {
59 fmt.Println("runtime: extracted")
60 } else {
61 fmt.Println("runtime: not extracted (will extract on first run)")
62 }
63 if _, err := os.Stat(stamp); err == nil {
64 fmt.Println("g4f: installed")
65 } else {
66 fmt.Println("g4f: not installed (will install on first run)")
67 }
68 code, err := runPython(ctx, py, []string{"--version"})
69 if err != nil {
70 fmt.Fprintln(os.Stderr, "g4f-go:", err)
71 return 1
72 }
73 return code
74 case "install", "uninstall":
75 if len(args) < 2 {
76 fmt.Fprintln(os.Stderr, "usage: g4f-go install g4f")
77 return 2
78 }
79 code, err := runPython(ctx, py, []string{
80 "-m", "pip", args...
81 })
82 if err != nil {
83 fmt.Fprintln(os.Stderr, "g4f-go:", err)
84 return 1
85 }
86 return code
87 case "bootstrap":
88 // Refresh the embedded package installation (e.g. after updating g4f-go).
89 code, err := runPython(ctx, py, []string{"-m", "pip", "install", "--no-input", "g4f"}, pipEnv(binDir)...)
90 if err != nil {
91 fmt.Fprintln(os.Stderr, "g4f-go:", err)
92 return 1
93 }
94 return code
95 }
96
97 if os.Getenv("G4F_PYTHON_ONLY") == "1" {
98 fmt.Println(py)
99 return 0
100 }
101
102 // Default: forward everything to the g4f module.
103 code, err := runPython(ctx, py, append([]string{"-m", "g4f"}, args...))
39 104 if err != nil {
40 105 fmt.Fprintln(os.Stderr, "g4f-go:", err)
41 os.Exit(1)
106 return 1
107 }
108 return code
109 }
110
111 // normalizeArgs cleans leading `g4f-go` repeats (typos like `g4f-go g4f-go ...`).
112 func normalizeArgs(args []string) []string {
113 for len(args) > 0 && args[0] == "g4f-go" {
114 args = args[1:]
115 }
116 // A leading binary-name echo (e.g. argv[0]) is stripped by callers.
117 return args
118 }
119
120 // hasSubcommand reports whether args start with a known g4f-go subcommand.
121 func hasSubcommand(args []string) bool {
122 if len(args) == 0 {
123 return true
124 }
125 switch args[0] {
126 case "help", "--help", "-h", "--version", "-v", "status", "install", "bootstrap":
127 return true
128 }
129 if strings.HasPrefix(args[0], "-") {
130 return true
42 131 }
43 os.Exit(code)
132 return false
44 133 }
Modified g4f/Provider/Copilot.py +0 -1
@@ -94,7 +94,6 @@ class Copilot(AsyncAuthedProvider, ProviderModelMixin):
94 94
95 95 working = True
96 96 use_nodriver = has_nodriver
97 active_by_default = True
98 97
99 98 default_model = "Copilot"
100 99 models = [default_model, "Think Deeper", "Smart (GPT-5)", "Study"]
Modified g4f/Provider/CopilotApp.py +74 -65
@@ -14,7 +14,7 @@ class CopilotApp(AsyncGeneratorProvider, ProviderModelMixin):
14 14 label = "Copilot App"
15 15 url = "https://play.google.com/store/apps/details?id=com.microsoft.copilot"
16 16 working = True
17 supports_stream = True
17 active_by_default = True
18 18
19 19 default_model = "smart"
20 20 models = ["smart", "reasoning", "chat", "study", "search"]
@@ -26,8 +26,13 @@ class CopilotApp(AsyncGeneratorProvider, ProviderModelMixin):
26 26 "o1-preview": "reasoning",
27 27 "o3-mini": "reasoning",
28 28 "gpt-5": "smart",
29 "gpt-4o-mini": "chat",
29 30 }
30 31
32 @classmethod
33 async def get_quota(cls, **kwargs) -> int:
34 return {"live": cls.live}
35
31 36 @classmethod
32 37 async def create_async_generator(
33 38 cls, model: str, messages: Messages, proxy: str = None, **kwargs
@@ -50,73 +55,77 @@ class CopilotApp(AsyncGeneratorProvider, ProviderModelMixin):
50 55 "correctPersonalizationSetting": True,
51 56 "deferredDataUseCapable": True,
52 57 }
58 try:
59 async with aiohttp.ClientSession() as session:
60 async with session.post(
61 "https://copilot.microsoft.com/c/api/start",
62 headers=headers,
63 json=start_payload,
64 proxy=proxy,
65 ) as resp:
66 if resp.status != 200:
67 raise RuntimeError(
68 f"Failed to start conversation: {await resp.text()}"
69 )
53 70
54 async with aiohttp.ClientSession() as session:
55 async with session.post(
56 "https://copilot.microsoft.com/c/api/start",
57 headers=headers,
58 json=start_payload,
59 proxy=proxy,
60 ) as resp:
61 if resp.status != 200:
62 raise RuntimeError(
63 f"Failed to start conversation: {await resp.text()}"
64 )
65
66 start_data = await resp.json()
67 conversation_id = start_data.get("currentConversationId")
71 start_data = await resp.json()
72 conversation_id = start_data.get("currentConversationId")
68 73
69 client_session_id = str(uuid.uuid4())
70 ws_url = f"wss://copilot.microsoft.com/c/api/chat?api-version=2&clientSessionId={client_session_id}"
74 client_session_id = str(uuid.uuid4())
75 ws_url = f"wss://copilot.microsoft.com/c/api/chat?api-version=2&clientSessionId={client_session_id}"
71 76
72 async with session.ws_connect(ws_url, headers=headers, proxy=proxy) as ws:
73 async for msg in ws:
74 if msg.type == aiohttp.WSMsgType.TEXT:
75 data = json.loads(msg.data)
76 if data.get("event") == "connected":
77 break
77 async with session.ws_connect(ws_url, headers=headers, proxy=proxy) as ws:
78 async for msg in ws:
79 if msg.type == aiohttp.WSMsgType.TEXT:
80 data = json.loads(msg.data)
81 if data.get("event") == "connected":
82 break
78 83
79 model_lower = model.lower()
80 if (
81 "reasoning" in model_lower
82 or "think" in model_lower
83 or "o1" in model_lower
84 or "o3" in model_lower
85 ):
86 mode = "reasoning"
87 elif "smart" in model_lower or "gpt-5" in model_lower:
88 mode = "smart"
89 elif "study" in model_lower:
90 mode = "study"
91 elif "search" in model_lower:
92 mode = "search"
93 else:
94 mode = "smart"
84 model_lower = model.lower()
85 if (
86 "reasoning" in model_lower
87 or "think" in model_lower
88 or "o1" in model_lower
89 or "o3" in model_lower
90 ):
91 mode = "reasoning"
92 elif "smart" in model_lower or "gpt-5" in model_lower:
93 mode = "smart"
94 elif "study" in model_lower:
95 mode = "study"
96 elif "search" in model_lower:
97 mode = "search"
98 else:
99 mode = "smart"
95 100
96 send_payload = {
97 "event": "send",
98 "content": [{"type": "text", "text": prompt}],
99 "conversationId": conversation_id,
100 "mode": mode,
101 }
102 await ws.send_json(send_payload)
101 send_payload = {
102 "event": "send",
103 "content": [{"type": "text", "text": prompt}],
104 "conversationId": conversation_id,
105 "mode": mode,
106 }
107 await ws.send_json(send_payload)
103 108
104 sources = {}
105 async for msg in ws:
106 if msg.type == aiohttp.WSMsgType.TEXT:
107 data = json.loads(msg.data)
108 event = data.get("event")
109 if event == "appendText":
110 yield data.get("text", "")
111 elif event == "citation":
112 sources[data.get("url")] = data
113 yield SourceLink(
114 list(sources.keys()).index(data.get("url")),
115 data.get("url"),
116 )
117 elif event == "done":
118 if sources:
119 yield Sources(sources.values())
120 break
121 elif msg.type == aiohttp.WSMsgType.ERROR:
122 raise RuntimeError(f"WebSocket Error: {ws.exception()}")
109 sources = {}
110 async for msg in ws:
111 if msg.type == aiohttp.WSMsgType.TEXT:
112 data = json.loads(msg.data)
113 event = data.get("event")
114 if event == "appendText":
115 yield data.get("text", "")
116 elif event == "citation":
117 sources[data.get("url")] = data
118 yield SourceLink(
119 list(sources.keys()).index(data.get("url")),
120 data.get("url"),
121 )
122 elif event == "done":
123 if sources:
124 yield Sources(sources.values())
125 cls.live += 1
126 break
127 elif msg.type == aiohttp.WSMsgType.ERROR:
128 raise RuntimeError(f"WebSocket Error: {ws.exception()}")
129 except Exception as e:
130 cls.live -= 1
131 raise RuntimeError(f"Error during CopilotApp interaction: {e}") from e
Modified g4f/Provider/needs_auth/Airforce.py +0 -1
@@ -11,7 +11,6 @@ class Airforce(OpenaiTemplate):
11 11 login_url = "https://panel.api.airforce/dashboard"
12 12 base_url = "https://api.airforce/v1"
13 13 working = True
14 needs_auth = True
15 14 active_by_default = True
16 15 use_image_size = True
17 16 default_model = "gpt-4o-mini"
Modified g4f/providers/any_provider.py +0 -2
@@ -30,8 +30,6 @@ from .any_model_map import (
30 30 # Add providers to existing models on map
31 31 PROVIDERS_LIST_2 = [
32 32 "OpenaiChat",
33 "Copilot",
34 "CopilotAccount",
35 33 "CopilotApp",
36 34 "Pollinations",
37 35 "Perplexity",