返回提交历史
Modified
g4f-go/build/g4f-go-0.1.0-android-arm64.zip
+0
-0
Added
g4f-go/build/g4f-go-0.1.0-darwin-amd64.zip
+0
-0
Added
g4f-go/build/g4f-go-0.1.0-darwin-arm64.zip
+0
-0
Modified
g4f-go/build/g4f-go-0.1.0-linux-amd64.zip
+0
-0
Modified
g4f-go/build/g4f-go-0.1.0-linux-arm64.zip
+0
-0
Added
g4f-go/build/g4f-go-0.1.0-windows-amd64.zip
+0
-0
Modified
g4f-go/download.go
+35
-0
Modified
g4f/mcp/server.py
+5
-4
Modified
g4f/mcp/tools.py
+2
-0
XFEstudio/gpt4free
Add new builds
4d750f84
代码差异
9 个文件
+42
-4
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
@@ -10,6 +10,7 @@ import (
10
10
"io"
11
11
"net/http"
12
12
"os"
13
"os/exec"
13
14
"path/filepath"
14
15
"runtime"
15
16
"strings"
@@ -371,10 +372,38 @@ func copySymlinkTarget(target, linkname string) error {
371
372
return os.WriteFile(target, data, 0o755)
372
373
}
373
374
375
func IsTermuxSystem() bool {
376
// Check for Termux specific environment variable or directory
377
if os.Getenv("TERMUX_VERSION") != "" {
378
return true
379
}
380
_, err := os.Stat("/data/data/com.termux/files/usr")
381
return !os.IsNotExist(err)
382
}
383
374
384
// ensureRuntime is the top-level entry point. It downloads (if needed) and
375
385
// extracts the platform runtime into binDir, then returns the python
376
386
// executable/launcher path.
377
387
func ensureRuntime() (string, error) {
388
isTermux := IsTermuxSystem()
389
if isTermux {
390
// Check if key compilers/tools are installed
391
if !commandExists("clang") || !commandExists("make") {
392
fmt.Println("Missing required tools. Installing...")
393
394
packages := []string{"clang", "make", "libxml2", "libxslt", "libjpeg-turbo", "libpng"}
395
args := append([]string{"install", "-y"}, packages...)
396
397
cmd := exec.Command("pkg", args...)
398
cmd.Stdout = os.Stdout
399
cmd.Stderr = os.Stderr
400
401
if err := cmd.Run(); err != nil {
402
fmt.Printf("Error during package installation: %v\n", err)
403
}
404
}
405
}
406
378
407
binDir := installDir()
379
408
exe, err := pythonExecutable(binDir)
380
409
if err == nil {
@@ -414,6 +443,12 @@ func ensureRuntime() (string, error) {
414
443
return finalizeRuntime(binDir)
415
444
}
416
445
446
// Check if a command/binary exists in PATH
447
func commandExists(cmd string) bool {
448
_, err := exec.LookPath(cmd)
449
return err == nil
450
}
451
417
452
// finalizeRuntime does platform-specific finishing (launcher setup) and
418
453
// returns the interpreter path.
419
454
func finalizeRuntime(binDir string) (string, error) {
@@ -74,7 +74,7 @@ class MCPServer:
74
74
allowing AI assistants to utilize web search, scraping, and image generation.
75
75
"""
76
76
77
def __init__(self, safe_mode: bool = False):
77
def __init__(self, safe_mode: bool = False, github_token: Optional[str] = None):
78
78
"""Initialize MCP server with available tools
79
79
80
80
Args:
@@ -83,6 +83,7 @@ class MCPServer:
83
83
listing the workspace root directory is blocked.
84
84
"""
85
85
self.safe_mode = safe_mode
86
self.github_token = github_token
86
87
self.tools = {
87
88
"web_search": WebSearchTool(),
88
89
"image_generation": ImageGenerationTool(),
@@ -98,8 +99,8 @@ class MCPServer:
98
99
"fetch_webpage": FetchWebpageTool(),
99
100
"file_search_glob": FileSearchGlobTool(),
100
101
"grep_search": GrepSearchTool(),
101
"github_repo": GithubRepoTool(),
102
"github_text_search": GithubTextSearchTool(),
102
"github_repo": GithubRepoTool(False, self.github_token),
103
"github_text_search": GithubTextSearchTool(False, self.github_token),
103
104
}
104
105
self.server_info = {
105
106
"name": "gpt4free-mcp-server",
@@ -560,7 +561,7 @@ def main(
560
561
safe: If True, start in safe mode — callers cannot override the module
561
562
allowlist for Python execution and workspace root listing is blocked.
562
563
"""
563
server = MCPServer(safe_mode=safe)
564
server = MCPServer(safe_mode=safe, github_token=os.environ.get("GITHUB_TOKEN"))
564
565
if http:
565
566
asyncio.run(server.run_http(host, port, origin))
566
567
else:
@@ -1149,6 +1149,7 @@ class GithubRepoTool(MCPTool):
1149
1149
headers = {
1150
1150
"Accept": "application/vnd.github+json",
1151
1151
"X-GitHub-Api-Version": "2022-11-28",
1152
"Authorization": f"Bearer {self.github_token}" if self.github_token else "",
1152
1153
}
1153
1154
async with ClientSession() as session:
1154
1155
async with session.get(search_url, headers=headers) as resp:
@@ -1239,6 +1240,7 @@ class GithubTextSearchTool(MCPTool):
1239
1240
headers = {
1240
1241
"Accept": "application/vnd.github+json",
1241
1242
"X-GitHub-Api-Version": "2022-11-28",
1243
"Authorization": f"Bearer {self.github_token}" if self.github_token else "",
1242
1244
}
1243
1245
async with ClientSession() as session:
1244
1246
async with session.get(search_url, headers=headers) as resp: