Skip to content

Commit 5aac66c

Browse files
committed
fix: add types and checks for builds
1 parent c9fe94d commit 5aac66c

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

src/providers/anthropic-base/messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProviderConfig } from '../types';
1+
import { ParameterConfig, ProviderConfig } from '../types';
22

33
export const messagesBaseConfig: ProviderConfig = {
44
model: {
@@ -82,7 +82,7 @@ export const getMessagesConfig = ({
8282
if (defaultValues) {
8383
Object.keys(defaultValues).forEach((key) => {
8484
if (!Array.isArray(baseParams[key])) {
85-
baseParams[key].default = defaultValues[key];
85+
(baseParams[key] as ParameterConfig).default = defaultValues[key];
8686
}
8787
});
8888
}

src/providers/cohere/chatComplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ export const CohereChatCompleteStreamChunkTransform: (
291291
index: streamState.lastIndex,
292292
delta: {
293293
role: 'assistant',
294-
content: parsedChunk.delta?.message?.content?.text ?? '',
295-
tool_calls: parsedChunk.delta?.message?.tool_calls,
294+
content: (parsedChunk as any).delta?.message?.content?.text ?? '',
295+
tool_calls: (parsedChunk as any).delta?.message?.tool_calls,
296296
},
297297
logprobs: null,
298298
finish_reason: null,

src/providers/google-vertex-ai/chatComplete.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../anthropic/types';
2222
import {
2323
GoogleMessage,
24+
GoogleMessagePart,
2425
GoogleMessageRole,
2526
GoogleToolConfig,
2627
SYSTEM_INSTRUCTION_DISABLED_MODELS,
@@ -82,7 +83,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
8283
return;
8384

8485
const role = transformOpenAIRoleToGoogleRole(message.role);
85-
let parts = [];
86+
let parts: GoogleMessagePart[] = [];
8687

8788
if (message.role === 'assistant' && message.tool_calls) {
8889
message.tool_calls.forEach((tool_call: ToolCall) => {
@@ -106,7 +107,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
106107
message.content.forEach((c: ContentType) => {
107108
if (c.type === 'text') {
108109
parts.push({
109-
text: c.text,
110+
text: c.text ?? '',
110111
});
111112
} else if (c.type === 'input_audio') {
112113
parts.push(transformInputAudioPart(c));
@@ -149,7 +150,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
149150
parts.push({
150151
inlineData: {
151152
mimeType: 'image/jpeg',
152-
data: c.image_url?.url,
153+
data: c.image_url?.url ?? '',
153154
},
154155
});
155156
}

src/providers/google-vertex-ai/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ErrorResponse, FinetuneRequest, Logprobs } from '../types';
1515
import { Context } from 'hono';
1616
import { env } from 'hono/adapter';
1717
import { ContentType, JsonSchema, Tool } from '../../types/requestBody';
18+
import { GoogleMessagePart } from '../google/chatComplete';
1819

1920
/**
2021
* Encodes an object as a Base64 URL-encoded string.
@@ -717,15 +718,15 @@ export const OPENAI_AUDIO_FORMAT_TO_VERTEX_MIME_TYPE_MAPPING = {
717718
wav: 'audio/wav',
718719
};
719720

720-
export const transformInputAudioPart = (c: ContentType) => {
721+
export const transformInputAudioPart = (c: ContentType): GoogleMessagePart => {
721722
const data = c.input_audio?.data;
722723
const mimeType =
723724
OPENAI_AUDIO_FORMAT_TO_VERTEX_MIME_TYPE_MAPPING[
724725
c.input_audio?.format as 'mp3' | 'wav'
725726
];
726727
return {
727728
inlineData: {
728-
data,
729+
data: data ?? '',
729730
mimeType,
730731
},
731732
};

src/providers/google/chatComplete.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,26 @@ interface GoogleFunctionResponseMessagePart {
115115
};
116116
}
117117

118-
type GoogleMessagePart =
118+
export type GoogleMessagePart =
119119
| GoogleFunctionCallMessagePart
120120
| GoogleFunctionResponseMessagePart
121+
| GoogleInlineDataMessagePart
122+
| GoogleFileDataMessagePart
121123
| { text: string };
122124

125+
export interface GoogleInlineDataMessagePart {
126+
inlineData: {
127+
mimeType?: string;
128+
data: string;
129+
};
130+
}
131+
132+
export interface GoogleFileDataMessagePart {
133+
fileData: {
134+
mimeType?: string;
135+
fileUri: string;
136+
};
137+
}
123138
export interface GoogleMessage {
124139
role: GoogleMessageRole;
125140
parts: GoogleMessagePart[];

0 commit comments

Comments
 (0)