import express from 'express'; import cors from 'cors'; import dotenv from 'dotenv'; import { Configuration, OpenAIApi } from 'openai'; dotenv.config(); const app = express(); app.use(cors()); app.use(express.json()); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); // Paste your detailed wiki info here — copy & paste as a big string! // For example, I put a detailed The Wild West wiki summary below: const wikiExcerpt = ` The Wild West is a Roblox game created by Onett. It is set in the American Old West and includes activities like bounty hunting, trading, mining, and gunfights. Players can explore towns, take part in auctions, buy horses and weapons, and engage in PvP combat. Gameplay: - Players start in Bronze City, the main hub. - Players can collect bounties from Bounty Boards by hunting NPC outlaws. - The auction house lets players buy and sell weapons, horses, and other items. - Weapons include revolvers, rifles, shotguns, and dynamite. - Horses have different breeds and stats, like speed and stamina. Locations: - Bronze City (starting town) - Raider Canyons (dangerous area with bandits) - Outlaw Hideout (high-level PvP zone) - Mining Camps Auctions and Items: - Auction items change regularly and include rare weapons like the Golden Buffalo Rifle. - Players bid using in-game currency earned from missions and hunting. - Items can be traded between players. Combat: - Gunfights are skill-based, involving aiming and timing. - Players can use cover and different weapons tactically. - Bounty hunting rewards players for capturing or killing NPC outlaws. Trading: - Players can trade items and horses with others. - Certain rare items are highly sought after in the community. Missions and Progression: - Missions offer experience and currency rewards. - Players can level up and unlock new weapons and features. - The game has seasonal events and updates. `; app.post('/chat', async (req, res) => { const question = req.body.question; if (!question) return res.status(400).json({ error: 'Missing question' }); const prompt = ` You are an expert on the Roblox game "The Wild West." Use the following information to answer the question: ${wikiExcerpt} Question: ${question} Answer: `; try { const completion = await openai.createChatCompletion({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: prompt }], max_tokens: 300, temperature: 0.7, }); const answer = completion.data.choices[0].message.content.trim(); res.json({ answer }); } catch (error) { console.error(error); res.status(500).json({ error: 'OpenAI API error' }); } }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log(`Server running on port ${PORT}`));