From 1a962284e3972685d63c8f704b2a279134875d89 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Tue, 22 Oct 2024 19:15:28 +0530 Subject: [PATCH] support prompting with documents --- src/globals.ts | 49 ++++++++++++++++++++++++ src/providers/bedrock/chatComplete.ts | 3 +- src/providers/google-vertex-ai/utils.ts | 51 +------------------------ 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/globals.ts b/src/globals.ts index 4faa3a424..d38b9a90f 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -138,3 +138,52 @@ export const MULTIPART_FORM_DATA_ENDPOINTS: endpointStrings[] = [ 'createTranscription', 'createTranslation', ]; + +export const fileExtensionMimeTypeMap = { + mp4: 'video/mp4', + jpeg: 'image/jpeg', + jpg: 'image/jpeg', + png: 'image/png', + bmp: 'image/bmp', + tiff: 'image/tiff', + webp: 'image/webp', + pdf: 'application/pdf', + csv: 'text/csv', + doc: 'application/msword', + docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + xls: 'application/vnd.ms-excel', + xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + html: 'text/html', + md: 'text/markdown', + mp3: 'audio/mp3', + wav: 'audio/wav', + txt: 'text/plain', + mov: 'video/mov', + mpeg: 'video/mpeg', + mpg: 'video/mpg', + avi: 'video/avi', + wmv: 'video/wmv', + mpegps: 'video/mpegps', + flv: 'video/flv', +}; + +export const imagesMimeTypes = [ + fileExtensionMimeTypeMap.jpeg, + fileExtensionMimeTypeMap.jpg, + fileExtensionMimeTypeMap.png, + fileExtensionMimeTypeMap.bmp, + fileExtensionMimeTypeMap.tiff, + fileExtensionMimeTypeMap.webp, +]; + +export const documentMimeTypes = [ + fileExtensionMimeTypeMap.pdf, + fileExtensionMimeTypeMap.csv, + fileExtensionMimeTypeMap.doc, + fileExtensionMimeTypeMap.docx, + fileExtensionMimeTypeMap.xls, + fileExtensionMimeTypeMap.xlsx, + fileExtensionMimeTypeMap.html, + fileExtensionMimeTypeMap.md, + fileExtensionMimeTypeMap.txt, +]; diff --git a/src/providers/bedrock/chatComplete.ts b/src/providers/bedrock/chatComplete.ts index 0bc60fc82..16038d411 100644 --- a/src/providers/bedrock/chatComplete.ts +++ b/src/providers/bedrock/chatComplete.ts @@ -1,6 +1,5 @@ -import { BEDROCK } from '../../globals'; +import { BEDROCK, documentMimeTypes, imagesMimeTypes } from '../../globals'; import { Message, Params, ToolCall } from '../../types/requestBody'; -import { documentMimeTypes, imagesMimeTypes } from '../google-vertex-ai/utils'; import { ChatCompletionResponse, ErrorResponse, diff --git a/src/providers/google-vertex-ai/utils.ts b/src/providers/google-vertex-ai/utils.ts index 9a4e6c0a8..7b690c9c4 100644 --- a/src/providers/google-vertex-ai/utils.ts +++ b/src/providers/google-vertex-ai/utils.ts @@ -1,6 +1,6 @@ import { GoogleErrorResponse } from './types'; import { generateErrorResponse } from '../utils'; -import { GOOGLE_VERTEX_AI } from '../../globals'; +import { fileExtensionMimeTypeMap, GOOGLE_VERTEX_AI } from '../../globals'; import { ErrorResponse } from '../types'; /** @@ -141,55 +141,6 @@ export const getModelAndProvider = (modelString: string) => { return { provider, model }; }; -const fileExtensionMimeTypeMap = { - mp4: 'video/mp4', - jpeg: 'image/jpeg', - jpg: 'image/jpeg', - png: 'image/png', - bmp: 'image/bmp', - tiff: 'image/tiff', - webp: 'image/webp', - pdf: 'application/pdf', - csv: 'text/csv', - doc: 'application/msword', - docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - xls: 'application/vnd.ms-excel', - xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - html: 'text/html', - md: 'text/markdown', - mp3: 'audio/mp3', - wav: 'audio/wav', - txt: 'text/plain', - mov: 'video/mov', - mpeg: 'video/mpeg', - mpg: 'video/mpg', - avi: 'video/avi', - wmv: 'video/wmv', - mpegps: 'video/mpegps', - flv: 'video/flv', -}; - -export const imagesMimeTypes = [ - fileExtensionMimeTypeMap.jpeg, - fileExtensionMimeTypeMap.jpg, - fileExtensionMimeTypeMap.png, - fileExtensionMimeTypeMap.bmp, - fileExtensionMimeTypeMap.tiff, - fileExtensionMimeTypeMap.webp, -]; - -export const documentMimeTypes = [ - fileExtensionMimeTypeMap.pdf, - fileExtensionMimeTypeMap.csv, - fileExtensionMimeTypeMap.doc, - fileExtensionMimeTypeMap.docx, - fileExtensionMimeTypeMap.xls, - fileExtensionMimeTypeMap.xlsx, - fileExtensionMimeTypeMap.html, - fileExtensionMimeTypeMap.md, - fileExtensionMimeTypeMap.txt, -]; - export const getMimeType = (url: string): string | undefined => { const urlParts = url.split('.'); const extension = urlParts[