integrate openrouter api - Initial Deployment
Browse files- index.html +31 -6
- prompts.txt +1 -0
index.html
CHANGED
|
@@ -314,11 +314,22 @@
|
|
| 314 |
</div>
|
| 315 |
|
| 316 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
// Initialize the app
|
| 318 |
document.addEventListener('DOMContentLoaded', function() {
|
| 319 |
const chatArea = document.getElementById('chat-area');
|
| 320 |
const languageBtn = document.getElementById('language-btn');
|
| 321 |
let currentLanguage = 'en';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
// Simulate API connection
|
| 324 |
setTimeout(() => {
|
|
@@ -499,7 +510,7 @@
|
|
| 499 |
const inputField = document.querySelector('input[type="text"]');
|
| 500 |
const sendButton = document.querySelector('.fa-paper-plane').parentNode;
|
| 501 |
|
| 502 |
-
function sendMessage() {
|
| 503 |
const message = inputField.value.trim();
|
| 504 |
if (message) {
|
| 505 |
const userMessage = document.createElement('div');
|
|
@@ -529,8 +540,9 @@
|
|
| 529 |
chatArea.appendChild(typing);
|
| 530 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
|
|
|
| 534 |
typing.remove();
|
| 535 |
|
| 536 |
const botResponse = document.createElement('div');
|
|
@@ -538,13 +550,26 @@
|
|
| 538 |
botResponse.innerHTML = `
|
| 539 |
<div class="message-bubble bot-message p-4 relative">
|
| 540 |
<div class="absolute -left-2 top-0 w-4 h-4 bg-amber-200 transform -skew-x-12"></div>
|
| 541 |
-
<p class="text-amber-900">
|
| 542 |
-
<p class="text-sm text-amber-700 mt-2">หากคุณต้องการข้อมูลเฉพาะเจาะจงมากขึ้น โปรดแจ้งให้ฉันทราบนะคะ</p>
|
| 543 |
</div>
|
| 544 |
`;
|
| 545 |
chatArea.appendChild(botResponse);
|
| 546 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 547 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
|
|
|
| 314 |
</div>
|
| 315 |
|
| 316 |
<script>
|
| 317 |
+
// OpenRouter API Configuration
|
| 318 |
+
const OPENROUTER_API_KEY = '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'; // Replace with your actual key
|
| 319 |
+
const OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/chat/completions';
|
| 320 |
+
const OPENROUTER_MODEL = 'openchat/openchat-7b'; // You can change this to preferred model
|
| 321 |
+
|
| 322 |
// Initialize the app
|
| 323 |
document.addEventListener('DOMContentLoaded', function() {
|
| 324 |
const chatArea = document.getElementById('chat-area');
|
| 325 |
const languageBtn = document.getElementById('language-btn');
|
| 326 |
let currentLanguage = 'en';
|
| 327 |
+
let conversationHistory = [
|
| 328 |
+
{
|
| 329 |
+
role: "system",
|
| 330 |
+
content: "คุณคือผู้ช่วยทางการท่องเที่ยวสำหรับ Tour Der Wang ที่วังสามหมอ จ.อุดรธานี จงตอบคำถามเกี่ยวกับสถานที่ท่องเที่ยว แพ็คเกจทัวร์ และกิจกรรมต่าง ๆ ในพื้นที่วังสามหมออย่างเป็นมิตรและให้ข้อมูลครบถ้วน"
|
| 331 |
+
}
|
| 332 |
+
];
|
| 333 |
|
| 334 |
// Simulate API connection
|
| 335 |
setTimeout(() => {
|
|
|
|
| 510 |
const inputField = document.querySelector('input[type="text"]');
|
| 511 |
const sendButton = document.querySelector('.fa-paper-plane').parentNode;
|
| 512 |
|
| 513 |
+
async function sendMessage() {
|
| 514 |
const message = inputField.value.trim();
|
| 515 |
if (message) {
|
| 516 |
const userMessage = document.createElement('div');
|
|
|
|
| 540 |
chatArea.appendChild(typing);
|
| 541 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 542 |
|
| 543 |
+
try {
|
| 544 |
+
const apiResponse = await callOpenRouterApi(message);
|
| 545 |
+
|
| 546 |
typing.remove();
|
| 547 |
|
| 548 |
const botResponse = document.createElement('div');
|
|
|
|
| 550 |
botResponse.innerHTML = `
|
| 551 |
<div class="message-bubble bot-message p-4 relative">
|
| 552 |
<div class="absolute -left-2 top-0 w-4 h-4 bg-amber-200 transform -skew-x-12"></div>
|
| 553 |
+
<p class="text-amber-900">${apiResponse}</p>
|
|
|
|
| 554 |
</div>
|
| 555 |
`;
|
| 556 |
chatArea.appendChild(botResponse);
|
| 557 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 558 |
+
} catch (error) {
|
| 559 |
+
console.error('Error:', error);
|
| 560 |
+
typing.remove();
|
| 561 |
+
|
| 562 |
+
const botResponse = document.createElement('div');
|
| 563 |
+
botResponse.className = 'flex mb-4';
|
| 564 |
+
botResponse.innerHTML = `
|
| 565 |
+
<div class="message-bubble bot-message p-4 relative">
|
| 566 |
+
<div class="absolute -left-2 top-0 w-4 h-4 bg-amber-200 transform -skew-x-12"></div>
|
| 567 |
+
<p class="text-amber-900">ขออภัยค่ะ เกิดข้อผิดพลาดในการเชื่อมต่อกับระบบ โปรดลองอีกครั้งในภายหลัง</p>
|
| 568 |
+
</div>
|
| 569 |
+
`;
|
| 570 |
+
chatArea.appendChild(botResponse);
|
| 571 |
+
chatArea.scrollTop = chatArea.scrollHeight;
|
| 572 |
+
}
|
| 573 |
}
|
| 574 |
}
|
| 575 |
|
prompts.txt
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
integrate openrouter api
|