Skip to content

Commit b8835c4

Browse files
build dist
1 parent df624d5 commit b8835c4

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

dist/index.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class LLMClient {
970970
this.baseUrl =
971971
options.baseUrl ||
972972
(this.provider === "groq"
973-
? "https://api.groq.com/openai/v1/models"
973+
? "https://api.groq.com/openai/v1"
974974
: "https://generativelanguage.googleapis.com/v1beta/models");
975975
}
976976
/**
@@ -1243,14 +1243,28 @@ RESPOND ONLY WITH THE JSON OBJECT. NO OTHER TEXT.`;
12431243
* Call Groq API with retry logic
12441244
*/
12451245
async callGroqAPI(model, prompt, _responseSchema, attempt = 1) {
1246-
const url = `${this.baseUrl}/${model}/generate`;
1247-
const body = {
1248-
input: prompt,
1249-
temperature: 0.7,
1250-
top_p: 0.95,
1251-
max_output_tokens: 2048,
1252-
top_k: 40,
1253-
};
1246+
const trimmedBase = this.baseUrl.replace(/\/$/, "");
1247+
const useOpenAICompat = trimmedBase.includes("/openai/v1");
1248+
const openAIBase = trimmedBase.replace(/\/models$/, "");
1249+
const url = useOpenAICompat
1250+
? `${openAIBase}/completions`
1251+
: `${trimmedBase}/${model}/generate`;
1252+
const body = useOpenAICompat
1253+
? {
1254+
model,
1255+
prompt,
1256+
temperature: 0.7,
1257+
top_p: 0.95,
1258+
max_tokens: 2048,
1259+
top_k: 40,
1260+
}
1261+
: {
1262+
input: prompt,
1263+
temperature: 0.7,
1264+
top_p: 0.95,
1265+
max_output_tokens: 2048,
1266+
top_k: 40,
1267+
};
12541268
try {
12551269
const response = await (0, node_fetch_1.default)(url, {
12561270
method: "POST",
@@ -1348,10 +1362,16 @@ RESPOND ONLY WITH THE JSON OBJECT. NO OTHER TEXT.`;
13481362
extractResponseText(response) {
13491363
if (this.provider === "groq") {
13501364
const groqResponse = response;
1351-
const text = groqResponse.output
1365+
const openAIText = groqResponse.choices
1366+
?.map((choice) => choice.text || choice.message?.content || "")
1367+
.join("");
1368+
if (openAIText) {
1369+
return openAIText.trim();
1370+
}
1371+
const groqText = groqResponse.output
13521372
?.map((out) => out.content?.map((item) => item.text || "").join(""))
13531373
.join("") || "";
1354-
return text.trim();
1374+
return groqText.trim();
13551375
}
13561376
const geminiResponse = response;
13571377
const text = geminiResponse.candidates?.[0]?.content?.parts
@@ -1425,7 +1445,10 @@ RESPOND ONLY WITH THE JSON OBJECT. NO OTHER TEXT.`;
14251445
}
14261446
if (this.provider === "groq") {
14271447
const availableModels = new Set();
1428-
const url = new URL(this.baseUrl);
1448+
const trimmedBase = this.baseUrl.replace(/\/$/, "");
1449+
const url = trimmedBase.endsWith("/models")
1450+
? new URL(trimmedBase)
1451+
: new URL(`${trimmedBase}/models`);
14291452
try {
14301453
const response = await (0, node_fetch_1.default)(url.toString(), {
14311454
method: "GET",

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)