mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
refactor: Use Ask AI feature through AI services instead of hooks (#11027)
This commit is contained in:
@@ -1,30 +1,44 @@
|
||||
import type { IRestApiContext, Schema } from '@/Interface';
|
||||
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||||
import type { IRestApiContext } from '@/Interface';
|
||||
import type { AskAiRequest, ChatRequest, ReplaceCodeRequest } from '@/types/assistant.types';
|
||||
import { makeRestApiRequest, streamRequest } from '@/utils/apiUtils';
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
|
||||
export function chatWithAssistant(
|
||||
ctx: IRestApiContext,
|
||||
payload: ChatRequest.RequestPayload,
|
||||
onMessageUpdated: (data: ChatRequest.ResponsePayload) => void,
|
||||
onDone: () => void,
|
||||
onError: (e: Error) => void,
|
||||
): void {
|
||||
void streamRequest<ChatRequest.ResponsePayload>(
|
||||
ctx,
|
||||
'/ai/chat',
|
||||
payload,
|
||||
onMessageUpdated,
|
||||
onDone,
|
||||
onError,
|
||||
);
|
||||
}
|
||||
|
||||
export async function replaceCode(
|
||||
context: IRestApiContext,
|
||||
data: ReplaceCodeRequest.RequestPayload,
|
||||
): Promise<ReplaceCodeRequest.ResponsePayload> {
|
||||
return await makeRestApiRequest<ReplaceCodeRequest.ResponsePayload>(
|
||||
context,
|
||||
'POST',
|
||||
'/ai/chat/apply-suggestion',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function generateCodeForPrompt(
|
||||
ctx: IRestApiContext,
|
||||
{
|
||||
question,
|
||||
context,
|
||||
model,
|
||||
n8nVersion,
|
||||
}: {
|
||||
question: string;
|
||||
context: {
|
||||
schema: Array<{ nodeName: string; schema: Schema }>;
|
||||
inputSchema: { nodeName: string; schema: Schema };
|
||||
pushRef: string;
|
||||
ndvPushRef: string;
|
||||
};
|
||||
model: string;
|
||||
n8nVersion: string;
|
||||
},
|
||||
{ question, context, forNode }: AskAiRequest.RequestPayload,
|
||||
): Promise<{ code: string }> {
|
||||
return await makeRestApiRequest(ctx, 'POST', '/ask-ai', {
|
||||
return await makeRestApiRequest(ctx, 'POST', '/ai/ask-ai', {
|
||||
question,
|
||||
context,
|
||||
model,
|
||||
n8nVersion,
|
||||
forNode,
|
||||
} as IDataObject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user