@isnolan/bodhi-adapter
Advanced tools
Comparing version 0.5.5 to 0.6.0
@@ -56,3 +56,4 @@ declare enum Provider { | ||
type FilePart = { | ||
type: 'image' | 'video' | 'document'; | ||
type: 'file'; | ||
mime_type: string; | ||
url: string; | ||
@@ -59,0 +60,0 @@ }; |
@@ -71,4 +71,4 @@ // src/types/provider.ts | ||
const base64 = buffer.toString("base64"); | ||
const mime_type = response.headers.get("content-type"); | ||
return { mime_type, data: base64 }; | ||
const mimeType = response.headers.get("content-type"); | ||
return { mimeType, data: base64 }; | ||
} | ||
@@ -220,4 +220,4 @@ combineChoices(choices) { | ||
} | ||
if (["image", "video"].includes(part.type)) { | ||
parts.push({ type: "image_url", image_url: part.url }); | ||
if (part.type === "file" && part.mime_type?.startsWith("image")) { | ||
parts.push({ type: "image_url", image_url: { url: part.url } }); | ||
} | ||
@@ -361,2 +361,3 @@ if (part.type === "function_call" && part.id) { | ||
contents: await this.corvertContents(opts), | ||
// systemInstruction: await this.corvertSystemContent(opts), | ||
tools: this.corvertTools(opts), | ||
@@ -381,3 +382,3 @@ safety_settings: [ | ||
const rows = await Promise.all( | ||
opts.messages.filter((item) => item.role !== "system").map(async (item) => { | ||
opts.messages.filter((item) => ["user", "assistant"].includes(item.role)).map(async (item) => { | ||
const parts = []; | ||
@@ -389,7 +390,11 @@ await Promise.all( | ||
} | ||
if (["image", "video"].includes(part.type)) { | ||
try { | ||
const inline_data = await this.fetchFile(part.url); | ||
parts.push({ inline_data }); | ||
} catch (err) { | ||
if (part.type === "file") { | ||
const { mime_type, url } = part; | ||
if (url.startsWith("gs://")) { | ||
parts.push({ fileData: { mimeType: mime_type, fileUri: url } }); | ||
} else { | ||
try { | ||
parts.push({ inlineData: await this.fetchFile(url) }); | ||
} catch (err) { | ||
} | ||
} | ||
@@ -456,3 +461,3 @@ } | ||
{ | ||
baseURL: "https://asia-northeast1-aiplatform.googleapis.com/v1/projects/bodhi-415003/locations/asia-northeast1" | ||
baseURL: "https://us-central1-aiplatform.googleapis.com/v1/projects/bodhi-415003/locations/us-central1" | ||
}, | ||
@@ -465,3 +470,3 @@ opts | ||
models() { | ||
return ["gemini-pro", "gemini-pro-vision"]; | ||
return ["gemini-1.0-pro", "gemini-1.5-pro-preview-0409"]; | ||
} | ||
@@ -492,8 +497,7 @@ /** | ||
const token = await this.getToken(); | ||
const hasMedia = opts.messages.some( | ||
(item) => item.parts.some((part) => part.type === "image" || part.type === "video") | ||
); | ||
const model = hasMedia ? "gemini-pro-vision" : opts.model || "gemini-pro"; | ||
const hasFile = opts.messages.some((item) => item.parts.some((part) => part.type === "file")); | ||
const model = hasFile && opts.model === "gemini-1.0-pro" ? "gemini-1.0-pro-vision" : opts.model; | ||
const url = `${this.baseURL}/publishers/google/models/${model}:streamGenerateContent?alt=sse`; | ||
const params = await this.convertParams(options); | ||
console.log(`[fetch]params`, url, JSON.stringify(params, null, 2)); | ||
const res = await fetchSSE3(url, { | ||
@@ -509,3 +513,2 @@ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, | ||
} | ||
let response; | ||
const body = res.body; | ||
@@ -652,5 +655,5 @@ body.on("error", (err) => reject(new chat.ChatError(err.message, 500))); | ||
} | ||
if (["image", "video"].includes(part.type)) { | ||
if (part.type === "file") { | ||
try { | ||
const { mime_type: media_type, data } = await this.fetchFile(part.url); | ||
const { mimeType: media_type, data } = await this.fetchFile(part.url); | ||
parts.push({ type: "image", source: { type: "base64", media_type, data } }); | ||
@@ -815,5 +818,5 @@ } catch (err) { | ||
} | ||
if (["image", "video"].includes(part.type)) { | ||
if (part.type === "file") { | ||
try { | ||
const { mime_type: media_type, data } = await this.fetchFile(part.url); | ||
const { mimeType: media_type, data } = await this.fetchFile(part.url); | ||
parts.push({ type: "image", source: { type: "base64", media_type, data } }); | ||
@@ -820,0 +823,0 @@ } catch (err) { |
{ | ||
"name": "@isnolan/bodhi-adapter", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"description": "llms adapter api for bodhi", | ||
@@ -43,4 +43,5 @@ "main": "index.js", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.1", | ||
"tsup": "^8.0.1" | ||
"ts-jest": "^29.1.2", | ||
"tsup": "^8.0.1", | ||
"typescript": "~5.1.6" | ||
}, | ||
@@ -47,0 +48,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
413798
4168
11