fix type bugs
This commit is contained in:
parent
b88f795036
commit
de9e25c7e0
7 changed files with 33 additions and 7 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -42,5 +42,6 @@
|
|||
"extensions/.continue-debug": true
|
||||
// "sync/**": true
|
||||
},
|
||||
"eslint.workingDirectories": ["./core"]
|
||||
"eslint.workingDirectories": ["./core"],
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Asksage extends BaseLLM {
|
|||
? message.content
|
||||
: message.content
|
||||
.filter((part) => part.type === "text")
|
||||
.map((part) => part.text)
|
||||
.map((part) => (part as TextMessagePart).text)
|
||||
.join(""),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
GeminiGenerationConfig,
|
||||
GeminiToolFunctionDeclaration,
|
||||
} from "./gemini-types.js";
|
||||
import { findLast } from "../../util/findLast.js";
|
||||
|
||||
class Gemini extends BaseLLM {
|
||||
static providerName = "gemini";
|
||||
|
|
@ -155,7 +156,8 @@ class Gemini extends BaseLLM {
|
|||
.map((msg) => {
|
||||
if (msg.role === "tool") {
|
||||
let fn_name = "";
|
||||
const lastToolCallMessage = messages.findLast(
|
||||
const lastToolCallMessage = findLast(
|
||||
messages,
|
||||
(msg) => "toolCalls" in msg && msg.toolCalls?.[0]?.function?.name,
|
||||
) as AssistantChatMessage;
|
||||
if (lastToolCallMessage) {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ export function toChatMessage(
|
|||
content:
|
||||
typeof message.content === "string"
|
||||
? message.content || " " // LM Studio (and other providers) don't accept empty content
|
||||
: message.content.filter((part) => part.type === "text"),
|
||||
: message.content
|
||||
.filter((part) => part.type === "text")
|
||||
.map((part) => part as TextMessagePart), // can remove with newer typescript version
|
||||
};
|
||||
|
||||
if (message.toolCalls) {
|
||||
|
|
|
|||
|
|
@ -12,3 +12,14 @@ export function findLastIndex(
|
|||
}
|
||||
return lastIndex;
|
||||
}
|
||||
|
||||
export function findLast<T>(
|
||||
arr: T[],
|
||||
criterion: (item: T) => any,
|
||||
): T | undefined {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
if (criterion(arr[i])) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
ContextItem,
|
||||
MessageContent,
|
||||
MessagePart,
|
||||
TextMessagePart,
|
||||
} from "../index";
|
||||
|
||||
export function stripImages(messageContent: MessageContent): string {
|
||||
|
|
@ -12,7 +13,7 @@ export function stripImages(messageContent: MessageContent): string {
|
|||
|
||||
return messageContent
|
||||
.filter((part) => part.type === "text")
|
||||
.map((part) => part.text)
|
||||
.map((part) => (part as TextMessagePart).text)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
|
||||
import { JSONContent } from "@tiptap/core";
|
||||
import { InputModifiers, MessageContent, SlashCommandDescription } from "core";
|
||||
import {
|
||||
InputModifiers,
|
||||
MessageContent,
|
||||
SlashCommandDescription,
|
||||
TextMessagePart,
|
||||
} from "core";
|
||||
import { constructMessages } from "core/llm/constructMessages";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
import posthog from "posthog-js";
|
||||
|
|
@ -28,7 +33,11 @@ const getSlashCommandForInput = (
|
|||
let lastText =
|
||||
typeof input === "string"
|
||||
? input
|
||||
: input.filter((part) => part.type === "text").slice(-1)[0]?.text || "";
|
||||
: (
|
||||
input.filter((part) => part.type === "text").slice(-1)[0] as
|
||||
| TextMessagePart
|
||||
| undefined
|
||||
)?.text || "";
|
||||
|
||||
if (lastText.startsWith("/")) {
|
||||
slashCommandName = lastText.split(" ")[0].substring(1);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue