File tree Expand file tree Collapse file tree 3 files changed +69
-14
lines changed
packages/@n8n/nodes-langchain Expand file tree Collapse file tree 3 files changed +69
-14
lines changed Original file line number Diff line number Diff line change 1
- import type { IAuthenticateGeneric , ICredentialType , INodeProperties } from 'n8n-workflow' ;
1
+ import type {
2
+ ICredentialDataDecryptedObject ,
3
+ ICredentialType ,
4
+ IDisplayOptions ,
5
+ IHttpRequestOptions ,
6
+ INodeProperties ,
7
+ } from 'n8n-workflow' ;
2
8
3
9
export class AzureOpenAiApi implements ICredentialType {
4
10
name = 'azureOpenAiApi' ;
@@ -37,14 +43,50 @@ export class AzureOpenAiApi implements ICredentialType {
37
43
default : undefined ,
38
44
placeholder : 'https://westeurope.api.cognitive.microsoft.com' ,
39
45
} ,
40
- ] ;
41
-
42
- authenticate : IAuthenticateGeneric = {
43
- type : 'generic' ,
44
- properties : {
45
- headers : {
46
- 'api-key' : '={{$credentials.apiKey}}' ,
46
+ {
47
+ displayName : 'Add Custom Header' ,
48
+ name : 'header' ,
49
+ type : 'boolean' ,
50
+ default : false ,
51
+ } ,
52
+ {
53
+ displayName : 'Header Name' ,
54
+ name : 'headerName' ,
55
+ type : 'string' ,
56
+ displayOptions : {
57
+ show : {
58
+ header : [ true ] ,
59
+ } ,
60
+ } as IDisplayOptions ,
61
+ default : '' ,
62
+ } ,
63
+ {
64
+ displayName : 'Header Value' ,
65
+ name : 'headerValue' ,
66
+ type : 'string' ,
67
+ typeOptions : {
68
+ password : true ,
47
69
} ,
70
+ displayOptions : {
71
+ show : {
72
+ header : [ true ] ,
73
+ } ,
74
+ } as IDisplayOptions ,
75
+ default : '' ,
48
76
} ,
49
- } ;
77
+ ] ;
78
+
79
+ async authenticate (
80
+ credentials : ICredentialDataDecryptedObject ,
81
+ requestOptions : IHttpRequestOptions ,
82
+ ) : Promise < IHttpRequestOptions > {
83
+ requestOptions . headers = { 'api-key' : credentials . apiKey } ;
84
+ if ( credentials . header ) {
85
+ requestOptions . headers = {
86
+ 'api-key' : credentials . apiKey ,
87
+ [ credentials . headerName as string ] : credentials . headerValue ,
88
+ } ;
89
+ }
90
+ return requestOptions ;
91
+ }
50
92
}
Original file line number Diff line number Diff line change @@ -358,6 +358,11 @@ export class LmChatOpenAi implements INodeType {
358
358
dispatcher : getProxyAgent ( configuration . baseURL ?? 'https://api.openai.com/v1' ) ,
359
359
} ;
360
360
}
361
+ if ( credentials . header ) {
362
+ configuration . defaultHeaders = {
363
+ [ credentials . headerName as string ] : credentials . headerValue as string ,
364
+ } ;
365
+ }
361
366
362
367
// Extra options to send to OpenAI, that are not directly supported by LangChain
363
368
const modelKwargs : {
Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ export class LmChatAzureOpenAi implements INodeType {
103
103
104
104
this . logger . info ( `Instantiating AzureChatOpenAI model with deployment: ${ modelName } ` ) ;
105
105
106
+ const credentials = await this . getCredentials ( 'azureOpenAiApi' ) ;
107
+ const configuration = {
108
+ fetchOptions : {
109
+ dispatcher : getProxyAgent ( ) ,
110
+ } ,
111
+ defaultHeaders : { } ,
112
+ } ;
113
+ if ( credentials . header ) {
114
+ configuration . defaultHeaders = {
115
+ [ credentials . headerName as string ] : credentials . headerValue as string ,
116
+ } ;
117
+ }
106
118
// Create and return the model
107
119
const model = new AzureChatOpenAI ( {
108
120
azureOpenAIApiDeploymentName : modelName ,
@@ -111,11 +123,7 @@ export class LmChatAzureOpenAi implements INodeType {
111
123
timeout : options . timeout ?? 60000 ,
112
124
maxRetries : options . maxRetries ?? 2 ,
113
125
callbacks : [ new N8nLlmTracing ( this ) ] ,
114
- configuration : {
115
- fetchOptions : {
116
- dispatcher : getProxyAgent ( ) ,
117
- } ,
118
- } ,
126
+ configuration,
119
127
modelKwargs : options . responseFormat
120
128
? {
121
129
response_format : { type : options . responseFormat } ,
You can’t perform that action at this time.
0 commit comments