-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathscript.js
64 lines (55 loc) · 1.27 KB
/
script.js
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
const VOWELS = [
'a', 'e', 'i', 'o', 'u',
]
function privateFunction() {
return 0
}
export function count_vowels() {
let input = Host.inputString()
let count = privateFunction()
for (let i = 0; i < input.length; i++) {
if (VOWELS.includes(input[i].toLowerCase())) {
count += 1
}
}
Host.outputString(JSON.stringify({count}))
return 0
}
export function greet() {
Host.outputString("Hello World from greet! " + Host.inputString())
return 0
}
export function greet2() {
console.log("console log")
console.error("console error")
Var.set("thing", "variable value")
Host.outputBytes(Var.get("thing"))
return 0
}
export function i_error_out() {
throw Error("I am an error")
}
export function call_http() {
let body = JSON.stringify({
"model": "gpt-3.5-turbo",
"temperature": 0.7,
"messages": [
{
"role": "user",
"content": "Please write a haiku about Wasm",
}
],
})
let resp = Http.request(
{
url: "https://api.openai.com/v1/chat/completions",
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${Config.get("open_ai_key")}`
}
},
body
)
Host.outputString(resp.body)
}