Skip to content

Commit 784b22a

Browse files
committed
fix(search): removed full text param from built-in search, anthropic provider streaming fix
1 parent 37443a7 commit 784b22a

File tree

3 files changed

+87
-31
lines changed

3 files changed

+87
-31
lines changed

apps/sim/app/api/tools/search/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function POST(request: NextRequest) {
5656
query: validated.query,
5757
type: 'auto',
5858
useAutoprompt: true,
59-
text: true,
59+
highlights: true,
6060
apiKey: env.EXA_API_KEY,
6161
})
6262

@@ -77,7 +77,7 @@ export async function POST(request: NextRequest) {
7777
const results = (result.output.results || []).map((r: any, index: number) => ({
7878
title: r.title || '',
7979
link: r.url || '',
80-
snippet: r.text || '',
80+
snippet: Array.isArray(r.highlights) ? r.highlights.join(' ... ') : '',
8181
date: r.publishedDate || undefined,
8282
position: index + 1,
8383
}))

apps/sim/providers/anthropic/index.ts

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -561,37 +561,93 @@ export const anthropicProvider: ProviderConfig = {
561561
throw error
562562
}
563563

564-
const providerEndTime = Date.now()
565-
const providerEndTimeISO = new Date(providerEndTime).toISOString()
566-
const totalDuration = providerEndTime - providerStartTime
564+
const accumulatedCost = calculateCost(request.model, tokens.prompt, tokens.completion)
567565

568-
return {
569-
content,
570-
model: request.model || 'claude-3-7-sonnet-20250219',
571-
tokens,
572-
toolCalls:
573-
toolCalls.length > 0
574-
? toolCalls.map((tc) => ({
575-
name: tc.name,
576-
arguments: tc.arguments as Record<string, any>,
577-
startTime: tc.startTime,
578-
endTime: tc.endTime,
579-
duration: tc.duration,
580-
result: tc.result,
581-
}))
582-
: undefined,
583-
toolResults: toolResults.length > 0 ? toolResults : undefined,
584-
timing: {
585-
startTime: providerStartTimeISO,
586-
endTime: providerEndTimeISO,
587-
duration: totalDuration,
588-
modelTime: modelTime,
589-
toolsTime: toolsTime,
590-
firstResponseTime: firstResponseTime,
591-
iterations: iterationCount + 1,
592-
timeSegments: timeSegments,
566+
const streamingPayload = {
567+
...payload,
568+
messages: currentMessages,
569+
stream: true,
570+
tool_choice: undefined,
571+
}
572+
573+
const streamResponse: any = await anthropic.messages.create(streamingPayload)
574+
575+
const streamingResult = {
576+
stream: createReadableStreamFromAnthropicStream(
577+
streamResponse,
578+
(streamContent, usage) => {
579+
streamingResult.execution.output.content = streamContent
580+
streamingResult.execution.output.tokens = {
581+
prompt: tokens.prompt + usage.input_tokens,
582+
completion: tokens.completion + usage.output_tokens,
583+
total: tokens.total + usage.input_tokens + usage.output_tokens,
584+
}
585+
586+
const streamCost = calculateCost(
587+
request.model,
588+
usage.input_tokens,
589+
usage.output_tokens
590+
)
591+
streamingResult.execution.output.cost = {
592+
input: accumulatedCost.input + streamCost.input,
593+
output: accumulatedCost.output + streamCost.output,
594+
total: accumulatedCost.total + streamCost.total,
595+
}
596+
597+
const streamEndTime = Date.now()
598+
const streamEndTimeISO = new Date(streamEndTime).toISOString()
599+
600+
if (streamingResult.execution.output.providerTiming) {
601+
streamingResult.execution.output.providerTiming.endTime = streamEndTimeISO
602+
streamingResult.execution.output.providerTiming.duration =
603+
streamEndTime - providerStartTime
604+
}
605+
}
606+
),
607+
execution: {
608+
success: true,
609+
output: {
610+
content: '',
611+
model: request.model || 'claude-3-7-sonnet-20250219',
612+
tokens: {
613+
prompt: tokens.prompt,
614+
completion: tokens.completion,
615+
total: tokens.total,
616+
},
617+
toolCalls:
618+
toolCalls.length > 0
619+
? {
620+
list: toolCalls,
621+
count: toolCalls.length,
622+
}
623+
: undefined,
624+
providerTiming: {
625+
startTime: providerStartTimeISO,
626+
endTime: new Date().toISOString(),
627+
duration: Date.now() - providerStartTime,
628+
modelTime: modelTime,
629+
toolsTime: toolsTime,
630+
firstResponseTime: firstResponseTime,
631+
iterations: iterationCount + 1,
632+
timeSegments: timeSegments,
633+
},
634+
cost: {
635+
input: accumulatedCost.input,
636+
output: accumulatedCost.output,
637+
total: accumulatedCost.total,
638+
},
639+
},
640+
logs: [],
641+
metadata: {
642+
startTime: providerStartTimeISO,
643+
endTime: new Date().toISOString(),
644+
duration: Date.now() - providerStartTime,
645+
},
646+
isStreaming: true,
593647
},
594648
}
649+
650+
return streamingResult as StreamingExecution
595651
} catch (error) {
596652
const providerEndTime = Date.now()
597653
const providerEndTimeISO = new Date(providerEndTime).toISOString()

apps/sim/providers/groq/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export const groqProvider: ProviderConfig = {
393393
const streamingPayload = {
394394
...payload,
395395
messages: currentMessages,
396-
tool_choice: 'auto',
396+
tool_choice: originalToolChoice || 'auto',
397397
stream: true,
398398
}
399399

0 commit comments

Comments
 (0)