-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
schema.ts
179 lines (167 loc) · 5.06 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';
import { DEFAULT_OPENAI_MODEL, OpenAiProviderType } from './constants';
// Connector schema
export const ConfigSchema = schema.oneOf([
schema.object({
apiProvider: schema.oneOf([schema.literal(OpenAiProviderType.AzureAi)]),
apiUrl: schema.string(),
headers: schema.maybe(schema.recordOf(schema.string(), schema.string())),
}),
schema.object({
apiProvider: schema.oneOf([schema.literal(OpenAiProviderType.OpenAi)]),
apiUrl: schema.string(),
defaultModel: schema.string({ defaultValue: DEFAULT_OPENAI_MODEL }),
headers: schema.maybe(schema.recordOf(schema.string(), schema.string())),
}),
schema.object({
apiProvider: schema.oneOf([schema.literal(OpenAiProviderType.Other)]),
apiUrl: schema.string(),
defaultModel: schema.string(),
headers: schema.maybe(schema.recordOf(schema.string(), schema.string())),
}),
]);
export const SecretsSchema = schema.object({ apiKey: schema.string() });
// Run action schema
export const RunActionParamsSchema = schema.object({
body: schema.string(),
// abort signal from client
signal: schema.maybe(schema.any()),
timeout: schema.maybe(schema.number()),
});
const AIMessage = schema.object({
role: schema.string(),
content: schema.string(),
name: schema.maybe(schema.string()),
function_call: schema.maybe(
schema.object({
arguments: schema.string(),
name: schema.string(),
})
),
tool_calls: schema.maybe(
schema.arrayOf(
schema.object({
id: schema.string(),
function: schema.object({
arguments: schema.string(),
name: schema.string(),
}),
type: schema.string(),
})
)
),
tool_call_id: schema.maybe(schema.string()),
});
// Run action schema
export const InvokeAIActionParamsSchema = schema.object({
messages: schema.arrayOf(AIMessage),
model: schema.maybe(schema.string()),
functions: schema.maybe(
schema.arrayOf(
schema.object(
{
name: schema.string(),
description: schema.string(),
parameters: schema.object(
{
type: schema.string(),
properties: schema.object({}, { unknowns: 'allow' }),
additionalProperties: schema.boolean(),
$schema: schema.string(),
},
{ unknowns: 'allow' }
),
},
// Not sure if this will include other properties, we should pass them if it does
{ unknowns: 'allow' }
)
)
),
function_call: schema.maybe(
schema.oneOf([
schema.literal('none'),
schema.literal('auto'),
schema.object(
{
name: schema.string(),
},
{ unknowns: 'ignore' }
),
])
),
n: schema.maybe(schema.number()),
stop: schema.maybe(
schema.nullable(schema.oneOf([schema.string(), schema.arrayOf(schema.string())]))
),
temperature: schema.maybe(schema.number()),
// abort signal from client
signal: schema.maybe(schema.any()),
timeout: schema.maybe(schema.number()),
});
export const InvokeAIActionResponseSchema = schema.object({
message: schema.string(),
usage: schema.object(
{
prompt_tokens: schema.number(),
completion_tokens: schema.number(),
total_tokens: schema.number(),
},
{ unknowns: 'ignore' }
),
});
// Execute action schema
export const StreamActionParamsSchema = schema.object({
body: schema.string(),
stream: schema.boolean({ defaultValue: false }),
// abort signal from client
signal: schema.maybe(schema.any()),
timeout: schema.maybe(schema.number()),
});
export const StreamingResponseSchema = schema.any();
export const RunActionResponseSchema = schema.object(
{
id: schema.maybe(schema.string()),
object: schema.maybe(schema.string()),
created: schema.maybe(schema.number()),
model: schema.maybe(schema.string()),
usage: schema.object(
{
prompt_tokens: schema.number(),
completion_tokens: schema.number(),
total_tokens: schema.number(),
},
{ unknowns: 'ignore' }
),
choices: schema.arrayOf(
schema.object(
{
message: schema.object(
{
role: schema.string(),
// nullable because message can contain function calls instead of final response when used with RAG
content: schema.maybe(schema.nullable(schema.string())),
},
{ unknowns: 'ignore' }
),
finish_reason: schema.maybe(schema.string()),
index: schema.maybe(schema.number()),
},
{ unknowns: 'ignore' }
)
),
},
{ unknowns: 'ignore' }
);
// Run action schema
export const DashboardActionParamsSchema = schema.object({
dashboardId: schema.string(),
});
export const DashboardActionResponseSchema = schema.object({
available: schema.boolean(),
});