Skip to content

Commit

Permalink
support prompting with documents
Browse files Browse the repository at this point in the history
  • Loading branch information
narengogi committed Oct 22, 2024
1 parent 3d7551d commit 1a96228
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 52 deletions.
49 changes: 49 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
3 changes: 1 addition & 2 deletions src/providers/bedrock/chatComplete.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
51 changes: 1 addition & 50 deletions src/providers/google-vertex-ai/utils.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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[
Expand Down

0 comments on commit 1a96228

Please sign in to comment.