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 @@