A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
refactor: generic llm provider with getHeaders and getBody
Christian Fei367192fb48c3
diff --git a/lib/llm/providers/generic.js b/lib/llm/providers/generic.jsindex f17910c..bf25c88 100644--- a/lib/llm/providers/generic.js+++ b/lib/llm/providers/generic.js@@ -10,37 +10,40 @@ export class Generic {max_tokens,}) {this.system = system- this.headers = Object.assign({- 'Content-Type': 'application/json',- }, apiKey ? { 'Authorization': `Bearer ${apiKey}` } : {})-- this.settings = {- model,- host,- endpoint,- apiKey,- temperature,- max_tokens- }+ this.model = model+ this.host = host+ this.endpoint = endpoint+ this.apiKey = apiKey+ this.temperature = temperature+ this.max_tokens = max_tokens}- async summarize(prompt) {- if (prompt.length > MAX_PROMPT_LEN) prompt = prompt.substring(0, MAX_PROMPT_LEN)+ getHeaders () {+ console.log('this headers called - generic')+ return Object.assign({+ 'Content-Type': 'application/json',+ }, this.apiKey ? { 'Authorization': `Bearer ${this.apiKey}` } : {})+ }- const body = JSON.stringify({- model: this.settings.model,- temperature: Number(this.settings.temperature),+ getBody (prompt) {+ return JSON.stringify({+ model: this.model,+ temperature: Number(this.temperature),messages: [{ role: "system", content: this.system },{ role: "user", content: prompt }]})+ }++ async summarize(prompt) {+ if (prompt.length > MAX_PROMPT_LEN) prompt = prompt.substring(0, MAX_PROMPT_LEN)try {- const response = await fetch(this.settings.host + this.settings.endpoint, {+ const response = await fetch(this.host + this.endpoint, {method: 'POST',- headers: this.headers,- body+ headers: this.getHeaders(),+ body: this.getBody(prompt)})const data = await response.json()