-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm.js
More file actions
75 lines (69 loc) · 2.24 KB
/
llm.js
File metadata and controls
75 lines (69 loc) · 2.24 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
const apiKeyInput = document.getElementById('apiKey');
window.onload = () => {
const savedKey = localStorage.getItem('api_key');
if (savedKey) {
apiKeyInput.value = savedKey;
}
};
apiKeyInput.addEventListener('change', () => {
localStorage.setItem('api_key', apiKeyInput.value);
});
async function llm_call(prompt) {
const url = "https://api.groq.com/openai/v1/chat/completions";
const model = "llama-3.1-8b-instant";
const apiKey = apiKeyInput.value;
if (!apiKey) {
alert("API Key is missing! Please input it in the header.");
}
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: model,
messages: [{ role: "user", content: prompt + " (output JSON only)" }],
temperature: 0.1,
max_completion_tokens: 1024,
top_p: 1,
stream: false,
stop: null,
response_format: { type: "json_object" }
})
});
const data = await response.json();
result = data.choices[0].message.content;
// console.log(JSON.stringify(result));
return result;
}
async function llm_do(intent) {
const url = "https://api.groq.com/openai/v1/chat/completions";
const model = "groq/compound";
const apiKey = apiKeyInput.value;
if (!apiKey) {
alert("API Key is missing! Please input it in the header.");
}
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: model,
messages: [{ role: "user", content: intent }],
temperature: 1,
max_completion_tokens: 1024,
top_p: 1,
stream: false,
stop: null,
compound_custom: {
"tools": {"enabled_tools": ["web_search", "code_interpreter", "visit_website"]}
}}),
});
const data = await response.json();
result = data.choices[0].message.content;
console.log(JSON.stringify(result));
return result;
}