From 3f3fd16f4f3e52f2bbc466ff93166b8a4df91f8c Mon Sep 17 00:00:00 2001 From: Xiaoyang Chen Date: Tue, 30 Jul 2024 10:37:02 +0000 Subject: [PATCH] update --- go/bin/args.go | 78 +++++++++++++++++++++ go/bin/{llm => }/chat.go | 31 ++++++++- go/bin/go.sum | 2 - go/bin/i18n.go | 32 +++++++-- go/bin/i18n_table.go | 61 +++++++++++++++++ go/bin/llm/main.go | 83 ----------------------- go/bin/llm_launcher/main.go | 75 -------------------- go/bin/llm_transcribe/main.go | 78 --------------------- go/bin/main.go | 54 +++++++++++++++ go/bin/posix.go | 21 +++++- go/bin/{llm_transcribe => }/transcribe.go | 37 ++++++++-- go/bin/windows.go | 2 +- go/llm/go.mod | 2 +- src/libllm/CMakeLists.txt | 10 +-- 14 files changed, 304 insertions(+), 262 deletions(-) create mode 100644 go/bin/args.go rename go/bin/{llm => }/chat.go (83%) delete mode 100644 go/bin/go.sum create mode 100644 go/bin/i18n_table.go delete mode 100644 go/bin/llm/main.go delete mode 100644 go/bin/llm_launcher/main.go delete mode 100644 go/bin/llm_transcribe/main.go create mode 100644 go/bin/main.go rename go/bin/{llm_transcribe => }/transcribe.go (68%) diff --git a/go/bin/args.go b/go/bin/args.go new file mode 100644 index 0000000..b97ab95 --- /dev/null +++ b/go/bin/args.go @@ -0,0 +1,78 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Xiaoyang Chen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main + +import ( + "flag" + "log" + "os" + "strings" + + "github.com/ling0322/libllm/go/llm" +) + +var gModelPath string +var gDevice string +var gInputFile string + +func addDeviceFlag(fs *flag.FlagSet) { + fs.StringVar(&gDevice, "device", "auto", "inference device, either cpu, cuda or auto") +} + +func getDeviceArg() llm.Device { + var device llm.Device + if strings.ToLower(gDevice) == "cpu" { + device = llm.Cpu + } else if strings.ToLower(gDevice) == "cuda" { + device = llm.Cuda + } else if strings.ToLower(gDevice) == "auto" { + device = llm.Auto + } else { + log.Fatalf("unexpected device %s", gDevice) + } + + return device +} + +func addModelFlag(fs *flag.FlagSet) { + fs.StringVar(&gModelPath, "model", "", "the libllm model file *.llmpkg") +} + +func getModelArg(fs *flag.FlagSet) string { + if gModelPath == "" { + fs.Usage() + os.Exit(1) + } + + return gModelPath +} + +func addInputFlag(fs *flag.FlagSet) { + fs.StringVar(&gInputFile, "input", "", "the input file.") +} + +func getInputArg(fs *flag.FlagSet) string { + if gInputFile == "" { + fs.Usage() + os.Exit(1) + } + + return gInputFile +} diff --git a/go/bin/llm/chat.go b/go/bin/chat.go similarity index 83% rename from go/bin/llm/chat.go rename to go/bin/chat.go index 2eaf078..4b1acbc 100644 --- a/go/bin/llm/chat.go +++ b/go/bin/chat.go @@ -22,6 +22,7 @@ package main import ( "bufio" "errors" + "flag" "fmt" "io" "log" @@ -33,7 +34,35 @@ import ( "github.com/ling0322/libllm/go/skill" ) -func chatMain(model llm.Model) { +func printChatUsage(fs *flag.FlagSet) { + fmt.Fprintln(os.Stderr, "Usage: llm chat [OPTIONS]") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Options:") + fs.PrintDefaults() + fmt.Fprintln(os.Stderr, "") +} + +func chatMain(args []string) { + fs := flag.NewFlagSet("", flag.ExitOnError) + fs.Usage = func() { + printChatUsage(fs) + } + + addModelFlag(fs) + addDeviceFlag(fs) + _ = fs.Parse(args) + + if fs.NArg() != 0 { + fs.Usage() + os.Exit(1) + } + + modelName := getModelArg(fs) + model, err := llm.NewModel(modelName, getDeviceArg()) + if err != nil { + log.Fatal(err) + } + llmChat, err := skill.NewChat(model) if err != nil { log.Fatal(err) diff --git a/go/bin/go.sum b/go/bin/go.sum deleted file mode 100644 index dc8e02b..0000000 --- a/go/bin/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/ling0322/libllm/go/i18n v0.0.0-20240626100001-bf6e1d13e2be h1:W/7pkPYLRaHvWNCezcFNzv/WzKSl7wZpkgKndToLh94= -github.com/ling0322/libllm/go/i18n v0.0.0-20240626100001-bf6e1d13e2be/go.mod h1:+AS95R9P+RH73A5IROS+q0l6NoozpyfJGhrBurYiokM= diff --git a/go/bin/i18n.go b/go/bin/i18n.go index c3d19de..7cae2f4 100644 --- a/go/bin/i18n.go +++ b/go/bin/i18n.go @@ -1,7 +1,25 @@ -package bin +// The MIT License (MIT) +// +// Copyright (c) 2024 Xiaoyang Chen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main import ( - "errors" "log" ) @@ -10,23 +28,23 @@ type Localizer struct { msgMap map[int]string } -func NewLocalizer(localeMsgMap map[string]map[int]string) (*Localizer, error) { +func NewLocalizer(localeMsgMap map[string]map[int]string) *Localizer { locale, err := getLocale() if err != nil { - locale = "" + locale = "en_us" } msgMap, ok := localeMsgMap[locale] if ok { - return &Localizer{locale, msgMap}, nil + return &Localizer{locale, msgMap} } msgMap, ok = localeMsgMap["en_us"] if !ok { - return nil, errors.New("en_us not found in the localeMsgMap") + log.Fatal("en_us not found in the localeMsgMap") } - return &Localizer{locale, msgMap}, nil + return &Localizer{locale, msgMap} } func (l *Localizer) Get(messageID int) string { diff --git a/go/bin/i18n_table.go b/go/bin/i18n_table.go new file mode 100644 index 0000000..9817b94 --- /dev/null +++ b/go/bin/i18n_table.go @@ -0,0 +1,61 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Xiaoyang Chen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main + +var gLocalizer = NewLocalizer(map[string]map[int]string{ + "en_us": gMsgEnUs, + "zh_cn": gMsgZhCn, +}) + +const ( + MsgErrMoreThanOnePkg = iota + MsgErrPkgNotExist + MsgErrError + MsgPressEnter + MsgInputQuestion + MsgInputQuestionNew + MsgInputQuestionSys + MsgNewSession + MsgStat +) + +var gMsgZhCn = map[int]string{ + MsgErrMoreThanOnePkg: "请不要在当前文件夹放多于1个的.llmpkg文件", + MsgErrPkgNotExist: "找不到.llmpkg文件", + MsgErrError: "错误: ", + MsgPressEnter: "按回车键继续...", + MsgInputQuestion: "请输入问题:", + MsgInputQuestionNew: " 输入 ':new' 重新开始一个新的对话 (清除历史).", + MsgInputQuestionSys: " 输入 ':sys <系统指令>' 设置对话的系统指令,并重新开始一个新的对话.", + MsgNewSession: "===== 新的对话 =====", + MsgStat: "(%d个Token, 总共耗时%.2f秒, 平均每个Token耗时%.2f毫秒)\n", +} + +var gMsgEnUs = map[int]string{ + MsgErrMoreThanOnePkg: "More than one .llmpkg in current directory. Please keep only one of them", + MsgErrPkgNotExist: "Unable to find .llmpkg model file in current directory", + MsgErrError: "Error: ", + MsgPressEnter: "Press [Enter] to continue ...", + MsgInputQuestion: "Please input your question.", + MsgInputQuestionNew: " Type ':new' to start a new session (clean history).", + MsgInputQuestionSys: " Type ':sys ' to set the system prompt and start a new session .", + MsgNewSession: "===== new session =====", + MsgStat: "(%d tokens, time=%.2fs, %.2fms per token)\n", +} diff --git a/go/bin/llm/main.go b/go/bin/llm/main.go deleted file mode 100644 index 42ecf2b..0000000 --- a/go/bin/llm/main.go +++ /dev/null @@ -1,83 +0,0 @@ -package main - -import ( - "flag" - "log" - "strings" - - "github.com/ling0322/libllm/go/bin" - "github.com/ling0322/libllm/go/llm" -) - -var gModelPath string -var gDevice string -var gTask string -var gAudioFile string -var gLocalizer *bin.Localizer - -const ( - MsgInputQuestion = iota - MsgInputQuestionNew - MsgInputQuestionSys - MsgNewSession - MsgStat -) - -var gMsgZhCn = map[int]string{ - MsgInputQuestion: "请输入问题:", - MsgInputQuestionNew: " 输入 ':new' 重新开始一个新的对话 (清除历史).", - MsgInputQuestionSys: " 输入 ':sys <系统指令>' 设置对话的系统指令,并重新开始一个新的对话.", - MsgNewSession: "===== 新的对话 =====", - MsgStat: "(%d个Token, 总共耗时%.2f秒, 平均每个Token耗时%.2f毫秒)\n", -} - -var gMsgEnUs = map[int]string{ - MsgInputQuestion: "Please input your question.", - MsgInputQuestionNew: " Type ':new' to start a new session (clean history).", - MsgInputQuestionSys: " Type ':sys ' to set the system prompt and start a new session .", - MsgNewSession: "===== new session =====", - MsgStat: "(%d tokens, time=%.2fs, %.2fms per token)\n", -} - -func main() { - flag.StringVar(&gModelPath, "model", "", "path of model file (.llmpkg)") - flag.StringVar(&gDevice, "device", "audo", "inference device (cpu|cuda|audo)") - flag.StringVar(&gAudioFile, "audio", "", "the input audio file, only used in transcribe task") - flag.StringVar(&gTask, "task", "chat", "the task to run (chat|transcribe)") - flag.Parse() - - var err error - gLocalizer, err = bin.NewLocalizer(map[string]map[int]string{ - "en_us": gMsgEnUs, - "zh_cn": gMsgZhCn, - }) - if err != nil { - log.Fatal(err) - } - - var device llm.Device - if strings.ToLower(gDevice) == "cpu" { - device = llm.Cpu - } else if strings.ToLower(gDevice) == "cuda" { - device = llm.Cuda - } else if strings.ToLower(gDevice) == "audo" { - device = llm.Auto - } else { - log.Fatalf("unexpected device %s", gDevice) - } - - if gModelPath == "" { - log.Fatal("argument -model is required") - } - - model, err := llm.NewModel(gModelPath, device) - if err != nil { - log.Fatal(err) - } - - if gTask == "chat" { - chatMain(model) - } else { - log.Fatalf("unexpected task: %s", gTask) - } -} diff --git a/go/bin/llm_launcher/main.go b/go/bin/llm_launcher/main.go deleted file mode 100644 index 0aab28d..0000000 --- a/go/bin/llm_launcher/main.go +++ /dev/null @@ -1,75 +0,0 @@ -// LLM launcher for windows. - -package main - -import ( - "fmt" - "log" - "os" - "os/exec" - "path/filepath" - - "github.com/ling0322/libllm/go/i18n" -) - -const ( - MsgErrMoreThanOnePkg = iota - MsgErrPkgNotExist - MsgErrError - MsgPressEnter -) - -var gMsgZhCn = map[int]string{ - MsgErrMoreThanOnePkg: "请不要在当前文件夹放多于1个的.llmpkg文件", - MsgErrPkgNotExist: "找不到.llmpkg文件", - MsgErrError: "错误: ", - MsgPressEnter: "按回车键继续...", -} - -var gMsgEnUs = map[int]string{ - MsgErrMoreThanOnePkg: "More than one .llmpkg in current directory. Please keep only one of them", - MsgErrPkgNotExist: "Unable to find .llmpkg model file in current directory", - MsgErrError: "Error: ", - MsgPressEnter: "Press [Enter] to continue ...", -} - -func main() { - fmt.Println(`>>==================================================<<`) - fmt.Println(`|| ____ ____ ______ ____ ____ ____ __ ||`) - fmt.Println(`||| | | || >| | | | | \ / |||`) - fmt.Println(`||| |_ | || < | |_ | |_ | \/ |||`) - fmt.Println(`|||______||____||______>|______||______||__/\__/|__|||`) - fmt.Println(`>>==================================================<<`) - fmt.Println() - - localizer, err := i18n.NewLocalizer(map[string]map[int]string{ - "en_us": gMsgEnUs, - "zh_cn": gMsgZhCn, - }) - if err != nil { - log.Fatal(err) - } - - llmpkgFiles, err := filepath.Glob("*.llmpkg") - if err != nil { - log.Fatal(err) - } - - if len(llmpkgFiles) > 1 { - fmt.Fprintln(os.Stderr, localizer.Get(MsgErrMoreThanOnePkg)) - } else if len(llmpkgFiles) == 0 { - fmt.Fprintln(os.Stderr, localizer.Get(MsgErrPkgNotExist)) - } else { - cmd := exec.Command(".\\llm.exe", "-model", llmpkgFiles[0]) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin - - if err := cmd.Run(); err != nil { - os.Stderr.WriteString(localizer.Get(MsgErrError) + err.Error() + "\n") - } - } - - fmt.Println(localizer.Get(MsgPressEnter)) - fmt.Scanln() -} diff --git a/go/bin/llm_transcribe/main.go b/go/bin/llm_transcribe/main.go deleted file mode 100644 index f3a51a5..0000000 --- a/go/bin/llm_transcribe/main.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "flag" - "log" - "strings" - - "github.com/ling0322/libllm/go/bin" - "github.com/ling0322/libllm/go/llm" -) - -var gModelPath string -var gDevice string -var gInputFile string -var gLocalizer *bin.Localizer -var gFfmpegBin string - -const ( - MsgInputQuestion = iota - MsgInputQuestionNew - MsgInputQuestionSys - MsgNewSession - MsgStat -) - -var gMsgZhCn = map[int]string{ - MsgInputQuestion: "请输入问题:", - MsgInputQuestionNew: " 输入 ':new' 重新开始一个新的对话 (清除历史).", - MsgInputQuestionSys: " 输入 ':sys <系统指令>' 设置对话的系统指令,并重新开始一个新的对话.", - MsgNewSession: "===== 新的对话 =====", - MsgStat: "(%d个Token, 总共耗时%.2f秒, 平均每个Token耗时%.2f毫秒)\n", -} - -var gMsgEnUs = map[int]string{ - MsgInputQuestion: "Please input your question.", - MsgInputQuestionNew: " Type ':new' to start a new session (clean history).", - MsgInputQuestionSys: " Type ':sys ' to set the system prompt and start a new session .", - MsgNewSession: "===== new session =====", - MsgStat: "(%d tokens, time=%.2fs, %.2fms per token)\n", -} - -func main() { - flag.StringVar(&gModelPath, "model", "", "path of model file (.llmpkg)") - flag.StringVar(&gDevice, "device", "audo", "inference device (cpu|cuda|audo)") - flag.StringVar(&gInputFile, "input", "", "the input audio file, only used in transcribe task") - flag.Parse() - - var err error - gLocalizer, err = bin.NewLocalizer(map[string]map[int]string{ - "en_us": gMsgEnUs, - "zh_cn": gMsgZhCn, - }) - if err != nil { - log.Fatal(err) - } - - var device llm.Device - if strings.ToLower(gDevice) == "cpu" { - device = llm.Cpu - } else if strings.ToLower(gDevice) == "cuda" { - device = llm.Cuda - } else if strings.ToLower(gDevice) == "audo" { - device = llm.Auto - } else { - log.Fatalf("unexpected device %s", gDevice) - } - - if gModelPath == "" { - log.Fatal("argument -model is required") - } - - model, err := llm.NewModel(gModelPath, device) - if err != nil { - log.Fatal(err) - } - - transcribeMain(model) -} diff --git a/go/bin/main.go b/go/bin/main.go new file mode 100644 index 0000000..ee16b7c --- /dev/null +++ b/go/bin/main.go @@ -0,0 +1,54 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Xiaoyang Chen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main + +import ( + "fmt" + "os" +) + +func printCommandUsage() { + fmt.Fprintln(os.Stderr, "Usage: llm COMMAND") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Commands:") + fmt.Fprintln(os.Stderr, " chat Chat with LLM") + fmt.Fprintln(os.Stderr, " transcribe Transcribe audio or video file to text") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Run 'llm COMMAND -h' for more information on a command.") +} + +func main() { + if len(os.Args) == 1 { + printCommandUsage() + os.Exit(1) + } + + command := os.Args[1] + switch command { + case "chat": + chatMain(os.Args[2:]) + case "transcribe": + transcribeMain(os.Args[2:]) + default: + fmt.Fprintf(os.Stderr, "Invalid command \"%s\"\n\n", command) + printCommandUsage() + os.Exit(1) + } +} diff --git a/go/bin/posix.go b/go/bin/posix.go index 44d7623..2f46fc1 100644 --- a/go/bin/posix.go +++ b/go/bin/posix.go @@ -1,7 +1,26 @@ //go:build !windows // +build !windows -package bin +// The MIT License (MIT) +// +// Copyright (c) 2024 Xiaoyang Chen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main import ( "fmt" diff --git a/go/bin/llm_transcribe/transcribe.go b/go/bin/transcribe.go similarity index 68% rename from go/bin/llm_transcribe/transcribe.go rename to go/bin/transcribe.go index f808bb7..9f7ead9 100644 --- a/go/bin/llm_transcribe/transcribe.go +++ b/go/bin/transcribe.go @@ -20,6 +20,7 @@ package main import ( + "flag" "fmt" "log" "os" @@ -28,12 +29,40 @@ import ( "github.com/ling0322/libllm/go/skill" ) -func transcribeMain(model llm.Model) { - if gInputFile == "" { - log.Fatal("argument -input is required for transcribe task") +func printTranscribeUsage(fs *flag.FlagSet) { + fmt.Fprintln(os.Stderr, "Usage: llm transribe [OPTIONS]") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Options:") + fs.PrintDefaults() + fmt.Fprintln(os.Stderr, "") +} + +func transcribeMain(args []string) { + fs := flag.NewFlagSet("", flag.ExitOnError) + fs.Usage = func() { + printTranscribeUsage(fs) + } + + addDeviceFlag(fs) + addModelFlag(fs) + addInputFlag(fs) + _ = fs.Parse(args) + + modelFile := getModelArg(fs) + device := getDeviceArg() + inputFile := getInputArg(fs) + + if fs.NArg() != 0 { + fs.Usage() + os.Exit(1) + } + + model, err := llm.NewModel(modelFile, device) + if err != nil { + log.Fatal(err) } - fd, err := os.Open(gInputFile) + fd, err := os.Open(inputFile) if err != nil { log.Fatal(err) } diff --git a/go/bin/windows.go b/go/bin/windows.go index 6b80619..8d1fe56 100644 --- a/go/bin/windows.go +++ b/go/bin/windows.go @@ -4,7 +4,7 @@ // Original source file: https://github.com/jeandeaual/go-locale/blob/master/locale_windows.go // LICENSE: MIT: https://github.com/jeandeaual/go-locale/blob/master/LICENSE -package bin +package main import ( "strings" diff --git a/go/llm/go.mod b/go/llm/go.mod index 541b039..0ad9bbd 100644 --- a/go/llm/go.mod +++ b/go/llm/go.mod @@ -1,3 +1,3 @@ module github.com/ling0322/libllm/go/llm -go 1.15 +go 1.21 diff --git a/src/libllm/CMakeLists.txt b/src/libllm/CMakeLists.txt index 704af33..4984bee 100644 --- a/src/libllm/CMakeLists.txt +++ b/src/libllm/CMakeLists.txt @@ -260,13 +260,5 @@ add_test(NAME unittest COMMAND $) add_custom_target(llmbin ALL DEPENDS libllm - COMMAND go build -o $>/llm${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_SOURCE_DIR}/go/bin/llm + COMMAND go build -o $>/llm${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_SOURCE_DIR}/go/bin WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/go/bin) - -add_custom_target(llmtranscribe - ALL - DEPENDS libllm - COMMAND go build - -o $>/llm-transcribe${CMAKE_EXECUTABLE_SUFFIX} - ${CMAKE_SOURCE_DIR}/go/bin/llm_transcribe - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/go/bin) \ No newline at end of file