mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Shovel around more of AI code (no-changelog) (#12218)
This commit is contained in:
committed by
GitHub
parent
a8e7a05856
commit
2ce1644d01
@@ -9,6 +9,8 @@ import type {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions';
|
||||
|
||||
import { conversationalAgentProperties } from './agents/ConversationalAgent/description';
|
||||
import { conversationalAgentExecute } from './agents/ConversationalAgent/execute';
|
||||
import { openAiFunctionsAgentProperties } from './agents/OpenAiFunctionsAgent/description';
|
||||
@@ -21,7 +23,6 @@ import { sqlAgentAgentProperties } from './agents/SqlAgent/description';
|
||||
import { sqlAgentAgentExecute } from './agents/SqlAgent/execute';
|
||||
import { toolsAgentProperties } from './agents/ToolsAgent/description';
|
||||
import { toolsAgentExecute } from './agents/ToolsAgent/execute';
|
||||
import { promptTypeOptions, textFromPreviousNode, textInput } from '../../../utils/descriptions';
|
||||
|
||||
// Function used in the inputs expression to figure out which inputs to
|
||||
// display based on the agent type
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { SYSTEM_MESSAGE, HUMAN_MESSAGE } from './prompt';
|
||||
|
||||
export const conversationalAgentProperties: INodeProperties[] = [
|
||||
|
||||
@@ -6,14 +6,11 @@ import { CombiningOutputParser } from 'langchain/output_parsers';
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
isChatInstance,
|
||||
getPromptInputByType,
|
||||
getConnectedTools,
|
||||
} from '../../../../../utils/helpers';
|
||||
import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '../../../../../utils/schemaParsing';
|
||||
import { getTracingConfig } from '../../../../../utils/tracing';
|
||||
import { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers';
|
||||
import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '@utils/schemaParsing';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { checkForStructuredTools, extractParsedOutput } from '../utils';
|
||||
|
||||
export async function conversationalAgentExecute(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { SYSTEM_MESSAGE } from './prompt';
|
||||
|
||||
export const openAiFunctionsAgentProperties: INodeProperties[] = [
|
||||
|
||||
@@ -12,9 +12,10 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getConnectedTools, getPromptInputByType } from '../../../../../utils/helpers';
|
||||
import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser';
|
||||
import { getTracingConfig } from '../../../../../utils/tracing';
|
||||
import { getConnectedTools, getPromptInputByType } from '@utils/helpers';
|
||||
import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { extractParsedOutput } from '../utils';
|
||||
|
||||
export async function openAiFunctionsAgentExecute(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE } from './prompt';
|
||||
|
||||
export const planAndExecuteAgentProperties: INodeProperties[] = [
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getConnectedTools, getPromptInputByType } from '../../../../../utils/helpers';
|
||||
import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '../../../../../utils/schemaParsing';
|
||||
import { getTracingConfig } from '../../../../../utils/tracing';
|
||||
import { getConnectedTools, getPromptInputByType } from '@utils/helpers';
|
||||
import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '@utils/schemaParsing';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { checkForStructuredTools, extractParsedOutput } from '../utils';
|
||||
|
||||
export async function planAndExecuteAgentExecute(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { HUMAN_MESSAGE_TEMPLATE, PREFIX, SUFFIX, SUFFIX_CHAT } from './prompt';
|
||||
|
||||
export const reActAgentAgentProperties: INodeProperties[] = [
|
||||
|
||||
@@ -11,14 +11,11 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getConnectedTools,
|
||||
getPromptInputByType,
|
||||
isChatInstance,
|
||||
} from '../../../../../utils/helpers';
|
||||
import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '../../../../../utils/schemaParsing';
|
||||
import { getTracingConfig } from '../../../../../utils/tracing';
|
||||
import { getConnectedTools, getPromptInputByType, isChatInstance } from '@utils/helpers';
|
||||
import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { throwIfToolSchema } from '@utils/schemaParsing';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { checkForStructuredTools, extractParsedOutput } from '../utils';
|
||||
|
||||
export async function reActAgentAgentExecute(
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions';
|
||||
|
||||
import { SQL_PREFIX, SQL_SUFFIX } from './other/prompts';
|
||||
import {
|
||||
promptTypeOptions,
|
||||
textFromPreviousNode,
|
||||
textInput,
|
||||
} from '../../../../../utils/descriptions';
|
||||
|
||||
const dataSourceOptions: INodeProperties = {
|
||||
displayName: 'Data Source',
|
||||
|
||||
@@ -12,12 +12,13 @@ import {
|
||||
type IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getPromptInputByType, serializeChatHistory } from '@utils/helpers';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { getMysqlDataSource } from './other/handlers/mysql';
|
||||
import { getPostgresDataSource } from './other/handlers/postgres';
|
||||
import { getSqliteDataSource } from './other/handlers/sqlite';
|
||||
import { SQL_PREFIX, SQL_SUFFIX } from './other/prompts';
|
||||
import { getPromptInputByType, serializeChatHistory } from '../../../../../utils/helpers';
|
||||
import { getTracingConfig } from '../../../../../utils/tracing';
|
||||
|
||||
const parseTablesString = (tablesString: string) =>
|
||||
tablesString
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type IExecuteFunctions } from 'n8n-workflow';
|
||||
import { DataSource } from '@n8n/typeorm';
|
||||
import { type IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
export async function getMysqlDataSource(this: IExecuteFunctions): Promise<DataSource> {
|
||||
const credentials = await this.getCredentials('mySql');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type IExecuteFunctions } from 'n8n-workflow';
|
||||
import { DataSource } from '@n8n/typeorm';
|
||||
import { type IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
export async function getPostgresDataSource(this: IExecuteFunctions): Promise<DataSource> {
|
||||
const credentials = await this.getCredentials('postgres');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DataSource } from '@n8n/typeorm';
|
||||
import * as fs from 'fs';
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';
|
||||
import * as temp from 'temp';
|
||||
import * as sqlite3 from 'sqlite3';
|
||||
import { DataSource } from '@n8n/typeorm';
|
||||
import * as temp from 'temp';
|
||||
|
||||
export async function getSqliteDataSource(
|
||||
this: IExecuteFunctions,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { SYSTEM_MESSAGE } from './prompt';
|
||||
|
||||
export const toolsAgentProperties: INodeProperties[] = [
|
||||
|
||||
@@ -14,16 +14,13 @@ import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import type { ZodObject } from 'zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { SYSTEM_MESSAGE } from './prompt';
|
||||
import {
|
||||
isChatInstance,
|
||||
getPromptInputByType,
|
||||
getConnectedTools,
|
||||
} from '../../../../../utils/helpers';
|
||||
import { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers';
|
||||
import {
|
||||
getOptionalOutputParsers,
|
||||
type N8nOutputParser,
|
||||
} from '../../../../../utils/output_parsers/N8nOutputParser';
|
||||
} from '@utils/output_parsers/N8nOutputParser';
|
||||
|
||||
import { SYSTEM_MESSAGE } from './prompt';
|
||||
|
||||
function getOutputParserSchema(outputParser: N8nOutputParser): ZodObject<any, any, any, any> {
|
||||
const schema =
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { z } from 'zod';
|
||||
import type { BaseOutputParser } from '@langchain/core/output_parsers';
|
||||
import type { DynamicStructuredTool, Tool } from 'langchain/tools';
|
||||
import { NodeOperationError, type IExecuteFunctions, type INode } from 'n8n-workflow';
|
||||
import type { z } from 'zod';
|
||||
|
||||
type ZodObjectAny = z.ZodObject<any, any, any, any>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user