integrated headers functionality
This commit is contained in:
parent
4a4c940dbd
commit
55ed6819a2
|
|
@ -33,6 +33,13 @@ class ApiChain_Chains implements INode {
|
||||||
label: 'Document',
|
label: 'Document',
|
||||||
name: 'document',
|
name: 'document',
|
||||||
type: 'Document'
|
type: 'Document'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Headers',
|
||||||
|
name: 'headers',
|
||||||
|
type: 'json',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -40,16 +47,18 @@ class ApiChain_Chains implements INode {
|
||||||
async init(nodeData: INodeData): Promise<any> {
|
async init(nodeData: INodeData): Promise<any> {
|
||||||
const model = nodeData.inputs?.model as BaseLanguageModel
|
const model = nodeData.inputs?.model as BaseLanguageModel
|
||||||
const docs = nodeData.inputs?.document as Document[]
|
const docs = nodeData.inputs?.document as Document[]
|
||||||
|
const headers = nodeData.inputs?.headers as string
|
||||||
|
|
||||||
const chain = await getOpenAPIChain(docs, model)
|
const chain = await getAPIChain(docs, model, headers)
|
||||||
return chain
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||||
const model = nodeData.inputs?.model as BaseLanguageModel
|
const model = nodeData.inputs?.model as BaseLanguageModel
|
||||||
const docs = nodeData.inputs?.document as Document[]
|
const docs = nodeData.inputs?.document as Document[]
|
||||||
|
const headers = nodeData.inputs?.headers as string
|
||||||
|
|
||||||
const chain = await getOpenAPIChain(docs, model)
|
const chain = await getAPIChain(docs, model, headers)
|
||||||
if (options.socketIO && options.socketIOClientId) {
|
if (options.socketIO && options.socketIOClientId) {
|
||||||
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
|
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
|
||||||
const res = await chain.run(input, [handler])
|
const res = await chain.run(input, [handler])
|
||||||
|
|
@ -61,7 +70,7 @@ class ApiChain_Chains implements INode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOpenAPIChain = async (documents: Document[], llm: BaseLanguageModel) => {
|
const getAPIChain = async (documents: Document[], llm: BaseLanguageModel, headers: any) => {
|
||||||
const texts = documents.map(({ pageContent }) => pageContent)
|
const texts = documents.map(({ pageContent }) => pageContent)
|
||||||
const apiResponsePrompt = new PromptTemplate({
|
const apiResponsePrompt = new PromptTemplate({
|
||||||
inputVariables: ['api_docs', 'question', 'api_url', 'api_response'],
|
inputVariables: ['api_docs', 'question', 'api_url', 'api_response'],
|
||||||
|
|
@ -70,7 +79,8 @@ const getOpenAPIChain = async (documents: Document[], llm: BaseLanguageModel) =>
|
||||||
|
|
||||||
const chain = APIChain.fromLLMAndAPIDocs(llm, texts.toString(), {
|
const chain = APIChain.fromLLMAndAPIDocs(llm, texts.toString(), {
|
||||||
apiResponsePrompt,
|
apiResponsePrompt,
|
||||||
verbose: process.env.DEBUG === 'true' ? true : false
|
verbose: process.env.DEBUG === 'true' ? true : false,
|
||||||
|
headers: typeof headers === 'object' ? headers : headers ? JSON.parse(headers) : {}
|
||||||
})
|
})
|
||||||
return chain
|
return chain
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue