🐛 handle gemini errors
This commit is contained in:
parent
00137fd7a1
commit
27ce6efd06
2 changed files with 30 additions and 23 deletions
|
|
@ -48,7 +48,7 @@ class GooglePalm extends BaseLLM {
|
|||
const body = {
|
||||
contents: messages.map((msg) => {
|
||||
return {
|
||||
role: msg.role === "assistant" ? "ASSISTANT" : "USER",
|
||||
role: msg.role === "assistant" ? "model" : "user",
|
||||
parts: [{ text: msg.content }],
|
||||
};
|
||||
}),
|
||||
|
|
@ -60,6 +60,8 @@ class GooglePalm extends BaseLLM {
|
|||
const data = await response.json();
|
||||
if (data.error) {
|
||||
throw new Error(data.error.message);
|
||||
} else if (data.candidates[0].finishReason === "OTHER") {
|
||||
throw new Error("Google PaLM API returned empty response");
|
||||
}
|
||||
yield {
|
||||
role: "assistant",
|
||||
|
|
|
|||
|
|
@ -394,29 +394,34 @@ export function getSidebarContent(
|
|||
break;
|
||||
}
|
||||
case "googlePalmCompletion": {
|
||||
const sConfig = await ide.getSerializedConfig();
|
||||
const modelDesc = sConfig.models.find(
|
||||
(m) =>
|
||||
m.provider === "google-palm" && m.title === data.message.modelTitle
|
||||
);
|
||||
if (!modelDesc) {
|
||||
return "";
|
||||
try {
|
||||
const sConfig = await ide.getSerializedConfig();
|
||||
const modelDesc = sConfig.models.find(
|
||||
(m) =>
|
||||
m.provider === "google-palm" &&
|
||||
m.title === data.message.modelTitle
|
||||
);
|
||||
if (!modelDesc) {
|
||||
return "";
|
||||
}
|
||||
const model = llmFromDescription({
|
||||
...modelDesc,
|
||||
provider: "google-palm-real",
|
||||
});
|
||||
if (!model) {
|
||||
return "";
|
||||
}
|
||||
let completion = "";
|
||||
for await (const update of model.streamChat(
|
||||
data.message.messages,
|
||||
data.message.options
|
||||
)) {
|
||||
completion += update.content;
|
||||
}
|
||||
respond(completion);
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(`Google PaLM failed with error: ${e}`);
|
||||
}
|
||||
const model = llmFromDescription({
|
||||
...modelDesc,
|
||||
provider: "google-palm-real",
|
||||
});
|
||||
if (!model) {
|
||||
return "";
|
||||
}
|
||||
let completion = "";
|
||||
for await (const update of model.streamChat(
|
||||
data.message.messages,
|
||||
data.message.options
|
||||
)) {
|
||||
completion += update.content;
|
||||
}
|
||||
respond(completion);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue