From 8e5669e5b760c56c46511fd1b209d258039c5ed1 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Mon, 9 Jun 2025 23:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=AE=9E=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E7=BA=AF=E7=95=8C=E9=9D=A2=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai.js | 21 +++++++++++++++++++++ index.html | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ai.js diff --git a/ai.js b/ai.js new file mode 100644 index 0000000..7b1e4cc --- /dev/null +++ b/ai.js @@ -0,0 +1,21 @@ +import * as Ai from '@kevisual/ai'; + +console.log('Chat module loaded', Ai); + +const ai = new Ai.SiliconFlowProvider({ + model: 'Qwen/Qwen2-7B-Instruct', + apiKey: process.env.OPENAI_API_KEY, +}); + +export const chat = async (messages) => { + try { + const response = await ai.chat(messages); + return response.choices[0].message.content; + } catch (error) { + console.error('Error in chat completion:', error); + throw error; // Re-throw the error for further handling + } +}; +// Example usage +// const res = await chat([{ role: 'user', content: 'Hello, how are you?' }]); +// console.log('Chat response:', res); diff --git a/index.html b/index.html index 9d94fee..5ca28af 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,9 @@ @@ -34,6 +36,7 @@
123
+ \ No newline at end of file