Skip to content

Commit 2817351

Browse files
committed
add support for messages route in vertex anthropic as well
1 parent 038082a commit 2817351

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ export const GoogleApiConfig: ProviderAPIConfig = {
170170
}
171171

172172
case 'anthropic': {
173-
if (mappedFn === 'chatComplete') {
173+
if (mappedFn === 'chatComplete' || mappedFn === 'messages') {
174174
return `${projectRoute}/publishers/${provider}/models/${model}:rawPredict`;
175-
} else if (mappedFn === 'stream-chatComplete') {
175+
} else if (
176+
mappedFn === 'stream-chatComplete' ||
177+
mappedFn === 'stream-messages'
178+
) {
176179
return `${projectRoute}/publishers/${provider}/models/${model}:streamRawPredict`;
177180
}
178181
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import {
4747
import { GoogleFinetuneRetrieveResponseTransform } from './retrieveFinetune';
4848
import { GoogleFinetuneListResponseTransform } from './listFinetunes';
4949
import { GoogleListFilesRequestHandler } from './listFiles';
50+
import {
51+
VertexAnthropicMessagesConfig,
52+
VertexAnthropicMessagesResponseTransform,
53+
} from './messages';
5054

5155
const VertexConfig: ProviderConfigs = {
5256
api: VertexApiConfig,
@@ -112,10 +116,12 @@ const VertexConfig: ProviderConfigs = {
112116
api: GoogleApiConfig,
113117
createBatch: GoogleBatchCreateConfig,
114118
createFinetune: baseConfig.createFinetune,
119+
messages: VertexAnthropicMessagesConfig,
115120
responseTransforms: {
116121
'stream-chatComplete':
117122
VertexAnthropicChatCompleteStreamChunkTransform,
118123
chatComplete: VertexAnthropicChatCompleteResponseTransform,
124+
messages: VertexAnthropicMessagesResponseTransform,
119125
...responseTransforms,
120126
},
121127
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { GOOGLE_VERTEX_AI } from '../../globals';
2+
import { MessagesResponse } from '../../types/messagesResponse';
3+
import { getMessagesConfig } from '../anthropic-base/messages';
4+
import { AnthropicErrorResponse } from '../anthropic/types';
5+
import { AnthropicErrorResponseTransform } from '../anthropic/utils';
6+
import { ErrorResponse } from '../types';
7+
import { generateInvalidProviderResponseError } from '../utils';
8+
9+
export const VertexAnthropicMessagesConfig = getMessagesConfig({});
10+
11+
export const VertexAnthropicMessagesResponseTransform = (
12+
response: MessagesResponse | AnthropicErrorResponse,
13+
responseStatus: number
14+
): MessagesResponse | ErrorResponse => {
15+
if (responseStatus !== 200) {
16+
const errorResposne = AnthropicErrorResponseTransform(
17+
response as AnthropicErrorResponse
18+
);
19+
if (errorResposne) return errorResposne;
20+
}
21+
22+
if ('model' in response) return response;
23+
24+
return generateInvalidProviderResponseError(response, GOOGLE_VERTEX_AI);
25+
};

src/providers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type endpointStrings =
8080
| 'moderate'
8181
| 'stream-complete'
8282
| 'stream-chatComplete'
83+
| 'stream-messages'
8384
| 'proxy'
8485
| 'imageGenerate'
8586
| 'createSpeech'

0 commit comments

Comments
 (0)