Skip to content

Commit 5dc0651

Browse files
committed
modified: hug-1.js
modified: hug.js
1 parent 0597b5d commit 5dc0651

2 files changed

Lines changed: 108 additions & 99 deletions

File tree

hug-1.js

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,72 +12,76 @@ const hfchat = process.env.HFCHAT
1212
const cookie = `token=${token}; hf-chat=${hfchat}`
1313

1414
function hug(msg) {
15-
return new Promise((resolve) => {
15+
return new Promise(async (resolve) => {
1616
if (!token) return "Huggingface token not provided"
1717
if (!hfchat) return "hfchat not provided"
18-
fetch("https://huggingface.co/chat/conversation", {
18+
19+
let data = process.env.CONV ? { "conversationId": process.env.CONV } : await newConversationId().then(data => data)
20+
21+
process.env.CONV = data.conversationId
22+
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}/__data.json?x-sveltekit-invalidated=1_1`, {
1923
"headers": {
20-
"content-type": "application/json",
2124
"cookie": cookie
2225
},
23-
"body": "{\"model\":\"OpenAssistant/oasst-sft-6-llama-30b-xor\"}",
24-
"method": "POST"
26+
"body": null,
27+
"method": "GET"
2528
})
26-
.then(data => data.json())
27-
.then(data => {
28-
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}/__data.json?x-sveltekit-invalidated=1_1`, {
29+
.then(() => {
30+
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}`, {
2931
"headers": {
32+
"content-type": "application/json",
3033
"cookie": cookie
3134
},
32-
"body": null,
33-
"method": "GET"
34-
})
35-
.then(() => {
36-
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}`, {
37-
"headers": {
38-
"content-type": "application/json",
39-
"cookie": cookie
40-
},
41-
"body": JSON.stringify({
42-
"inputs": msg,
43-
"parameters": {
44-
"temperature": 0.2,
45-
"truncate": 1000,
46-
"max_new_tokens": 1024,
47-
"stop": [
48-
"</s>"
49-
],
50-
"top_p": 0.95,
51-
"repetition_penalty": 1.2,
52-
"top_k": 50,
53-
"return_full_text": false
54-
},
55-
"stream": true,
56-
"options": {
57-
"id": randomUUID(),
58-
"response_id": randomUUID(),
59-
"is_retry": false,
60-
"use_cache": false,
61-
"web_search_id": ""
62-
}
63-
}),
64-
"method": "POST"
65-
}).then(dataa => dataa.text())
66-
.then(dataa => {
67-
dataa = JSON.parse(dataa.slice(dataa.lastIndexOf('data:{"token":{') + 'data:'.length)).generated_text
68-
resolve(dataa)
69-
})
35+
"body": JSON.stringify({
36+
"inputs": msg,
37+
"parameters": {
38+
"temperature": 0.2,
39+
"truncate": 1000,
40+
"max_new_tokens": 1024,
41+
"stop": [
42+
"</s>"
43+
],
44+
"top_p": 0.95,
45+
"repetition_penalty": 1.2,
46+
"top_k": 50,
47+
"return_full_text": false
48+
},
49+
"stream": true,
50+
"options": {
51+
"id": randomUUID(),
52+
"response_id": randomUUID(),
53+
"is_retry": false,
54+
"use_cache": false,
55+
"web_search_id": ""
56+
}
57+
}),
58+
"method": "POST"
59+
}).then(dataa => dataa.text())
60+
.then(dataa => {
61+
dataa = JSON.parse(dataa.slice(dataa.lastIndexOf('data:{"token":{') + 'data:'.length)).generated_text
62+
resolve(dataa)
7063
})
71-
72-
7364
})
65+
66+
})
67+
}
68+
function newConversationId() {
69+
return new Promise((resolve) => {
70+
fetch("https://huggingface.co/chat/conversation", {
71+
"headers": {
72+
"content-type": "application/json",
73+
"cookie": cookie
74+
},
75+
"body": "{\"model\":\"OpenAssistant/oasst-sft-6-llama-30b-xor\"}",
76+
"method": "POST"
77+
}).then(data => data.json())
78+
.then(data => resolve(data))
7479
})
7580
}
76-
7781
function ask() {
78-
rl.question("\033[35mYou: \033[34m> \033[36m", (msg) => {
82+
rl.question("You: > ", (msg) => {
7983
hug(msg).then(data => {
80-
console.log("😊 : \033[34m" + data)
84+
console.log("😊 : " + data)
8185
ask()
8286
})
8387
})

hug.js

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,70 @@ const hfchat = env.HFCHAT
66
const cookie = `token=${token}; hf-chat=${hfchat}`
77

88
function hug(msg) {
9-
return new Promise((resolve) => {
9+
return new Promise(async (resolve) => {
1010
if (!token) return "Huggingface token not provided"
1111
if (!hfchat) return "hfchat not provided"
12-
fetch("https://huggingface.co/chat/conversation", {
12+
13+
let data = process.env.CONV ? { "conversationId": process.env.CONV } : await newConversationId().then(data => data)
14+
15+
process.env.CONV = data.conversationId
16+
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}/__data.json?x-sveltekit-invalidated=1_1`, {
1317
"headers": {
14-
"content-type": "application/json",
1518
"cookie": cookie
1619
},
17-
"body": "{\"model\":\"OpenAssistant/oasst-sft-6-llama-30b-xor\"}",
18-
"method": "POST"
20+
"body": null,
21+
"method": "GET"
1922
})
20-
.then(data => data.json())
21-
.then(data => {
22-
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}/__data.json?x-sveltekit-invalidated=1_1`, {
23+
.then(() => {
24+
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}`, {
2325
"headers": {
26+
"content-type": "application/json",
2427
"cookie": cookie
2528
},
26-
"body": null,
27-
"method": "GET"
28-
})
29-
.then(() => {
30-
fetch(`https://huggingface.co/chat/conversation/${data.conversationId}`, {
31-
"headers": {
32-
"content-type": "application/json",
33-
"cookie": cookie
34-
},
35-
"body": JSON.stringify({
36-
"inputs": msg,
37-
"parameters": {
38-
"temperature": 0.2,
39-
"truncate": 1000,
40-
"max_new_tokens": 1024,
41-
"stop": [
42-
"</s>"
43-
],
44-
"top_p": 0.95,
45-
"repetition_penalty": 1.2,
46-
"top_k": 50,
47-
"return_full_text": false
48-
},
49-
"stream": true,
50-
"options": {
51-
"id": randomUUID(),
52-
"response_id": randomUUID(),
53-
"is_retry": false,
54-
"use_cache": false,
55-
"web_search_id": ""
56-
}
57-
}),
58-
"method": "POST"
59-
}).then(dataa => dataa.text())
60-
.then(dataa => {
61-
dataa = JSON.parse(dataa.slice(dataa.lastIndexOf('data:{"token":{') + 'data:'.length)).generated_text
62-
resolve(dataa)
63-
})
29+
"body": JSON.stringify({
30+
"inputs": msg,
31+
"parameters": {
32+
"temperature": 0.2,
33+
"truncate": 1000,
34+
"max_new_tokens": 1024,
35+
"stop": [
36+
"</s>"
37+
],
38+
"top_p": 0.95,
39+
"repetition_penalty": 1.2,
40+
"top_k": 50,
41+
"return_full_text": false
42+
},
43+
"stream": true,
44+
"options": {
45+
"id": randomUUID(),
46+
"response_id": randomUUID(),
47+
"is_retry": false,
48+
"use_cache": false,
49+
"web_search_id": ""
50+
}
51+
}),
52+
"method": "POST"
53+
}).then(dataa => dataa.text())
54+
.then(dataa => {
55+
dataa = JSON.parse(dataa.slice(dataa.lastIndexOf('data:{"token":{') + 'data:'.length)).generated_text
56+
resolve(dataa)
6457
})
65-
66-
6758
})
59+
60+
})
61+
}
62+
function newConversationId() {
63+
return new Promise((resolve) => {
64+
fetch("https://huggingface.co/chat/conversation", {
65+
"headers": {
66+
"content-type": "application/json",
67+
"cookie": cookie
68+
},
69+
"body": "{\"model\":\"OpenAssistant/oasst-sft-6-llama-30b-xor\"}",
70+
"method": "POST"
71+
}).then(data => data.json())
72+
.then(data => resolve(data))
6873
})
6974
}
7075

0 commit comments

Comments
 (0)