upgrade langchain version 0.1.0

This commit is contained in:
Henry
2024-01-26 23:41:55 +00:00
parent 601a4d6b66
commit 0606d2c6dd
180 changed files with 905 additions and 746 deletions
+3 -3
View File
@@ -149,8 +149,8 @@ export interface IUsedTool {
* Classes
*/
import { PromptTemplate as LangchainPromptTemplate, PromptTemplateInput } from 'langchain/prompts'
import { VectorStore } from 'langchain/vectorstores/base'
import { PromptTemplate as LangchainPromptTemplate, PromptTemplateInput } from '@langchain/core/prompts'
import { VectorStore } from '@langchain/core/vectorstores'
export class PromptTemplate extends LangchainPromptTemplate {
promptValues: ICommonObject
@@ -202,7 +202,7 @@ export class VectorStoreRetriever {
/**
* Implement abstract classes and interface for memory
*/
import { BaseMessage } from 'langchain/schema'
import { BaseMessage } from '@langchain/core/messages'
import { BufferMemory, BufferWindowMemory, ConversationSummaryMemory } from 'langchain/memory'
export interface MemoryMethods {
+8 -6
View File
@@ -1,11 +1,13 @@
import { AgentExecutorInput, BaseSingleActionAgent, BaseMultiActionAgent, RunnableAgent, StoppingMethod } from 'langchain/agents'
import { ChainValues, AgentStep, AgentFinish, AgentAction, BaseMessage, FunctionMessage, AIMessage } from 'langchain/schema'
import { OutputParserException } from 'langchain/schema/output_parser'
import { CallbackManager, CallbackManagerForChainRun, Callbacks } from 'langchain/callbacks'
import { ChainValues } from '@langchain/core/utils/types'
import { AgentStep, AgentFinish, AgentAction } from '@langchain/core/agents'
import { BaseMessage, FunctionMessage, AIMessage } from '@langchain/core/messages'
import { OutputParserException } from '@langchain/core/output_parsers'
import { CallbackManager, CallbackManagerForChainRun, Callbacks } from '@langchain/core/callbacks/manager'
import { ToolInputParsingException, Tool } from '@langchain/core/tools'
import { Runnable } from 'langchain/schema/runnable'
import { BaseChain, SerializedLLMChain } from 'langchain/chains'
import { Runnable } from '@langchain/core/runnables'
import { Serializable } from '@langchain/core/load/serializable'
import { BaseChain, SerializedLLMChain } from 'langchain/chains'
import { AgentExecutorInput, BaseSingleActionAgent, BaseMultiActionAgent, RunnableAgent, StoppingMethod } from 'langchain/agents'
type AgentExecutorOutput = ChainValues
+64 -60
View File
@@ -1,17 +1,21 @@
import { BaseTracer, Run, BaseCallbackHandler, LangChainTracer } from 'langchain/callbacks'
import { AgentAction, ChainValues } from 'langchain/schema'
import { Logger } from 'winston'
import { v4 as uuidv4 } from 'uuid'
import { Server } from 'socket.io'
import { Client } from 'langsmith'
import { LLMonitorHandler, LLMonitorHandlerFields } from 'langchain/callbacks/handlers/llmonitor'
import { getCredentialData, getCredentialParam } from './utils'
import { ICommonObject, INodeData } from './Interface'
import CallbackHandler from 'langfuse-langchain'
import { LangChainTracerFields } from '@langchain/core/tracers/tracer_langchain'
import lunary from 'lunary'
import { RunTree, RunTreeConfig, Client as LangsmithClient } from 'langsmith'
import { Langfuse, LangfuseTraceClient, LangfuseSpanClient, LangfuseGenerationClient } from 'langfuse'
import monitor from 'llmonitor'
import { v4 as uuidv4 } from 'uuid'
import { BaseCallbackHandler } from '@langchain/core/callbacks/base'
import { LangChainTracer, LangChainTracerFields } from '@langchain/core/tracers/tracer_langchain'
import { BaseTracer, Run } from '@langchain/core/tracers/base'
import { ChainValues } from '@langchain/core/utils/types'
import { AgentAction } from '@langchain/core/agents'
import { LunaryHandler } from '@langchain/community/callbacks/handlers/lunary'
import { getCredentialData, getCredentialParam } from './utils'
import { ICommonObject, INodeData } from './Interface'
interface AgentRun extends Run {
actions: AgentAction[]
@@ -268,20 +272,20 @@ export const additionalCallbacks = async (nodeData: INodeData, options: ICommonO
const handler = new CallbackHandler(langFuseOptions)
callbacks.push(handler)
} else if (provider === 'llmonitor') {
const llmonitorAppId = getCredentialParam('llmonitorAppId', credentialData, nodeData)
const llmonitorEndpoint = getCredentialParam('llmonitorEndpoint', credentialData, nodeData)
} else if (provider === 'lunary') {
const lunaryAppId = getCredentialParam('lunaryAppId', credentialData, nodeData)
const lunaryEndpoint = getCredentialParam('lunaryEndpoint', credentialData, nodeData)
let llmonitorFields: LLMonitorHandlerFields = {
appId: llmonitorAppId,
apiUrl: llmonitorEndpoint ?? 'https://app.llmonitor.com'
let lunaryFields = {
appId: lunaryAppId,
apiUrl: lunaryEndpoint ?? 'https://app.lunary.ai'
}
if (nodeData?.inputs?.analytics?.llmonitor) {
llmonitorFields = { ...llmonitorFields, ...nodeData?.inputs?.analytics?.llmonitor }
if (nodeData?.inputs?.analytics?.lunary) {
lunaryFields = { ...lunaryFields, ...nodeData?.inputs?.analytics?.lunary }
}
const handler = new LLMonitorHandler(llmonitorFields)
const handler = new LunaryHandler(lunaryFields)
callbacks.push(handler)
}
}
@@ -339,16 +343,16 @@ export class AnalyticHandler {
release
})
this.handlers['langFuse'] = { client: langfuse }
} else if (provider === 'llmonitor') {
const llmonitorAppId = getCredentialParam('llmonitorAppId', credentialData, this.nodeData)
const llmonitorEndpoint = getCredentialParam('llmonitorEndpoint', credentialData, this.nodeData)
} else if (provider === 'lunary') {
const lunaryAppId = getCredentialParam('lunaryAppId', credentialData, this.nodeData)
const lunaryEndpoint = getCredentialParam('lunaryEndpoint', credentialData, this.nodeData)
monitor.init({
appId: llmonitorAppId,
apiUrl: llmonitorEndpoint
lunary.init({
appId: lunaryAppId,
apiUrl: lunaryEndpoint
})
this.handlers['llmonitor'] = { client: monitor }
this.handlers['lunary'] = { client: lunary }
}
}
}
@@ -361,7 +365,7 @@ export class AnalyticHandler {
const returnIds: ICommonObject = {
langSmith: {},
langFuse: {},
llmonitor: {}
lunary: {}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'langSmith')) {
@@ -427,8 +431,8 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const monitor = this.handlers['lunary'].client
if (monitor) {
const runId = uuidv4()
@@ -437,10 +441,10 @@ export class AnalyticHandler {
name,
userId: this.options.chatId,
input,
...this.nodeData?.inputs?.analytics?.llmonitor
...this.nodeData?.inputs?.analytics?.lunary
})
this.handlers['llmonitor'].chainEvent = { [runId]: runId }
returnIds['llmonitor'].chainEvent = runId
this.handlers['lunary'].chainEvent = { [runId]: runId }
returnIds['lunary'].chainEvent = runId
}
}
@@ -473,9 +477,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const chainEventId = returnIds['llmonitor'].chainEvent
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const chainEventId = returnIds['lunary'].chainEvent
const monitor = this.handlers['lunary'].client
if (monitor && chainEventId) {
await monitor.trackEvent('chain', 'end', {
@@ -514,9 +518,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const chainEventId = returnIds['llmonitor'].chainEvent
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const chainEventId = returnIds['lunary'].chainEvent
const monitor = this.handlers['lunary'].client
if (monitor && chainEventId) {
await monitor.trackEvent('chain', 'end', {
@@ -531,7 +535,7 @@ export class AnalyticHandler {
const returnIds: ICommonObject = {
langSmith: {},
langFuse: {},
llmonitor: {}
lunary: {}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'langSmith')) {
@@ -562,9 +566,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const monitor = this.handlers['llmonitor'].client
const chainEventId: string = this.handlers['llmonitor'].chainEvent[parentIds['llmonitor'].chainEvent]
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const monitor = this.handlers['lunary'].client
const chainEventId: string = this.handlers['lunary'].chainEvent[parentIds['lunary'].chainEvent]
if (monitor && chainEventId) {
const runId = uuidv4()
@@ -575,8 +579,8 @@ export class AnalyticHandler {
userId: this.options.chatId,
input
})
this.handlers['llmonitor'].llmEvent = { [runId]: runId }
returnIds['llmonitor'].llmEvent = runId
this.handlers['lunary'].llmEvent = { [runId]: runId }
returnIds['lunary'].llmEvent = runId
}
}
@@ -605,9 +609,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const llmEventId: string = this.handlers['llmonitor'].llmEvent[returnIds['llmonitor'].llmEvent]
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const llmEventId: string = this.handlers['lunary'].llmEvent[returnIds['lunary'].llmEvent]
const monitor = this.handlers['lunary'].client
if (monitor && llmEventId) {
await monitor.trackEvent('llm', 'end', {
@@ -640,9 +644,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const llmEventId: string = this.handlers['llmonitor'].llmEvent[returnIds['llmonitor'].llmEvent]
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const llmEventId: string = this.handlers['lunary'].llmEvent[returnIds['lunary'].llmEvent]
const monitor = this.handlers['lunary'].client
if (monitor && llmEventId) {
await monitor.trackEvent('llm', 'end', {
@@ -657,7 +661,7 @@ export class AnalyticHandler {
const returnIds: ICommonObject = {
langSmith: {},
langFuse: {},
llmonitor: {}
lunary: {}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'langSmith')) {
@@ -688,9 +692,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const monitor = this.handlers['llmonitor'].client
const chainEventId: string = this.handlers['llmonitor'].chainEvent[parentIds['llmonitor'].chainEvent]
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const monitor = this.handlers['lunary'].client
const chainEventId: string = this.handlers['lunary'].chainEvent[parentIds['lunary'].chainEvent]
if (monitor && chainEventId) {
const runId = uuidv4()
@@ -701,8 +705,8 @@ export class AnalyticHandler {
userId: this.options.chatId,
input
})
this.handlers['llmonitor'].toolEvent = { [runId]: runId }
returnIds['llmonitor'].toolEvent = runId
this.handlers['lunary'].toolEvent = { [runId]: runId }
returnIds['lunary'].toolEvent = runId
}
}
@@ -731,9 +735,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const toolEventId: string = this.handlers['llmonitor'].toolEvent[returnIds['llmonitor'].toolEvent]
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const toolEventId: string = this.handlers['lunary'].toolEvent[returnIds['lunary'].toolEvent]
const monitor = this.handlers['lunary'].client
if (monitor && toolEventId) {
await monitor.trackEvent('tool', 'end', {
@@ -766,9 +770,9 @@ export class AnalyticHandler {
}
}
if (Object.prototype.hasOwnProperty.call(this.handlers, 'llmonitor')) {
const toolEventId: string = this.handlers['llmonitor'].llmEvent[returnIds['llmonitor'].toolEvent]
const monitor = this.handlers['llmonitor'].client
if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
const toolEventId: string = this.handlers['lunary'].llmEvent[returnIds['lunary'].toolEvent]
const monitor = this.handlers['lunary'].client
if (monitor && toolEventId) {
await monitor.trackEvent('tool', 'end', {
+2 -2
View File
@@ -8,7 +8,7 @@ import { DataSource } from 'typeorm'
import { ICommonObject, IDatabaseEntity, IMessage, INodeData, IVariable } from './Interface'
import { AES, enc } from 'crypto-js'
import { ChatMessageHistory } from 'langchain/memory'
import { AIMessage, HumanMessage, BaseMessage } from 'langchain/schema'
import { AIMessage, HumanMessage, BaseMessage } from '@langchain/core/messages'
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
export const notEmptyRegex = '(.|\\s)*\\S(.|\\s)*' //return true if string is not empty or blank
@@ -49,7 +49,7 @@ export const availableDependencies = [
'langfuse',
'langsmith',
'linkifyjs',
'llmonitor',
'lunary',
'mammoth',
'moment',
'mongodb',