Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/openAi/services/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const OpenAI = require("openai");
require("dotenv").config({ path: "../.env" });
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function classifyMessage(message) {
// const prompt = `
// You are a classification bot.
// Decide if this message is "general" (chit-chat, greeting, etc.)
// or "product" (asking about products, availability, price, size, color, etc.)
// Only return "general" or "product".
// Message: "${message}"
// `;
// const prompt = `
// You are a smart assistant that classifies a user message into exactly one intent.
// Available intents: product, talk_to_agent, help_line, delivery_info, order_process, previous_order, general, complain
// Examples:
// - "I want to buy a red t-shirt" → product
// - "Connect me with an admin" → talk_to_agent
// - "My package is delayed, need help" → help_line
// - "When will my order arrive?" → delivery_info
// - "How do I place an order?" → order_process
// - "Tell me about my last order" → previous_order
// - "Hello, how are you?" → general
// - "I am not happy with the product" → complain
// Classify the following message into one intent (return only the intent, no explanation):
// `;
const systemMessage = `
You are a chatbot intent classifier.
Classify user messages into one of these intents ONLY:
product, talk_to_agent, help_line, delivery_info, order_process, previous_order, general, complain.
Pay attention to context:
- If the user mentions a product but expresses dissatisfaction, classify as "complain".
- If the user wants to talk to admin/support, classify as "talk_to_agent".
Return ONLY the intent, no explanation.
`;
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: systemMessage },
{ role: "user", content: message }
]
// messages: [{ role: "user", content: systemMessage }],
});
const { prompt_tokens = 0, completion_tokens = 0, total_tokens = 0 } = response?.usage || {};
console.log(`Prompt tokens: ${prompt_tokens}, Completion tokens: ${completion_tokens}, Total tokens: ${total_tokens}`);
return response.choices[0].message.content.trim().toLowerCase();
}
classifyMessage("Hi, miya foul product disien.").then(console.log); // Example usage |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0348 ]-- |