22 lines
616 B
JavaScript

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);