Skip to content

Commit

Permalink
Merge pull request #240 from Ironclad/gogwilt/gpt4v-node-executor
Browse files Browse the repository at this point in the history
[Fix] GPT-4 Vision supports node executor (and Node.js execution in general)
  • Loading branch information
abrenneke authored Nov 17, 2023
2 parents b03f620 + 853b249 commit d18ff45
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/core/src/utils/base64.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
export async function uint8ArrayToBase64(uint8Array: Uint8Array) {
const blob = new Blob([uint8Array], { type: 'application/octet-stream' });
const dataUrl = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
return dataUrl.split(',')[1];
if (typeof window === 'undefined') {
// Node executor
return Buffer.from(uint8Array).toString('base64');
} else {
// Browser executor
const blob = new Blob([uint8Array], { type: 'application/octet-stream' });
const dataUrl = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
return dataUrl.split(',')[1];
}
}

export function base64ToUint8Array(base64: string) {
Expand Down

0 comments on commit d18ff45

Please sign in to comment.