Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

refactor: extract headers and body in llm request

Christian Fei9c0bb501fdd7
diff --git a/lib/llm.js b/lib/llm.js
index 4ed3b80..538d3ec 100644
--- a/lib/llm.js
+++ b/lib/llm.js
@@ -14,20 +14,24 @@ export async function fetchCompletionLMSTUDIO (
}
) {
if (prompt.length > 10000) prompt = prompt.substring(0, 10000)
+ const headers = Object.assign({
+ 'Content-Type': 'application/json'
+ }, apiKey ? {'Authorization': `Bearer ${apiKey}`} : {})
+ const body = JSON.stringify({
+ model,
+ messages: [
+ {role: "system", content: system},
+ {role: "user", content: prompt}
+ ]
+ })
+
try {
const response = await fetch(host + endpoint, {
method: 'POST',
- headers: Object.assign({
- 'Content-Type': 'application/json'
- }, apiKey ? {'Authorization': `Bearer ${apiKey}`} : {}),
- body: JSON.stringify({
- model,
- messages: [
- {role: "system", content: system},
- {role: "user", content: prompt}
- ]
- })
+ headers,
+ body
})
+
const data = await response.json()
if (!response.ok) {
console.error(data)