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
4 changes: 3 additions & 1 deletion redisinsight/api/config/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
join(os.homedir(), '.redisinsight-preview'),
join(os.homedir(), '.redisinsight-v2'),
process.env.RI_GUIDES_PATH || join(homedir, 'guides'),
]
],
},
server: {
env: 'production',
Expand All @@ -40,5 +40,7 @@ export default {
},
ai: {
convAiApiUrl: process.env.RI_AI_CONVAI_API_URL || 'https://redis.io/convai/api',
querySocketUrl: process.env.RI_AI_QUERY_SOCKET_URL || 'https://app.redislabs.com',
querySocketPath: process.env.RI_AI_QUERY_SOCKET_PATH || '/api/v1/cloud-copilot-service/socket.io/',
},
};
23 changes: 21 additions & 2 deletions redisinsight/api/src/modules/ai/query/ai-query.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isArray } from 'lodash';
import { Socket } from 'socket.io-client';
import { Injectable, Logger } from '@nestjs/common';
import { ClientContext, SessionMetadata } from 'src/common/models';
import { AiQueryProvider } from 'src/modules/ai/query/providers/ai-query.provider';
import { SendAiQueryMessageDto } from 'src/modules/ai/query/dto/send.ai-query.message.dto';
import { wrapAiQueryError } from 'src/modules/ai/query/exceptions';
import { DatabaseClientFactory } from 'src/modules/database/providers/database.client.factory';
import { getFullDbContext, getIndexContext } from 'src/modules/ai/query/utils/context.util';
import { getFullDbContext, getIndexContext, quotesIfNeeded } from 'src/modules/ai/query/utils/context.util';
import { Response } from 'express';
import {
AiQueryMessage,
Expand Down Expand Up @@ -56,6 +57,24 @@ export class AiQueryService {
return steps;
}

static prepareToolReply(toolReply: any) {
try {
const prepared = JSON.parse(toolReply);

if (prepared?.name === 'query' && prepared.content) {
const query = JSON.parse(prepared.content);
if (isArray(query)) {
prepared.content.query = JSON.stringify(query.map(quotesIfNeeded));
}
return JSON.stringify(prepared);
}
} catch (e) {
// ignore error
}

return toolReply;
}

static prepareHistory(messages: AiQueryMessage[]): string[][] {
const history = [];
messages.forEach((message) => {
Expand Down Expand Up @@ -178,7 +197,7 @@ export class AiQueryService {
socket.on(AiQueryWsEvents.TOOL_REPLY, async (data) => {
answer.steps.push(plainToClass(AiQueryIntermediateStep, {
type: AiQueryIntermediateStepType.TOOL,
data,
data: AiQueryService.prepareToolReply(data),
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type RedisClient = { sendCommand: (args: any, options: any) => Promise<any> };
const DOCUMENT_SAMPLES_PER_PREFIX = 5;
const HSCAN_COUNT = 500;

const quotesIfNeeded = (str: string) => (str.indexOf(' ') > -1 ? JSON.stringify(str) : str);
export const quotesIfNeeded = (str: string) => (str.indexOf(' ') > -1 ? JSON.stringify(str) : str);

// ====================================================================
// Reply converter
Expand Down