mirror of https://github.com/buster-so/buster.git
Merge pull request #1068 from buster-so/wells-bus-1881-running-into-prompt-issues-prompt-too-long
Wells bus 1881 running into prompt issues prompt too long
This commit is contained in:
commit
9eae2f6507
|
@ -2,8 +2,8 @@ import type { ModelMessage } from 'ai';
|
|||
import { generateObject } from 'ai';
|
||||
import { wrapTraced } from 'braintrust';
|
||||
import { z } from 'zod';
|
||||
import { Haiku35 } from '../../../llm/haiku-3-5';
|
||||
import { DEFAULT_ANTHROPIC_OPTIONS } from '../../../llm/providers/gateway';
|
||||
import { GPT5Mini } from '../../../llm';
|
||||
import { DEFAULT_OPENAI_OPTIONS } from '../../../llm/providers/gateway';
|
||||
|
||||
// Schema for what the LLM returns
|
||||
const llmOutputSchema = z.object({
|
||||
|
@ -91,11 +91,11 @@ export async function extractValuesWithLLM(
|
|||
const tracedValuesExtraction = wrapTraced(
|
||||
async () => {
|
||||
const { object } = await generateObject({
|
||||
model: Haiku35,
|
||||
model: GPT5Mini,
|
||||
schema: llmOutputSchema,
|
||||
messages,
|
||||
temperature: 0,
|
||||
providerOptions: DEFAULT_ANTHROPIC_OPTIONS,
|
||||
providerOptions: DEFAULT_OPENAI_OPTIONS,
|
||||
});
|
||||
|
||||
return object;
|
||||
|
|
|
@ -3,8 +3,8 @@ import { generateObject } from 'ai';
|
|||
import type { ModelMessage } from 'ai';
|
||||
import { wrapTraced } from 'braintrust';
|
||||
import { z } from 'zod';
|
||||
import { Haiku35 } from '../../../llm';
|
||||
import { DEFAULT_ANTHROPIC_OPTIONS } from '../../../llm/providers/gateway';
|
||||
import { GPT5Nano } from '../../../llm';
|
||||
import { DEFAULT_OPENAI_OPTIONS } from '../../../llm/providers/gateway';
|
||||
|
||||
// Zod-first: define input/output schemas and export inferred types
|
||||
export const generateChatTitleParamsSchema = z.object({
|
||||
|
@ -56,14 +56,10 @@ async function generateTitleWithLLM(messages: ModelMessage[]): Promise<string> {
|
|||
const tracedChatTitle = wrapTraced(
|
||||
async () => {
|
||||
const { object } = await generateObject({
|
||||
model: Haiku35,
|
||||
headers: {
|
||||
'anthropic-beta': 'fine-grained-tool-streaming-2025-05-14',
|
||||
anthropic_beta: 'fine-grained-tool-streaming-2025-05-14',
|
||||
},
|
||||
model: GPT5Nano,
|
||||
schema: llmOutputSchema,
|
||||
messages: titleMessages,
|
||||
providerOptions: DEFAULT_ANTHROPIC_OPTIONS,
|
||||
providerOptions: DEFAULT_OPENAI_OPTIONS,
|
||||
});
|
||||
|
||||
return object;
|
||||
|
|
|
@ -28,3 +28,5 @@ export {
|
|||
// Step retry utilities
|
||||
export { withStepRetry, createRetryableStep, runStepsWithRetry } from './with-step-retry';
|
||||
export type { StepRetryOptions } from './with-step-retry';
|
||||
|
||||
export { extractUserAndDoneToolMessages } from './memory/extract-user-and-done-tool-messages';
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import type { ModelMessage } from 'ai';
|
||||
|
||||
export function extractUserAndDoneToolMessages(messages: ModelMessage[]): ModelMessage[] {
|
||||
return messages.filter((m) => {
|
||||
// Include user messages and done tool calls and results
|
||||
if (m.role === 'user' && typeof m.content === 'string') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Include doneTool calls
|
||||
if (m.role === 'assistant' && Array.isArray(m.content)) {
|
||||
return m.content.some(
|
||||
(contentItem) => contentItem.type === 'tool-call' && contentItem.toolName === 'doneTool'
|
||||
);
|
||||
}
|
||||
|
||||
// Include doneTool results
|
||||
if (m.role === 'tool' && Array.isArray(m.content)) {
|
||||
return m.content.some(
|
||||
(contentItem) => contentItem.type === 'tool-result' && contentItem.toolName === 'doneTool'
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
|
@ -25,6 +25,7 @@ import { CREATE_METRICS_TOOL_NAME } from '../../tools/visualization-tools/metric
|
|||
import { MODIFY_METRICS_TOOL_NAME } from '../../tools/visualization-tools/metrics/modify-metrics-tool/modify-metrics-tool';
|
||||
import { CREATE_REPORTS_TOOL_NAME } from '../../tools/visualization-tools/reports/create-reports-tool/create-reports-tool';
|
||||
import { MODIFY_REPORTS_TOOL_NAME } from '../../tools/visualization-tools/reports/modify-reports-tool/modify-reports-tool';
|
||||
import { extractUserAndDoneToolMessages } from '../../utils';
|
||||
import { withStepRetry } from '../../utils/with-step-retry';
|
||||
import type { StepRetryOptions } from '../../utils/with-step-retry';
|
||||
import {
|
||||
|
@ -268,6 +269,7 @@ async function runAnalystPrepSteps({
|
|||
values: ExtractValuesSearchResult;
|
||||
analysisMode: AnalysisTypeRouterResult['analysisMode'];
|
||||
}> {
|
||||
const filteredToUserAndDoneToolMessages = extractUserAndDoneToolMessages(messages);
|
||||
const shouldInjectUserPersonalizationTodo = Boolean(userPersonalizationConfig);
|
||||
const [todos, values, , analysisMode] = await Promise.all([
|
||||
withStepRetry(
|
||||
|
@ -292,7 +294,7 @@ async function runAnalystPrepSteps({
|
|||
withStepRetry(
|
||||
() =>
|
||||
runExtractValuesAndSearchStep({
|
||||
messages,
|
||||
messages: filteredToUserAndDoneToolMessages,
|
||||
dataSourceId,
|
||||
}),
|
||||
{
|
||||
|
@ -310,7 +312,7 @@ async function runAnalystPrepSteps({
|
|||
withStepRetry(
|
||||
() =>
|
||||
runGenerateChatTitleStep({
|
||||
messages,
|
||||
messages: filteredToUserAndDoneToolMessages,
|
||||
chatId,
|
||||
messageId,
|
||||
}),
|
||||
|
@ -329,7 +331,7 @@ async function runAnalystPrepSteps({
|
|||
withStepRetry(
|
||||
() =>
|
||||
runAnalysisTypeRouterStep({
|
||||
messages,
|
||||
messages: filteredToUserAndDoneToolMessages,
|
||||
messageAnalysisMode,
|
||||
}),
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue