This repository was archived by the owner on Mar 19, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
packages/openai-compatible/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { BaseMessage } from 'cortexluna'
1+ import { BaseMessage , dataContentToBase64 } from 'cortexluna'
22
33export function convertToOpenAICompatibleChatMessages (
44 prompt : BaseMessage [ ]
@@ -62,7 +62,7 @@ export function convertToOpenAICompatibleChatMessages(
6262 : `data:${
6363 part . mineType ??
6464 'image/jpeg'
65- } ;base64,${ convertUint8ArrayToBase64 ( imageUrl ) } `
65+ } ;base64,${ dataContentToBase64 ( imageUrl ) } `
6666 }
6767 }
6868 }
@@ -196,13 +196,3 @@ export interface OpenAICompatibleToolMessage {
196196 content : string
197197 tool_call_id : string
198198}
199- function convertUint8ArrayToBase64 (
200- image :
201- | string
202- | ArrayBuffer
203- | Uint8Array < ArrayBuffer >
204- | Buffer < ArrayBuffer >
205- | URL
206- ) {
207- throw new Error ( 'Function not implemented.' )
208- }
Original file line number Diff line number Diff line change @@ -134,7 +134,9 @@ export class OpenAICompatibleLanguageModel implements LanguageModel {
134134 OpenAICompatibleChatResponseSchema . safeParse ( responseJSON )
135135
136136 if ( ! parsedResponse . success ) {
137- throw new Error ( `Invalid response from API: ${ responseBody } ` )
137+ throw new Error (
138+ `Invalid response from API: ${ responseBody } ${ parsedResponse . error } `
139+ )
138140 }
139141
140142 return parsedResponse . data
@@ -496,11 +498,11 @@ const OpenAICompatibleChatResponseSchema = z.object({
496498 ) ,
497499 usage : z
498500 . object ( {
499- prompt_tokens : z . number ( ) ,
500- completion_tokens : z . number ( ) ,
501+ prompt_tokens : z . number ( ) . nullish ( ) ,
502+ completion_tokens : z . number ( ) . nullish ( ) ,
501503 prompt_tokens_details : z
502504 . object ( {
503- cached_tokens : z . number ( )
505+ cached_tokens : z . number ( ) . nullish ( )
504506 } )
505507 . nullish ( )
506508 } )
You can’t perform that action at this time.
0 commit comments