fix: transition from removed apiClient to @mariozechner/pi-ai

This commit is contained in:
wassname
2026-04-23 15:20:19 +08:00
parent b9ec541e4f
commit 9c400d0e0a
2 changed files with 20 additions and 10 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ export default function (pi: ExtensionAPI) {
})
pi.on("context", async (event, ctx) => {
const prunedMessages = await applyPruning(event.messages, state, config, (ctx as any).apiClient)
const prunedMessages = await applyPruning(event.messages, state, config, ctx.model)
return { messages: prunedMessages }
})
+19 -9
View File
@@ -132,7 +132,7 @@ async function generateSummary(
turns: any[],
previousSummary: string | null,
focusTopic: string | null,
apiClient: any,
model: any,
): Promise<string | null> {
const contentToSummarize = serializeForSummary(turns);
@@ -213,13 +213,23 @@ Prioritize preserving all information related to the focus topic.`;
}
try {
const model = (apiClient && apiClient.model) ? apiClient.model : "gemini-2.0-flash";
const response = await apiClient.chat.completions.create({
model: model,
messages: [{ role: "user", content: prompt }],
max_tokens: 4000,
if (!model) return null;
const piAi = await import("@mariozechner/pi-ai");
const response = await piAi.complete(model, {
messages: [{ role: "user", content: prompt, timestamp: Date.now() }]
});
return response.choices[0]?.message?.content?.trim() || null;
let text = "";
if (Array.isArray(response.content)) {
text = response.content
.filter((c: any) => c.type === "text")
.map((c: any) => c.text)
.join("");
} else if (typeof (response as any).content === "string") {
text = (response as any).content;
}
return text.trim() || null;
} catch (e) {
console.error("Summary generation failed:", e);
return null;
@@ -333,7 +343,7 @@ export async function applyPruning(
messages: any[],
state: DcpState,
config: DcpConfig,
apiClient: any
model: any
): Promise<any[]> {
const msgs = messages.map((m: any) => {
const clone = { ...m };
@@ -369,7 +379,7 @@ export async function applyPruning(
if (compressStart < compressEnd) {
const middle = msgs.slice(compressStart, compressEnd);
const summary = await generateSummary(middle, state.previousSummary, null, apiClient);
const summary = await generateSummary(middle, state.previousSummary, null, model);
if (summary) {
const compressed: any[] = [];