返回提交历史
Modified
g4f-go/main.go
+19
-14
Modified
g4f-go/runtime.go
+9
-0
Modified
g4f/Provider/__init__.py
+5
-0
Added
g4f/Provider/needs_auth/GoogleAiMode.py
+595
-0
Modified
g4f/tools/run_tools.py
+6
-0
XFEstudio/gpt4free
Add Google AI Mode provider and enhance cost estimation logging
4f998cec
代码差异
5 个文件
+634
-14
@@ -118,22 +118,27 @@ func runMain() int {
118
118
return code
119
119
}
120
120
121
exe, err := pythonExecutable(binDir)
122
if err != nil {
123
fmt.Fprintln(os.Stderr, "g4f-go:", err)
124
return 1
125
}
126
if !g4fIsInstalled(binDir) {
127
// First call: install g4f.
128
start := time.Now()
129
if err := installG4F(binDir, exe, start); err != nil {
121
// On Termux we use the system python (no downloaded runtime), so skip
122
// the downloaded-runtime executable lookup and g4f install/upgrade
123
// logic that targets binDir/python-home.
124
if !IsTermuxSystem() {
125
exe, err := pythonExecutable(binDir)
126
if err != nil {
130
127
fmt.Fprintln(os.Stderr, "g4f-go:", err)
128
return 1
131
129
}
132
} else if len(args) > 0 && isUpgradeCommand(args[0]) {
133
// Subsequent call with gui/api/dev: upgrade g4f.
134
start := time.Now()
135
if err := upgradeG4F(binDir, exe, start); err != nil {
136
fmt.Fprintln(os.Stderr, "g4f-go:", err)
130
if !g4fIsInstalled(binDir) {
131
// First call: install g4f.
132
start := time.Now()
133
if err := installG4F(binDir, exe, start); err != nil {
134
fmt.Fprintln(os.Stderr, "g4f-go:", err)
135
}
136
} else if len(args) > 0 && isUpgradeCommand(args[0]) {
137
// Subsequent call with gui/api/dev: upgrade g4f.
138
start := time.Now()
139
if err := upgradeG4F(binDir, exe, start); err != nil {
140
fmt.Fprintln(os.Stderr, "g4f-go:", err)
141
}
137
142
}
138
143
}
139
144
@@ -180,7 +180,16 @@ func ensurePip(binDir, exe string) error {
180
180
// pipEnv restricts pip to the downloaded runtime so installs never touch the
181
181
// host Python. pbs installs are a full layout: lib/pythonX.Y/site-packages
182
182
// (unix) or Lib/site-packages (windows) inside the interpreter home.
183
// On Termux we use the system python, so we must NOT override PYTHONHOME
184
// (that would break the system interpreter); only set user-site isolation.
183
185
func pipEnv(binDir string) []string {
186
if IsTermuxSystem() {
187
return []string{
188
"PYTHONNOUSERSITE=1",
189
"PYTHONDONTWRITEBYTECODE=1",
190
"PYTHONUTF8=1",
191
}
192
}
184
193
home := pythonHome(binDir)
185
194
lib := filepath.Join(home, "Lib", "site-packages")
186
195
if runtime.GOOS != "windows" {
@@ -157,6 +157,10 @@ def _resolve_provider(name: str) -> ProviderType:
157
157
from g4f.Provider.needs_auth.GlhfChat import GlhfChat
158
158
159
159
return GlhfChat
160
elif name == "GoogleAiMode":
161
from g4f.Provider.needs_auth.GoogleAiMode import GoogleAiMode
162
163
return GoogleAiMode
160
164
elif name == "GoogleSearch":
161
165
from g4f.Provider.search.GoogleSearch import GoogleSearch
162
166
@@ -424,6 +428,7 @@ _provider_names = [
424
428
"GithubCopilot",
425
429
"GithubCopilotAPI",
426
430
"GlhfChat",
431
"GoogleAiMode",
427
432
"GoogleSearch",
428
433
"Grok",
429
434
"Groq",
@@ -448,6 +448,9 @@ async def async_iter_run_tools(
448
448
"label": usage_label,
449
449
**usage.get_dict(),
450
450
}
451
estimated_cost = usage_dict.get("pollen_cost") or usage_dict.get("market_cost") or usage_dict.get("estimated_cost")
452
if estimated_cost is not None:
453
debug.log(f"Model: {usage_model}, Estimated cost: {estimated_cost}")
451
454
prompt_tokens = usage_dict.get("prompt_tokens", 0)
452
455
if saved_tokens:
453
456
usage_dict["saved_tokens"] = saved_tokens
@@ -670,6 +673,9 @@ def iter_run_tools(
670
673
"label": usage_label,
671
674
**usage.get_dict(),
672
675
}
676
cost = usage_dict.get("pollen_cost") or usage_dict.get("market_cost") or usage_dict.get("estimated_cost")
677
if cost is not None:
678
debug.log(f"Cost: {cost}")
673
679
if saved_tokens:
674
680
usage_dict["saved_tokens"] = saved_tokens
675
681
prompt_tokens = usage_dict.get("prompt_tokens", 0) + saved_tokens