Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RequestInfoFromTableWithAIUseCaseV3
let heartbeatInterval: NodeJS.Timeout | null = null;

try {
response.write(`Analyzing your request about the "${tableName}" table...`);
// response.write(`Analyzing your request about the "${tableName}" table...`);
// heartbeatInterval = this.setupHeartbeat(response);

const system_prompt = this.createSystemPrompt(tableName, databaseType, foundConnection);
Expand Down Expand Up @@ -252,7 +252,7 @@ Remember that all responses should be clear and user-friendly, explaining techni
if (completedToolCall) {
try {
const toolName = completedToolCall.function.name;
response.write(`${this.getUserMessageForTool(toolName)}`);
// response.write(`${this.getUserMessageForTool(toolName)}`);

if (toolName === 'getTableStructure') {
await this.handleTableStructureTool(
Expand Down Expand Up @@ -297,7 +297,7 @@ Remember that all responses should be clear and user-friendly, explaining techni
) {
const tableStructureInfo = await this.getTableStructureInfo(dao, tableName, userEmail, foundConnection);

response.write(`Fetching table structure information for ${tableName}...`);
// response.write(`Fetching table structure information for ${tableName}...`);

const updatedSystemPrompt = this.createTableStructurePrompt(tableName, foundConnection, isMongoDb);

Expand Down Expand Up @@ -383,7 +383,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
let innerAiResponseBuffer = '';
const innerResponseIdRef = { id: null };

response.write(`Analyzing your data structure and preparing an appropriate query...`);
// response.write(`Analyzing your data structure and preparing an appropriate query...`);

for await (const innerChunk of continuedStream) {
const typedInnerChunk = innerChunk as any;
Expand All @@ -404,8 +404,8 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
if (typedInnerChunk.type === 'response.output_item.done' && typedInnerChunk.item?.type === 'function_call') {
const completedInnerToolCall = innerToolCalls.find((tc) => tc.id === typedInnerChunk.item.id);
if (completedInnerToolCall) {
const toolName = completedInnerToolCall.function.name;
response.write(`${this.getUserMessageForTool(toolName, true)}`);
// const toolName = completedInnerToolCall.function.name;
// response.write(`${this.getUserMessageForTool(toolName, true)}`);

await this.processQueryToolCall(
completedInnerToolCall,
Expand Down Expand Up @@ -662,7 +662,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
const sanitizedArgs = this.sanitizeJsonString(toolCall.function.arguments);
const toolArgs = JSON.parse(sanitizedArgs);

response.write(`${this.getUserMessageForTool(toolName)}`);
// response.write(`${this.getUserMessageForTool(toolName)}`);

if (toolName === 'executeRawSql') {
const query = toolArgs.query;
Expand All @@ -683,7 +683,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the

try {
const queryResult = await dao.executeRawQuery(finalQuery, tableName, userEmail);
response.write(`Query executed successfully.`);
// response.write(`Query executed successfully.`);
if (
await this.streamHumanReadableAnswer(
query,
Expand All @@ -695,9 +695,9 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
response,
)
) {
console.info('Successfully streamed human-readable answer');
// console.info('Successfully streamed human-readable answer');
} else {
console.info('Streaming failed, using non-streaming fallback');
// console.info('Streaming failed, using non-streaming fallback');
const formattedResults = this.formatQueryResults(queryResult);
const interpretation = await this.generateHumanReadableAnswer(
query,
Expand Down Expand Up @@ -732,9 +732,9 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
}

try {
console.info('Executing MongoDB pipeline:', pipeline);
// console.info('Executing MongoDB pipeline:', pipeline);
const pipelineResult = await dao.executeRawQuery(pipeline, tableName, userEmail);
response.write(`Pipeline executed successfully.`);
// response.write(`Pipeline executed successfully.`);
if (
await this.streamHumanReadableAnswer(
pipeline,
Expand All @@ -746,9 +746,9 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
response,
)
) {
console.info('Successfully streamed MongoDB pipeline interpretation');
// console.info('Successfully streamed MongoDB pipeline interpretation');
} else {
console.info('Streaming failed for MongoDB, using non-streaming fallback');
// console.info('Streaming failed for MongoDB, using non-streaming fallback');
const formattedResults = this.formatQueryResults(pipelineResult);
const interpretation = await this.generateHumanReadableAnswer(
pipeline,
Expand All @@ -770,7 +770,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
response.write(`Sorry, I couldn't complete the data analysis you requested: ${error.message}`);
}
} else if (toolName === 'getTableStructure') {
response.write(`Table structure information has been fetched.`);
// response.write(`Table structure information has been fetched.`);
} else {
console.info(`Unknown tool call: ${toolName}`);
response.write(`Received unknown tool call: ${toolName}`);
Expand Down Expand Up @@ -820,7 +820,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the

if (!query || query.length < 10) return false;

response.write(`I notice a potential database query in your question. Let me run that for you...`);
// response.write(`I notice a potential database query in your question. Let me run that for you...`);

if (!this.isValidSQLQuery(query)) {
response.write(
Expand All @@ -834,7 +834,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the

try {
const queryResult = await dao.executeRawQuery(finalQuery, tableName, userEmail);
response.write(`Successfully retrieved the data you requested.`);
// response.write(`Successfully retrieved the data you requested.`);

const openApiKey = getRequiredEnvVariable('OPENAI_API_KEY');
const openai = new OpenAI({ apiKey: openApiKey });
Expand Down Expand Up @@ -879,7 +879,7 @@ Remember: You MUST use the executeRawSql tool to run your query and show me the
userId: string,
): Promise<string | null> {
try {
console.log('Generating human-readable answer for query results using responses API');
// console.log('Generating human-readable answer for query results using responses API');

const simplifiedResults = this.simplifyQueryResults(queryResult);

Expand Down Expand Up @@ -1027,7 +1027,7 @@ Please provide a clear, concise, and conversational answer that directly address
): Promise<boolean> {
try {
console.log('Streaming human-readable answer for query results using responses API');
this.writeToResponse(response, 'Creating an explanation of what your data shows...');
// this.writeToResponse(response, 'Creating an explanation of what your data shows...');

const simplifiedResults = this.simplifyQueryResults(queryResult);
const instructions = this.getExplanationInstructions();
Expand Down
Loading