commit 9ffef462dd4ed5f964c6f17ed8dc42f05d7c55cc Author: hailin Date: Fri Jul 18 22:51:27 2025 +0800 first commit diff --git a/extract_chat_template.py b/extract_chat_template.py new file mode 100644 index 0000000..1b174f3 --- /dev/null +++ b/extract_chat_template.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# extract_chat_template.py —— 最终版 +# +# 用法示例: +# # 只导出原模板 +# python extract_chat_template.py Qwen3-32B/tokenizer_config.json \ +# -o Qwen3-32B/chat_template.jinja +# +# # 同时导出“无 ”版本 +# python extract_chat_template.py Qwen3-32B/tokenizer_config.json \ +# -o Qwen3-32B/chat_template.jinja \ +# --no-think \ +# -n Qwen3-32B/chat_template_nothink.jinja +# +# # -o/-n 若省略,就写到当前目录:chat_template.jinja / chat_template_nothink.jinja + +import argparse, json, re, sys +from pathlib import Path + +def main(): + p = argparse.ArgumentParser() + p.add_argument("config", type=Path, help="tokenizer_config.json 路径") + p.add_argument("-o", "--output", type=Path, + default=Path("chat_template.jinja"), + help="原始模板输出文件(默认 chat_template.jinja)") + p.add_argument("--no-think", action="store_true", + help="额外生成去掉 块的模板") + p.add_argument("-n", "--no-think-out", type=Path, + help="无 模板输出文件(默认 chat_template_nothink.jinja)") + args = p.parse_args() + + try: + tpl = json.loads(args.config.read_text(encoding="utf-8"))["chat_template"] + except Exception as e: + sys.exit(f"❌ 读取失败:{e}") + + # 写原始模板 + args.output.write_text(tpl, encoding="utf-8") + print(f"✅ 原模板 → {args.output.resolve()}") + + # 写无思考模板(可选) + if args.no_think: + nt_path = args.no_think_out or Path("chat_template_nothink.jinja") + nt_path.write_text(re.sub(r".*?", "", tpl, flags=re.S), + encoding="utf-8") + print(f"✅ 无 模板 → {nt_path.resolve()}") + +if __name__ == "__main__": + main() + diff --git a/extract_chat_template_ReadMe.txt b/extract_chat_template_ReadMe.txt new file mode 100644 index 0000000..db796b5 --- /dev/null +++ b/extract_chat_template_ReadMe.txt @@ -0,0 +1,9 @@ +# ① 只导出原始模板 +python extract_chat_template.py Qwen3-32B/tokenizer_config.json \ + -o Qwen3-32B/chat_template.jinja + +# ② 同时导出“无 ”版本 +python extract_chat_template.py Qwen3-32B/tokenizer_config.json \ + -o Qwen3-32B/chat_template.jinja \ + --no-think \ + -n Qwen3-32B/chat_template_nothink.jinja diff --git a/make_supabase_api_url.go b/make_supabase_api_url.go new file mode 100644 index 0000000..b47d453 --- /dev/null +++ b/make_supabase_api_url.go @@ -0,0 +1,83 @@ +package main + +import ( + "bytes" + "fmt" + "net" + "os/exec" + "strings" +) + +func getSupabaseURL() string { + // 获取默认网关 IP + gatewayIP, err := getDefaultGateway() + if err != nil { + fmt.Println("⚠️ 获取默认网关失败,使用 fallback:", err) + return "http://localhost:8000" + } + + // 获取所有本地网卡 IP 和子网 + ifaces, err := net.Interfaces() + if err != nil { + fmt.Println("⚠️ 获取本地接口失败:", err) + return "http://localhost:8000" + } + + for _, iface := range ifaces { + if (iface.Flags&net.FlagUp == 0) || (iface.Flags&net.FlagLoopback != 0) { + continue // 跳过不活跃或loopback接口 + } + + addrs, err := iface.Addrs() + if err != nil { + continue + } + + for _, addr := range addrs { + ipNet, ok := addr.(*net.IPNet) + if !ok || ipNet.IP.To4() == nil { + continue + } + + // 检查网关是否在这个接口的子网中 + if ipNet.Contains(gatewayIP) { + // 找到同网段的IP + return fmt.Sprintf("http://%s:8000", ipNet.IP.String()) + } + } + } + + // 如果没有匹配的网段,使用 fallback + return "http://localhost:8000" +} + +func getDefaultGateway() (net.IP, error) { + // 调用 Linux 命令获取默认路由 + cmd := exec.Command("ip", "route", "show", "default") + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + return nil, err + } + + lines := strings.Split(out.String(), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "default") { + fields := strings.Fields(line) + for i, f := range fields { + if f == "via" && i+1 < len(fields) { + return net.ParseIP(fields[i+1]), nil + } + } + } + } + + return nil, fmt.Errorf("default gateway not found") +} + +func main() { + supabaseURL := getSupabaseURL() + fmt.Printf("\"SUPABASE_URL\": \"%s\"\n", supabaseURL) +} +