-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
62 lines (49 loc) · 1.88 KB
/
Copy pathexample.html
File metadata and controls
62 lines (49 loc) · 1.88 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
<!DOCTYPE html>
<html>
<head>
<script type="module">
import { createAIAgent } from './js-agent.js';
import { createTestService } from './test-service.js';
import { commandFunctions } from './command-functions.js';
// Create test service
const test = createTestService({ debug: true });
// Define services
const services = {
test
};
const systemMessage = "You are a helpful AI assistant. Anwer in short sentences and provide useful information.";
// Callback function for AI response in stream mode
function aiResponseCallback(response) {
console.log("AI Response Chunk: ", response)
};
// Main
document.addEventListener('DOMContentLoaded', async function(e) {
// Create AI agent
const agent = createAIAgent({
oaiUrl: 'https://api.openai.com/v1/chat/completions',
oaiApiKey: "INSERT OPENAI API KEY HERE",
systemMessage: systemMessage,
model: 'gpt-3.5-turbo',
temperature: 0.7,
maxTokens: 4096,
services,
commandFunctions,
debugEnabled: true,
aiResponseCallback: aiResponseCallback
});
// Process a message (triggering a function call to the a defined service)
if (agent.available) {
await agent.processMessage("What is the current date?").then((response) => {
console.log("Main: Response: ", response);
if (response) {
console.log("End of request");
}
});
} else {
console.log("Main: AI agent is busy. Please try again later.");
}
});
</script>
</head>
<body></body>
</html>