Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/api/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {

yield { type: "text", text: chunk.content_block.text }
break
default: {
const block = chunk.content_block as {
type: string
text?: string
metadata?: { ui_only?: boolean; content?: string }
}

if (block.type === "ui") {
yield {
type: "text",
text: block.text || "",
metadata: block.metadata,
}
} else {
yield {
type: "text",
text: block.text || "",
}
}
break
}
}
break
case "content_block_delta":
Expand Down
10 changes: 8 additions & 2 deletions src/api/providers/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ export class DeepSeekHandler implements ApiHandler, SingleCompletionHandler {

try {
const chunk = JSON.parse(data)
// Handle regular delta format
const delta = chunk.choices[0]?.delta ?? {}

if (delta.content) {
if (delta.type === "ui") {
yield {
type: "text",
text: delta.metadata?.content || "",
metadata: delta.metadata,
}
} else if (delta.content) {
yield {
type: "text",
text: delta.content,
Expand Down
23 changes: 22 additions & 1 deletion src/api/providers/pearai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,28 @@ export class PearAiHandler {

async *createMessage(systemPrompt: string, messages: any[]): AsyncGenerator<any> {
const generator = this.handler.createMessage(systemPrompt, messages)
yield* generator
let warningMsg = ""

for await (const chunk of generator) {
console.dir(chunk)
if (chunk.type === "text" && chunk.metadata?.ui_only) {
warningMsg += chunk.metadata?.content
continue
}
yield chunk
}

if (warningMsg) {
if (warningMsg.includes("pay-as-you-go")) {
vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => {
if (selection === "View Pay-As-You-Go") {
vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go"))
}
})
} else {
vscode.window.showInformationMessage(warningMsg)
}
}
}

async completePrompt(prompt: string): Promise<string> {
Expand Down
4 changes: 4 additions & 0 deletions src/api/transform/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export type ApiStreamChunk = ApiStreamTextChunk | ApiStreamUsageChunk | ApiStrea
export interface ApiStreamTextChunk {
type: "text"
text: string
metadata?: {
ui_only?: boolean
content?: string
}
}

export interface ApiStreamReasoningChunk {
Expand Down
Loading