Skip to content

Commit c2c2670

Browse files
committed
make groq work properly
1 parent 4213d80 commit c2c2670

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/llmCall.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,20 @@ async function replaceSettingIfNotFound(key, value) {
7474

7575

7676

77+
let throttleTime = 20; // seconds
78+
let lastCallTime = 0;
79+
80+
async function throttle() {
81+
const currentTime = new Date().getTime();
82+
if (currentTime < lastCallTime + throttleTime * 1000) {
83+
const remainingTime = (lastCallTime + throttleTime * 1000) - currentTime;
84+
await new Promise((resolve) => setTimeout(resolve, remainingTime));
85+
}
7786

78-
79-
87+
lastCallTime = new Date().getTime();
88+
console.log("done waiting");
89+
return "It's done waiting";
90+
}
8091

8192
export class conversation {
8293
constructor() {
@@ -158,13 +169,25 @@ export class conversation {
158169
}
159170

160171
async getOpenAIResponse(tempMessageDiv = null) {
172+
if (this.service === "groq") await throttle();
161173
// read the api key from the setting file taking in to account this.service
162174
const apiKey = await readSetting(`llmConfig/${this.service}-api-key.txt`);
163175

164176
// set the base URL from the service
165177
const baseURL = this.llmServices.find(service => service.name === this.service)?.baseURL || null;
166178

167179

180+
// make a messages array that only contains the role and content fields
181+
let cleanedMessages = [];
182+
for (const message of this.messages) {
183+
await cleanedMessages.push({
184+
role: message.role,
185+
content: message.content,
186+
})
187+
}
188+
189+
190+
168191
let openai;
169192
if (baseURL) {
170193
openai = new OpenAI({ apiKey, baseURL, dangerouslyAllowBrowser: true });
@@ -177,10 +200,11 @@ export class conversation {
177200

178201
const resultStream = await openai.chat.completions.create({
179202
model: this.modelName,
180-
messages: this.messages,
203+
messages: cleanedMessages,
181204
stream: true
182205
});
183206

207+
184208
for await (const chunk of resultStream) {
185209
const content = chunk.choices[0]?.delta?.content || '';
186210
await console.log(content); // Real-time printing to console

src/mergeTools/html/html.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ export class htmlManipulator {
302302
}
303303

304304
const cleanHtmlExample = `
305+
<!DOCTYPE html>
306+
<html lang="en">
305307
<html>
306308
<head></head>
307309
<body>__BODY_CONTENT__</body>

src/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ code {
403403
padding: 5px;
404404
white-space: pre;
405405
overflow: auto;
406+
overflow-y:scroll;
406407
}
407408

408409

0 commit comments

Comments
 (0)