mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
35 lines
739 B
TypeScript
35 lines
739 B
TypeScript
|
import type { IRestApiContext, Schema } from '@/Interface';
|
||
|
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||
|
import type { IDataObject } from 'n8n-workflow';
|
||
|
|
||
|
type Usage = {
|
||
|
prompt_tokens: number;
|
||
|
completion_tokens: number;
|
||
|
total_tokens: number;
|
||
|
};
|
||
|
|
||
|
export async function generateCodeForPrompt(
|
||
|
ctx: IRestApiContext,
|
||
|
{
|
||
|
question,
|
||
|
context,
|
||
|
model,
|
||
|
n8nVersion,
|
||
|
}: {
|
||
|
question: string;
|
||
|
context: {
|
||
|
schema: Array<{ nodeName: string; schema: Schema }>;
|
||
|
inputSchema: { nodeName: string; schema: Schema };
|
||
|
};
|
||
|
model: string;
|
||
|
n8nVersion: string;
|
||
|
},
|
||
|
): Promise<{ code: string; usage: Usage }> {
|
||
|
return makeRestApiRequest(ctx, 'POST', '/ask-ai', {
|
||
|
question,
|
||
|
context,
|
||
|
model,
|
||
|
n8nVersion,
|
||
|
} as IDataObject);
|
||
|
}
|