mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +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
@@ -27,16 +27,17 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getPromptInputByType, isChatInstance } from '../../../utils/helpers';
|
||||
import type { N8nOutputParser } from '../../../utils/output_parsers/N8nOutputParser';
|
||||
import { getOptionalOutputParsers } from '../../../utils/output_parsers/N8nOutputParser';
|
||||
import { getTemplateNoticeField } from '../../../utils/sharedFields';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
import { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';
|
||||
import { getPromptInputByType, isChatInstance } from '@utils/helpers';
|
||||
import type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser';
|
||||
import { getTemplateNoticeField } from '@utils/sharedFields';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import {
|
||||
getCustomErrorMessage as getCustomOpenAiErrorMessage,
|
||||
isOpenAiError,
|
||||
} from '../../vendors/OpenAi/helpers/error-handling';
|
||||
import { promptTypeOptions, textFromPreviousNode } from '../../../utils/descriptions';
|
||||
|
||||
interface MessagesTemplate {
|
||||
type: string;
|
||||
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { promptTypeOptions, textFromPreviousNode } from '../../../utils/descriptions';
|
||||
import { getPromptInputByType, isChatInstance } from '../../../utils/helpers';
|
||||
import { getTemplateNoticeField } from '../../../utils/sharedFields';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
import { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';
|
||||
import { getPromptInputByType, isChatInstance } from '@utils/helpers';
|
||||
import { getTemplateNoticeField } from '@utils/sharedFields';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
const SYSTEM_PROMPT_TEMPLATE = `Use the following pieces of context to answer the users question.
|
||||
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import type { Document } from '@langchain/core/documents';
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import { PromptTemplate } from '@langchain/core/prompts';
|
||||
import type { SummarizationChainParams } from 'langchain/chains';
|
||||
import { loadSummarizationChain } from 'langchain/chains';
|
||||
import {
|
||||
NodeConnectionType,
|
||||
type INodeTypeBaseDescription,
|
||||
@@ -7,14 +12,10 @@ import {
|
||||
type INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import type { SummarizationChainParams } from 'langchain/chains';
|
||||
import { loadSummarizationChain } from 'langchain/chains';
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import type { Document } from '@langchain/core/documents';
|
||||
import { PromptTemplate } from '@langchain/core/prompts';
|
||||
import { N8nJsonLoader } from '../../../../utils/N8nJsonLoader';
|
||||
import { N8nBinaryLoader } from '../../../../utils/N8nBinaryLoader';
|
||||
import { getTemplateNoticeField } from '../../../../utils/sharedFields';
|
||||
import { N8nBinaryLoader } from '@utils/N8nBinaryLoader';
|
||||
import { N8nJsonLoader } from '@utils/N8nJsonLoader';
|
||||
import { getTemplateNoticeField } from '@utils/sharedFields';
|
||||
|
||||
import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';
|
||||
|
||||
export class ChainSummarizationV1 implements INodeType {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
import type { Document } from '@langchain/core/documents';
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import type { TextSplitter } from '@langchain/textsplitters';
|
||||
import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';
|
||||
import { loadSummarizationChain } from 'langchain/chains';
|
||||
import type {
|
||||
INodeTypeBaseDescription,
|
||||
IExecuteFunctions,
|
||||
@@ -7,18 +11,15 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
|
||||
import { N8nBinaryLoader } from '@utils/N8nBinaryLoader';
|
||||
import { N8nJsonLoader } from '@utils/N8nJsonLoader';
|
||||
import { getTemplateNoticeField } from '@utils/sharedFields';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { loadSummarizationChain } from 'langchain/chains';
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import type { Document } from '@langchain/core/documents';
|
||||
import type { TextSplitter } from '@langchain/textsplitters';
|
||||
import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';
|
||||
import { N8nJsonLoader } from '../../../../utils/N8nJsonLoader';
|
||||
import { N8nBinaryLoader } from '../../../../utils/N8nBinaryLoader';
|
||||
import { getTemplateNoticeField } from '../../../../utils/sharedFields';
|
||||
import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';
|
||||
import { getChainPromptsArgs } from '../helpers';
|
||||
import { getTracingConfig } from '../../../../utils/tracing';
|
||||
import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';
|
||||
|
||||
function getInputs(parameters: IDataObject) {
|
||||
const chunkingMode = parameters?.chunkingMode;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { SummarizationChainParams } from 'langchain/chains';
|
||||
import { PromptTemplate } from '@langchain/core/prompts';
|
||||
import type { SummarizationChainParams } from 'langchain/chains';
|
||||
interface ChainTypeOptions {
|
||||
combineMapPrompt?: string;
|
||||
prompt?: string;
|
||||
|
||||
@@ -13,15 +13,12 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions';
|
||||
import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
import { makeZodSchemaFromAttributes } from './helpers';
|
||||
import type { AttributeDefinition } from './types';
|
||||
import {
|
||||
inputSchemaField,
|
||||
jsonSchemaExampleField,
|
||||
schemaTypeField,
|
||||
} from '../../../utils/descriptions';
|
||||
import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
|
||||
const SYSTEM_PROMPT_TEMPLATE = `You are an expert extraction algorithm.
|
||||
Only extract relevant information from the text.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { AttributeDefinition } from './types';
|
||||
|
||||
function makeAttributeSchema(attributeDefinition: AttributeDefinition, required: boolean = true) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow/src';
|
||||
import get from 'lodash/get';
|
||||
|
||||
import { FakeLLM, FakeListChatModel } from '@langchain/core/utils/testing';
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import { InformationExtractor } from '../InformationExtractor.node';
|
||||
import { FakeLLM, FakeListChatModel } from '@langchain/core/utils/testing';
|
||||
import get from 'lodash/get';
|
||||
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow/src';
|
||||
|
||||
import { makeZodSchemaFromAttributes } from '../helpers';
|
||||
import { InformationExtractor } from '../InformationExtractor.node';
|
||||
import type { AttributeDefinition } from '../types';
|
||||
|
||||
const mockPersonAttributes: AttributeDefinition[] = [
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
||||
import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';
|
||||
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
@@ -6,15 +11,9 @@ import type {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
||||
import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';
|
||||
import { z } from 'zod';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
const DEFAULT_SYSTEM_PROMPT_TEMPLATE =
|
||||
'You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON.';
|
||||
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
import { getTracingConfig } from '@utils/tracing';
|
||||
|
||||
const SYSTEM_PROMPT_TEMPLATE =
|
||||
"Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json.";
|
||||
|
||||
Reference in New Issue
Block a user