-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
111 lines (74 loc) · 1.74 KB
/
Copy pathscript.js
File metadata and controls
111 lines (74 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const API_KEY = "YOUR_GROQ_API_KEY";
const url =
"https://api.groq.com/openai/v1/chat/completions";
async function generateTrip() {
const destination =
document.getElementById("destination").value;
const days =
document.getElementById("days").value;
const budget =
document.getElementById("budget").value;
const output =
document.getElementById("output");
output.innerHTML = "Generating travel itinerary...";
if (!destination) {
output.innerHTML =
"Please enter a destination.";
return;
}
if (!days || days <= 0) {
output.innerHTML =
"Number of days must be greater than 0.";
return;
}
if (!budget) {
output.innerHTML =
"Please select a budget type.";
return;
}
const prompt = `
Create a realistic ${days}-day travel itinerary.
Destination:
${destination}
Budget Type:
${budget}
Requirements:
- include places to visit
- suggest food and activities
- maintain realistic pacing
- keep the plan balanced
- use clean day-wise formatting
`;
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "llama-3.1-8b-instant",
messages: [
{
role: "user",
content: prompt
}
]
})
});
const data = await response.json();
console.log(data);
if (!data.choices) {
output.innerHTML =
data.error?.message || "API Error";
return;
}
output.innerHTML =
data.choices[0].message.content;
}
catch (error) {
console.log(error);
output.innerHTML =
"Something went wrong.";
}
}