Skip to content

Commit d3d06ab

Browse files
refactor(vertexai): initial setup to use ai package
1 parent 5cfdb3c commit d3d06ab

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

packages/ai/lib/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ import { GenerativeModel } from './models/generative-model';
2525
export { ChatSession } from './methods/chat-session';
2626
export * from './requests/schema-builder';
2727

28-
export { GenerativeModel };
29-
30-
export { AIError };
28+
export {
29+
GenerativeModel,
30+
AIError,
31+
AIErrorCode,
32+
ModelParams,
33+
RequestOptions,
34+
GoogleAIBackend,
35+
VertexAIBackend,
36+
};
3137

3238
/**
3339
* Returns the default {@link AI} instance that is associated with the provided

packages/vertexai/lib/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@
1717

1818
import './polyfills';
1919
import { getApp, ReactNativeFirebase } from '@react-native-firebase/app';
20-
import { ModelParams, RequestOptions, VertexAIErrorCode } from './types';
20+
import {
21+
getGenerativeModel as getGenerativeModelFromAI,
22+
getAI,
23+
VertexAIBackend,
24+
GenerativeModel,
25+
RequestOptions,
26+
ModelParams,
27+
} from '@react-native-firebase/ai';
28+
import { VertexAIErrorCode } from './types';
2129
import { DEFAULT_LOCATION } from './constants';
2230
import { VertexAI, VertexAIOptions } from './public-types';
2331
import { VertexAIError } from './errors';
24-
import { GenerativeModel } from './models/generative-model';
2532
import { VertexAIService } from './service';
2633
export { ChatSession } from './methods/chat-session';
2734
export * from './requests/schema-builder';
2835

29-
export { GenerativeModel };
30-
3136
export { VertexAIError };
3237

3338
/**
@@ -69,5 +74,10 @@ export function getGenerativeModel(
6974
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`,
7075
);
7176
}
72-
return new GenerativeModel(vertexAI, modelParams, requestOptions);
77+
78+
const ai = getAI(vertexAI.app, {
79+
backend: new VertexAIBackend(vertexAI.location),
80+
});
81+
82+
return getGenerativeModelFromAI(ai, modelParams, requestOptions);
7383
}

packages/vertexai/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"compilerOptions": {
3-
"rootDir": ".",
43
"allowUnreachableCode": false,
54
"allowUnusedLabels": false,
65
"esModuleInterop": true,
@@ -27,6 +26,8 @@
2726
"@react-native-firebase/app": ["../app/lib"],
2827
"@react-native-firebase/auth": ["../auth/lib"],
2928
"@react-native-firebase/app-check": ["../app-check/lib"],
29+
"@react-native-firebase/ai": ["../ai/lib"],
3030
}
31-
}
31+
},
32+
"include": ["lib/**/*", "../ai/lib/**/*"]
3233
}

tsconfig-jest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@react-native-firebase/app": ["packages/app/lib"],
77
"@react-native-firebase/auth": ["packages/auth/lib"],
88
"@react-native-firebase/app-check": ["packages/app-check/lib"],
9+
"@react-native-firebase/ai": ["packages/ai/lib"],
910
}
1011
}
1112
}

0 commit comments

Comments
 (0)