diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..a85a32e Binary files /dev/null and b/icon.png differ diff --git a/main.go b/main.go index 6c226a5..05f6863 100644 --- a/main.go +++ b/main.go @@ -118,12 +118,17 @@ func main() { } func getDefinition(word, sourceLang, targetLang string) ([]byte, error) { - wordKey := fmt.Sprintf("%s-%s:%s", sourceLang, targetLang, word) + // --- 新增:将接收到的单词统一转换为小写进行处理 --- + normalizedWord := strings.ToLower(word) + // --- 标准化结束 --- + + // 后续所有操作都使用这个标准化后的单词 + wordKey := fmt.Sprintf("%s-%s:%s", sourceLang, targetLang, normalizedWord) var cachedDefinition string err := db.QueryRow("SELECT definition FROM cache WHERE word_key = ?", wordKey).Scan(&cachedDefinition) if err == nil { - log.Printf("Cache hit from SQLite for key: %s", wordKey) + log.Printf("Cache hit for key: %s (Original: '%s')", wordKey, word) return []byte(cachedDefinition), nil } @@ -134,7 +139,8 @@ func getDefinition(word, sourceLang, targetLang string) ([]byte, error) { if !ok { return nil, fmt.Errorf("unsupported language pair: %s", promptKey) } - prompt := strings.Replace(promptTemplate, "${word}", word, -1) + // 使用标准化后的单词去填充Prompt + prompt := strings.Replace(promptTemplate, "${word}", normalizedWord, -1) requestBody, _ := json.Marshal(map[string]interface{}{"model": config.API.Model, "messages": []map[string]string{{"role": "user", "content": prompt}}}) req, _ := http.NewRequest("POST", config.API.URL, bytes.NewBuffer(requestBody)) diff --git a/static/goldendict-tutorial.html b/static/goldendict-tutorial.html new file mode 100644 index 0000000..2ed49b5 --- /dev/null +++ b/static/goldendict-tutorial.html @@ -0,0 +1,194 @@ + + +
+ + +通过本教程,您可以将这个强大的实时AI词典无缝集成到您本地的 GoldenDict 软件中,获得顶级的桌面端查词体验。
+ +GoldenDict 无法动态传递您选择的语言对。因此,您需要为您希望使用的**每一个语言对**(例如“英→汉”、“德→英”等)都单独添加一个词典条目。
+为了简化这个过程,我们提供了下面的 **URL生成器** 和常用示例。
+生成的URL (请复制):
+
+
+ 编辑 → 词典 (快捷键 F3)。网站 标签页, 然后点击 添加... 按钮。AI 词典 (英→汉)确定 保存。确定 使设置生效。为方便起见,这里提供一些常用组合的URL。请根据您的服务器地址(本地或远程)进行修改。
+http://localhost:8080/golden-dict?source=en&target=zh&word=%GDWORD%http://localhost:8080/golden-dict?source=de&target=zh&word=%GDWORD%http://localhost:8080/golden-dict?source=ja&target=zh&word=%GDWORD%http://localhost:8080/golden-dict?source=zh&target=en&word=%GDWORD%http://localhost:8080/golden-dict?source=en&target=en&word=%GDWORD%现在,您可以在 GoldenDict 中查词了。您添加的每一个语言对都会作为一个独立的标签页显示结果。
+