librechat-data-provider 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/config.ts CHANGED
@@ -18,6 +18,11 @@ export const defaultRetrievalModels = [
18
18
  'gpt-4-1106',
19
19
  ];
20
20
 
21
+ export enum SettingsViews {
22
+ default = 'default',
23
+ advanced = 'advanced',
24
+ }
25
+
21
26
  export const fileSourceSchema = z.nativeEnum(FileSources);
22
27
 
23
28
  export const modelConfigSchema = z
@@ -55,8 +60,8 @@ export const azureGroupSchema = z
55
60
  .and(azureBaseSchema);
56
61
 
57
62
  export const azureGroupConfigsSchema = z.array(azureGroupSchema).min(1);
63
+ export type TAzureGroup = z.infer<typeof azureGroupSchema>;
58
64
  export type TAzureGroups = z.infer<typeof azureGroupConfigsSchema>;
59
-
60
65
  export type TAzureModelMapSchema = {
61
66
  // deploymentName?: string;
62
67
  // version?: string;
@@ -77,6 +82,7 @@ export type TValidatedAzureConfig = {
77
82
 
78
83
  export enum Capabilities {
79
84
  code_interpreter = 'code_interpreter',
85
+ image_vision = 'image_vision',
80
86
  retrieval = 'retrieval',
81
87
  actions = 'actions',
82
88
  tools = 'tools',
@@ -95,6 +101,7 @@ export const assistantEndpointSchema = z.object({
95
101
  .optional()
96
102
  .default([
97
103
  Capabilities.code_interpreter,
104
+ Capabilities.image_vision,
98
105
  Capabilities.retrieval,
99
106
  Capabilities.actions,
100
107
  Capabilities.tools,
@@ -143,6 +150,8 @@ export const endpointSchema = z.object({
143
150
  customOrder: z.number().optional(),
144
151
  });
145
152
 
153
+ export type TEndpoint = z.infer<typeof endpointSchema>;
154
+
146
155
  export const azureEndpointSchema = z
147
156
  .object({
148
157
  groups: azureGroupConfigsSchema,
@@ -178,7 +187,7 @@ export const rateLimitSchema = z.object({
178
187
 
179
188
  export const configSchema = z.object({
180
189
  version: z.string(),
181
- cache: z.boolean(),
190
+ cache: z.boolean().optional().default(true),
182
191
  interface: z
183
192
  .object({
184
193
  privacyPolicy: z
@@ -229,6 +238,7 @@ export enum KnownEndpoints {
229
238
  ollama = 'ollama',
230
239
  perplexity = 'perplexity',
231
240
  'together.ai' = 'together.ai',
241
+ cohere = 'cohere',
232
242
  }
233
243
 
234
244
  export enum FetchTokenConfig {
@@ -292,6 +302,7 @@ export const defaultModels = {
292
302
  [EModelEndpoint.anthropic]: [
293
303
  'claude-3-opus-20240229',
294
304
  'claude-3-sonnet-20240229',
305
+ 'claude-3-haiku-20240307',
295
306
  'claude-2.1',
296
307
  'claude-2',
297
308
  'claude-1.2',
@@ -511,7 +522,7 @@ export enum Constants {
511
522
  /**
512
523
  * Key for the app's version.
513
524
  */
514
- VERSION = 'v0.6.10',
525
+ VERSION = 'v0.7.0',
515
526
  /**
516
527
  * Key for the Custom Config's version (librechat.yaml).
517
528
  */
@@ -522,8 +533,62 @@ export enum Constants {
522
533
  NO_PARENT = '00000000-0000-0000-0000-000000000000',
523
534
  }
524
535
 
536
+ /**
537
+ * Enum for Cohere related constants
538
+ */
539
+ export enum CohereConstants {
540
+ /**
541
+ * Cohere API Endpoint, for special handling
542
+ */
543
+ API_URL = 'https://api.cohere.ai/v1',
544
+ /**
545
+ * Role for "USER" messages
546
+ */
547
+ ROLE_USER = 'USER',
548
+ /**
549
+ * Role for "SYSTEM" messages
550
+ */
551
+ ROLE_SYSTEM = 'SYSTEM',
552
+ /**
553
+ * Role for "CHATBOT" messages
554
+ */
555
+ ROLE_CHATBOT = 'CHATBOT',
556
+ /**
557
+ * Title message as required by Cohere
558
+ */
559
+ TITLE_MESSAGE = 'TITLE:',
560
+ }
561
+
525
562
  export const defaultOrderQuery: {
526
- order: 'asc';
563
+ order: 'desc';
564
+ limit: 100;
527
565
  } = {
528
- order: 'asc',
566
+ order: 'desc',
567
+ limit: 100,
529
568
  };
569
+
570
+ export enum AssistantStreamEvents {
571
+ ThreadCreated = 'thread.created',
572
+ ThreadRunCreated = 'thread.run.created',
573
+ ThreadRunQueued = 'thread.run.queued',
574
+ ThreadRunInProgress = 'thread.run.in_progress',
575
+ ThreadRunRequiresAction = 'thread.run.requires_action',
576
+ ThreadRunCompleted = 'thread.run.completed',
577
+ ThreadRunFailed = 'thread.run.failed',
578
+ ThreadRunCancelling = 'thread.run.cancelling',
579
+ ThreadRunCancelled = 'thread.run.cancelled',
580
+ ThreadRunExpired = 'thread.run.expired',
581
+ ThreadRunStepCreated = 'thread.run.step.created',
582
+ ThreadRunStepInProgress = 'thread.run.step.in_progress',
583
+ ThreadRunStepCompleted = 'thread.run.step.completed',
584
+ ThreadRunStepFailed = 'thread.run.step.failed',
585
+ ThreadRunStepCancelled = 'thread.run.step.cancelled',
586
+ ThreadRunStepExpired = 'thread.run.step.expired',
587
+ ThreadRunStepDelta = 'thread.run.step.delta',
588
+ ThreadMessageCreated = 'thread.message.created',
589
+ ThreadMessageInProgress = 'thread.message.in_progress',
590
+ ThreadMessageCompleted = 'thread.message.completed',
591
+ ThreadMessageIncomplete = 'thread.message.incomplete',
592
+ ThreadMessageDelta = 'thread.message.delta',
593
+ ErrorEvent = 'error',
594
+ }
@@ -6,10 +6,7 @@ import * as t from './types';
6
6
  import * as s from './schemas';
7
7
  import request from './request';
8
8
  import * as endpoints from './api-endpoints';
9
-
10
- export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
11
- return request.get(endpoints.conversations(pageNumber));
12
- }
9
+ import type { AxiosResponse } from 'axios';
13
10
 
14
11
  export function abortRequestWithMessage(
15
12
  endpoint: string,
@@ -19,15 +16,6 @@ export function abortRequestWithMessage(
19
16
  return request.post(endpoints.abortRequest(endpoint), { arg: { abortKey, message } });
20
17
  }
21
18
 
22
- export function deleteConversation(payload: t.TDeleteConversationRequest) {
23
- //todo: this should be a DELETE request
24
- return request.post(endpoints.deleteConversation(), { arg: payload });
25
- }
26
-
27
- export function clearAllConversations(): Promise<unknown> {
28
- return request.post(endpoints.deleteConversation(), { arg: {} });
29
- }
30
-
31
19
  export function revokeUserKey(name: string): Promise<unknown> {
32
20
  return request.delete(endpoints.revokeUserKey(name));
33
21
  }
@@ -43,20 +31,6 @@ export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage
43
31
  return request.get(endpoints.messages(conversationId));
44
32
  }
45
33
 
46
- export function getConversationById(id: string): Promise<s.TConversation> {
47
- return request.get(endpoints.conversationById(id));
48
- }
49
-
50
- export function updateConversation(
51
- payload: t.TUpdateConversationRequest,
52
- ): Promise<t.TUpdateConversationResponse> {
53
- return request.post(endpoints.updateConversation(), { arg: payload });
54
- }
55
-
56
- export function genTitle(payload: m.TGenTitleRequest): Promise<m.TGenTitleResponse> {
57
- return request.post(endpoints.genTitle(), payload);
58
- }
59
-
60
34
  export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
61
35
  const { conversationId, messageId, text } = payload;
62
36
  if (!conversationId) {
@@ -103,13 +77,6 @@ export function getUserBalance(): Promise<string> {
103
77
  return request.get(endpoints.balance());
104
78
  }
105
79
 
106
- export const searchConversations = async (
107
- q: string,
108
- pageNumber: string,
109
- ): Promise<t.TSearchResults> => {
110
- return request.get(endpoints.search(q, pageNumber));
111
- };
112
-
113
80
  export const updateTokenCount = (text: string) => {
114
81
  return request.post(endpoints.tokenizer(), { arg: text });
115
82
  };
@@ -196,6 +163,10 @@ export const listAssistants = (
196
163
  return request.get(endpoints.assistants(), { params });
197
164
  };
198
165
 
166
+ export function getAssistantDocs(): Promise<a.AssistantDocument[]> {
167
+ return request.get(endpoints.assistants('documents'));
168
+ }
169
+
199
170
  /* Tools */
200
171
 
201
172
  export const getAvailableTools = (): Promise<s.TPlugin[]> => {
@@ -231,19 +202,13 @@ export const uploadAssistantAvatar = (data: m.AssistantAvatarVariables): Promise
231
202
  );
232
203
  };
233
204
 
234
- export const updateAction = (data: m.UpdateActionVariables): Promise<m.UpdateActionResponse> => {
235
- const { assistant_id, ...body } = data;
236
- return request.post(endpoints.assistants(`actions/${assistant_id}`), body);
205
+ export const getFileDownload = async (userId: string, filepath: string): Promise<AxiosResponse> => {
206
+ const encodedFilePath = encodeURIComponent(filepath);
207
+ return request.getResponse(`${endpoints.files()}/download/${userId}/${encodedFilePath}`, {
208
+ responseType: 'blob',
209
+ });
237
210
  };
238
211
 
239
- export function getActions(): Promise<a.Action[]> {
240
- return request.get(endpoints.assistants('actions'));
241
- }
242
-
243
- export function getAssistantDocs(): Promise<a.AssistantDocument[]> {
244
- return request.get(endpoints.assistants('documents'));
245
- }
246
-
247
212
  export const deleteFiles = async (
248
213
  files: f.BatchFile[],
249
214
  assistant_id?: string,
@@ -252,8 +217,35 @@ export const deleteFiles = async (
252
217
  data: { files, assistant_id },
253
218
  });
254
219
 
220
+ /* actions */
221
+
222
+ export const updateAction = (data: m.UpdateActionVariables): Promise<m.UpdateActionResponse> => {
223
+ const { assistant_id, ...body } = data;
224
+ return request.post(endpoints.assistants(`actions/${assistant_id}`), body);
225
+ };
226
+
227
+ export function getActions(): Promise<a.Action[]> {
228
+ return request.get(endpoints.assistants('actions'));
229
+ }
230
+
231
+ export const deleteAction = async (
232
+ assistant_id: string,
233
+ action_id: string,
234
+ model: string,
235
+ ): Promise<void> =>
236
+ request.delete(endpoints.assistants(`actions/${assistant_id}/${action_id}/${model}`));
237
+
255
238
  /* conversations */
256
239
 
240
+ export function deleteConversation(payload: t.TDeleteConversationRequest) {
241
+ //todo: this should be a DELETE request
242
+ return request.post(endpoints.deleteConversation(), { arg: payload });
243
+ }
244
+
245
+ export function clearAllConversations(): Promise<unknown> {
246
+ return request.post(endpoints.deleteConversation(), { arg: {} });
247
+ }
248
+
257
249
  export const listConversations = (
258
250
  params?: q.ConversationListParams,
259
251
  ): Promise<q.ConversationListResponse> => {
@@ -275,5 +267,27 @@ export const listConversationsByQuery = (
275
267
  }
276
268
  };
277
269
 
278
- export const deleteAction = async (assistant_id: string, action_id: string): Promise<void> =>
279
- request.delete(endpoints.assistants(`actions/${assistant_id}/${action_id}`));
270
+ export const searchConversations = async (
271
+ q: string,
272
+ pageNumber: string,
273
+ ): Promise<t.TSearchResults> => {
274
+ return request.get(endpoints.search(q, pageNumber));
275
+ };
276
+
277
+ export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
278
+ return request.get(endpoints.conversations(pageNumber));
279
+ }
280
+
281
+ export function getConversationById(id: string): Promise<s.TConversation> {
282
+ return request.get(endpoints.conversationById(id));
283
+ }
284
+
285
+ export function updateConversation(
286
+ payload: t.TUpdateConversationRequest,
287
+ ): Promise<t.TUpdateConversationResponse> {
288
+ return request.post(endpoints.updateConversation(), { arg: payload });
289
+ }
290
+
291
+ export function genTitle(payload: m.TGenTitleRequest): Promise<m.TGenTitleResponse> {
292
+ return request.post(endpoints.genTitle(), payload);
293
+ }
package/src/keys.ts CHANGED
@@ -22,6 +22,7 @@ export enum QueryKeys {
22
22
  tools = 'tools',
23
23
  actions = 'actions',
24
24
  assistantDocs = 'assistantDocs',
25
+ fileDownload = 'fileDownload',
25
26
  }
26
27
 
27
28
  export enum MutationKeys {
package/src/request.ts CHANGED
@@ -8,6 +8,10 @@ async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
8
8
  return response.data;
9
9
  }
10
10
 
11
+ async function _getResponse<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
12
+ return await axios.get(url, { ...options });
13
+ }
14
+
11
15
  async function _post(url: string, data?: any) {
12
16
  const response = await axios.post(url, JSON.stringify(data), {
13
17
  headers: { 'Content-Type': 'application/json' },
@@ -114,6 +118,7 @@ axios.interceptors.response.use(
114
118
 
115
119
  export default {
116
120
  get: _get,
121
+ getResponse: _getResponse,
117
122
  post: _post,
118
123
  postMultiPart: _postMultiPart,
119
124
  put: _put,
package/src/schemas.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
- import type { TMessageContentParts } from './types/assistants';
2
+ import { Tools } from './types/assistants';
3
+ import type { TMessageContentParts, FunctionTool, FunctionToolCall } from './types/assistants';
3
4
  import type { TFile } from './types/files';
4
5
 
5
6
  export const isUUID = z.string().uuid();
@@ -25,9 +26,26 @@ export const defaultAssistantFormValues = {
25
26
  model: '',
26
27
  functions: [],
27
28
  code_interpreter: false,
29
+ image_vision: false,
28
30
  retrieval: false,
29
31
  };
30
32
 
33
+ export const ImageVisionTool: FunctionTool = {
34
+ type: Tools.function,
35
+ [Tools.function]: {
36
+ name: 'image_vision',
37
+ description: 'Get detailed text descriptions for all current image attachments.',
38
+ parameters: {
39
+ type: 'object',
40
+ properties: {},
41
+ required: [],
42
+ },
43
+ },
44
+ };
45
+
46
+ export const isImageVisionTool = (tool: FunctionTool | FunctionToolCall) =>
47
+ tool.type === 'function' && tool.function?.name === ImageVisionTool?.function?.name;
48
+
31
49
  export const endpointSettings = {
32
50
  [EModelEndpoint.google]: {
33
51
  model: {
@@ -1,4 +1,5 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
+ import type { TFile } from './files';
2
3
 
3
4
  export type Schema = OpenAPIV3.SchemaObject & { description?: string };
4
5
  export type Reference = OpenAPIV3.ReferenceObject & { description?: string };
@@ -131,7 +132,7 @@ export type ToolCallsStepDetails = {
131
132
  type: 'tool_calls'; // Always 'tool_calls'.
132
133
  };
133
134
 
134
- export type ImageFile = {
135
+ export type ImageFile = TFile & {
135
136
  /**
136
137
  * The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
137
138
  * in the message content.
@@ -182,10 +183,16 @@ export type Text = {
182
183
  value: string;
183
184
  };
184
185
 
186
+ export enum AnnotationTypes {
187
+ FILE_CITATION = 'file_citation',
188
+ FILE_PATH = 'file_path',
189
+ }
190
+
185
191
  export enum ContentTypes {
186
192
  TEXT = 'text',
187
193
  TOOL_CALL = 'tool_call',
188
194
  IMAGE_FILE = 'image_file',
195
+ ERROR = 'error',
189
196
  }
190
197
 
191
198
  export enum StepTypes {
@@ -236,6 +243,7 @@ export type ContentPart = (CodeToolCall | RetrievalToolCall | FunctionToolCall |
236
243
  PartMetadata;
237
244
 
238
245
  export type TMessageContentParts =
246
+ | { type: ContentTypes.ERROR; text: Text & PartMetadata }
239
247
  | { type: ContentTypes.TEXT; text: Text & PartMetadata }
240
248
  | {
241
249
  type: ContentTypes.TOOL_CALL;
@@ -243,16 +251,25 @@ export type TMessageContentParts =
243
251
  }
244
252
  | { type: ContentTypes.IMAGE_FILE; image_file: ImageFile & PartMetadata };
245
253
 
246
- export type TContentData = TMessageContentParts & {
254
+ export type StreamContentData = TMessageContentParts & {
255
+ /** The index of the current content part */
256
+ index: number;
257
+ /** The current text content was already served but edited to replace elements therein */
258
+ edited?: boolean;
259
+ };
260
+
261
+ export type TContentData = StreamContentData & {
247
262
  messageId: string;
248
263
  conversationId: string;
249
264
  userMessageId: string;
250
265
  thread_id: string;
251
- index: number;
252
266
  stream?: boolean;
253
267
  };
254
268
 
255
269
  export const actionDelimiter = '_action_';
270
+ export const actionDomainSeparator = '---';
271
+ export const hostImageIdSuffix = '_host_copy';
272
+ export const hostImageNamePrefix = 'host_copy_';
256
273
 
257
274
  export enum AuthTypeEnum {
258
275
  ServiceHttp = 'service_http',
@@ -3,6 +3,7 @@ export enum FileSources {
3
3
  firebase = 'firebase',
4
4
  openai = 'openai',
5
5
  s3 = 's3',
6
+ vectordb = 'vectordb',
6
7
  }
7
8
 
8
9
  export enum FileContext {
@@ -56,6 +56,7 @@ export type UpdateActionVariables = {
56
56
  functions: FunctionTool[];
57
57
  metadata: ActionMetadata;
58
58
  action_id?: string;
59
+ model: string;
59
60
  };
60
61
 
61
62
  export type UploadAssistantAvatarOptions = {
@@ -109,6 +110,7 @@ export type UpdateActionOptions = {
109
110
  export type DeleteActionVariables = {
110
111
  assistant_id: string;
111
112
  action_id: string;
113
+ model: string;
112
114
  };
113
115
 
114
116
  export type DeleteActionOptions = {
package/tsconfig.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "target": "es5",
9
9
  "moduleResolution": "node",
10
10
  "allowSyntheticDefaultImports": true,
11
- "lib": ["es2017", "dom"],
11
+ "lib": ["es2017", "dom", "ES2021.String"],
12
12
  "allowJs": true,
13
13
  "skipLibCheck": true,
14
14
  "esModuleInterop": true,