@@ -3,6 +3,23 @@ const { Groq } = require('groq-sdk');
33const print = require ( './lib/print' ) ;
44const parseString = require ( 'xml2js' ) . parseString ;
55const ora = require ( 'ora' ) ;
6+ const gradient = require ( 'gradient-string' ) ;
7+
8+ const gradients = [
9+ 'cristal' ,
10+ 'teen' ,
11+ 'mind' ,
12+ 'morning' ,
13+ 'vice' ,
14+ 'passion' ,
15+ 'fruit' ,
16+ 'instagram' ,
17+ 'atlas' ,
18+ 'retro' ,
19+ 'summer' ,
20+ 'pastel' ,
21+ 'rainbow' ,
22+ ] ;
623
724module . exports = async ( word , options ) => {
825 console . log ( '' ) ;
@@ -13,7 +30,7 @@ module.exports = async (word, options) => {
1330 if ( isTrueOrUndefined ( iciba ) ) {
1431 const ICIBA_URL =
1532 'http://dict-co.iciba.com/api/dictionary.php?key=D191EBD014295E913574E1EAF8E06666&w=' ;
16- const spinner = ora ( '正在查询 iciba...' ) . start ( ) ;
33+ const spinner = ora ( '正在请教 iciba...' ) . start ( ) ;
1734 try {
1835 const response = await needle ( 'get' , `${ ICIBA_URL } ${ endcodedWord } ` , { parse : false } ) ;
1936 if ( response . statusCode === 200 ) {
@@ -37,8 +54,7 @@ module.exports = async (word, options) => {
3754 apiKey : GROQ_API_KEY || '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' ,
3855 } ) ;
3956 const model = 'llama3-groq-70b-8192-tool-use-preview' ;
40-
41- const spinner = ora ( '正在查询 Groq AI...' ) . start ( ) ;
57+ const spinner = ora ( `正在请教 ${ model } ...` ) . start ( ) ;
4258 try {
4359 const chatCompletion = await groqClient . chat . completions . create ( {
4460 messages : [
@@ -48,7 +64,7 @@ module.exports = async (word, options) => {
4864你是一本专业的中英文双语词典。请按照以下要求提供翻译和解释:
4965
50661. 格式要求:
51- [原词] [音标] ~ [翻译] [拼音]
67+ [原词] [音标] ~ [翻译] [拼音] ~ [EMOJI]
5268
5369 - [词性] [释义1]
5470 - [词性] [释义2]
@@ -61,15 +77,14 @@ module.exports = async (word, options) => {
6177 [翻译]
6278 ...
6379
64- ❤️
65- [座右铭]
80+ [EMOJI] [座右铭]
6681 -----
6782
68832. 翻译规则:
6984 - 英文输入翻译为中文,中文输入翻译为英文
7085 - 提供准确的音标(英文)或拼音(中文)
7186 - 列出所有常见词性及其对应的释义
72- - 释义应简洁明了,涵盖词语的主要含义
87+ - 释义应简洁明了,涵盖词语的主要含义,使用中文
7388 - 提供2-3个地道的例句,体现词语的不同用法和语境
7489
75903. 内容质量:
@@ -83,10 +98,12 @@ module.exports = async (word, options) => {
8398 - 注明词语的使用范围,如地域、行业特定用语等
8499 - 对于缩写词,提供完整形式和解释
85100
101+ 5. 格式中的 [EMOJI] 指的是一个 emoji 表情符号,请根据词性、释义、例句等选择合适的表情符号。
102+
86103请基于以上要求,为用户提供简洁、专业、全面且易于理解的词语翻译和解释。
87104
88105---
89- 最后使用这个词写一句简短的积极向上令人深思的英文座右铭。
106+ 最后使用这个词写一句简短的积极向上令人深思的英文座右铭,并提供中文翻译。但回复中不要包含"座右铭"三个字
90107` ,
91108 } ,
92109 {
@@ -98,15 +115,12 @@ module.exports = async (word, options) => {
98115 temperature : 0.3 ,
99116 max_tokens : 1024 ,
100117 top_p : 0.8 ,
101- stream : true ,
102- stop : null ,
103118 } ) ;
104119 spinner . stop ( ) ;
105- for await ( const chunk of chatCompletion ) {
106- process . stdout . write ( chunk . choices [ 0 ] ?. delta ?. content || '' ) ;
107- }
120+ const randomGradient = gradients [ Math . floor ( Math . random ( ) * gradients . length ) ] ;
121+ console . log ( gradient [ randomGradient ] ( chatCompletion . choices [ 0 ] . message . content ) ) ;
108122 } catch ( error ) {
109- spinner . fail ( ' 访问 Groq AI 失败,请检查网络或 API 密钥' ) ;
123+ spinner . fail ( ` 访问 ${ model } 失败,请检查网络或 API 密钥` ) ;
110124 }
111125 }
112126} ;
0 commit comments