Skip to content

Commit a1d1361

Browse files
russellwheatleymikehardydlarocquehsubox76tanzimfh
authored
feat: vertexAI package support (#8236)
* init * update README * .npmignore * license * initial port over of vertexAI from firebase-js-sdk * react-native-builder-bob * package.json updates * fix: format & fix TS type warnings * chore: format stream-reader file * initial attempt at polyfilling stream * fix: polyfill stream for react native * chore: remove verbatimModuleSyntax * chore: use module dist and update version for TS * chore: check in version.ts * get version from version.ts * fix: RN specific stream * feat: allow auth and app check to be passed in * test: write first test file * test: chat session * initial count token * test utils * ignore vertex test data * convert mocks * test: grab vertex mock responses * setup jest for vertex * fix vertex script * test: fix count token to use jest * yarn.lock * revert jest config * test: port over generate content test * test: fix generate content * format mock response * port over generative model test * test: generative model * port over request helpers tests * test: request helpers using jest * port over request tests * test: request tests * test: request tests * port over response helpers * test: response headers * port over schema builder * test: scheme builder * test: stream reader * port over api tests * test: update chat session helper * rm dead code * test: api tests * test: service test * chore: move vertex mock script to scripts/ * chore: update license headers * chore: make note on API versions * fix: pin `web-streams-polyfill` dependency * chore: remove version.ts from git * fix: mock-response types * chore: update genversion script * chore: move logger to app * fix: wire up `onLog()` & `setLogLevel()` for VertexAI * chore: rm unneeded TS declaration * chore: remove FirebaseService class * chore: update yarn.lock * test: make vertex response scripts only checkout repo if not existing * chore: move script call into vertex prepare * chore: move to start * fix: Logger internals, make it private * fix: try ignoring TS build issue * test: remove e2e test for onLog and add unit test * chore: remove onLog e2e test * chore: eslint update * chore: fix lint issues * fix: fetch API issue with global polyfill. not needed * fix: stream now global polyfill has been removed * chore: update yarn.lock * docs: vertexAI documentation * docs: vertexAI improvement * chore: format docs * chore: update spellcheck * chore: bump web-streams-polyfill version * chore: update yarn.lock * test: rm unused files * chore: update types to use RNFB * test: add vertexAI to test runner * chore: vertexAI e2e emulator functions * test: export vertex functions for testing * test: e2e test fetch/stream responses * test: reduce stream latency * test: setup test environment * test: add env var for test setup * chore: update app check and auth types * chore: update type comments * docs(vertexai): getting ready for production * chore: update script to rm dist/ * chore: make explicit that it is a type * fix: TS build issue on CI * test: fix jest tests * test: use different tsconfig for jest. the use of RNFB app module caused issues for compile/jest * docs: fix sidebar hyperlink * test: fix android e2e, point to correct host * chore: use correct types for auth and app check * chore: update initialization of vertexai * chore: updates stringToEnum object * fix: do not ship unit tests with released package * test: avoid typing error on stream types with temporary ignore * test: avoid logging test console messages we expect keeps the logs clean * test: fixups to avoid deprecation warnings and handle type errors from same * chore: update language tag * chore: switch to using `globalThis` * test(vertexai): alter test to expect new gl-rn header * chore: update license headers in src/ * chore: update license headers in tests/ * chore: update yarn.lock * chore: clean up code annotation and unused block of code * fix: filter empty text parts when streaming * chore: add missing enum types * chore: update license header * chore: update yarn.lock --------- Co-authored-by: Mike Hardy <[email protected]> Co-authored-by: Daniel La Rocque <[email protected]> Co-authored-by: hsubox76 <[email protected]> Co-authored-by: Tanzim Hossain <[email protected]> Co-authored-by: Josh Soref <[email protected]> Co-authored-by: DellaBitta <[email protected]>
1 parent 8f59579 commit a1d1361

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+7484
-78
lines changed

.github/workflows/scripts/functions/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ export { testFunctionDefaultRegionV2 } from './testFunctionDefaultRegion';
2424
export { testFunctionRemoteConfigUpdateV2 } from './testFunctionRemoteConfigUpdate';
2525
export { fetchAppCheckTokenV2 } from './fetchAppCheckToken';
2626
export { sendFCM } from './sendFCM';
27+
28+
export { testFetchStream, testFetch } from './vertexaiFunctions';
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as functions from 'firebase-functions/v2';
2+
3+
const poem = [
4+
'The wind whispers secrets through the trees,',
5+
'Rustling leaves in a gentle breeze.',
6+
'Sunlight dances on the grass,',
7+
'A fleeting moment, sure to pass.',
8+
'Birdsong fills the air so bright,',
9+
'A symphony of pure delight.',
10+
'Time stands still, a peaceful pause,',
11+
"In nature's beauty, no flaws.",
12+
];
13+
14+
const response = {
15+
candidates: [
16+
{
17+
content: {
18+
parts: [
19+
{
20+
text: 'Google\'s mission is to "organize the world\'s information and make it universally accessible and useful."',
21+
},
22+
],
23+
role: 'model',
24+
},
25+
finishReason: 'STOP',
26+
index: 0,
27+
safetyRatings: [
28+
{ category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', probability: 'NEGLIGIBLE' },
29+
{ category: 'HARM_CATEGORY_HATE_SPEECH', probability: 'NEGLIGIBLE' },
30+
{ category: 'HARM_CATEGORY_HARASSMENT', probability: 'NEGLIGIBLE' },
31+
{ category: 'HARM_CATEGORY_DANGEROUS_CONTENT', probability: 'NEGLIGIBLE' },
32+
],
33+
},
34+
],
35+
promptFeedback: {
36+
safetyRatings: [
37+
{ category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', probability: 'NEGLIGIBLE' },
38+
{ category: 'HARM_CATEGORY_HATE_SPEECH', probability: 'NEGLIGIBLE' },
39+
{ category: 'HARM_CATEGORY_HARASSMENT', probability: 'NEGLIGIBLE' },
40+
{ category: 'HARM_CATEGORY_DANGEROUS_CONTENT', probability: 'NEGLIGIBLE' },
41+
],
42+
},
43+
};
44+
45+
export const testFetchStream = functions.https.onRequest(async (req, res) => {
46+
res.setHeader('Content-Type', 'text/event-stream');
47+
res.setHeader('Cache-Control', 'no-cache');
48+
res.setHeader('Connection', 'keep-alive');
49+
50+
const updatedResponse = { ...response };
51+
52+
for (let i = 0; i < poem.length; i++) {
53+
updatedResponse.candidates[0].content.parts[0].text = poem[i];
54+
res.write(`data: ${JSON.stringify(updatedResponse)}\n\n`);
55+
await new Promise(resolve => setTimeout(resolve, 100));
56+
}
57+
res.end();
58+
});
59+
60+
export const testFetch = functions.https.onRequest(async (req, res) => {
61+
res.json(response);
62+
});

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ Pods/*
536536
**/Pods/**
537537
**/dist/
538538
packages/**/version.js
539+
packages/**/version.ts
539540
typedoc.raw.json
540541
tests/ios/Firebase
541542
tests/ios/resetXcode.sh
@@ -580,3 +581,7 @@ website/public
580581

581582
# Typescript items
582583
*.tsbuildinfo
584+
585+
# vertexai test data
586+
vertexai-sdk-test-data
587+
mocks-lookup.ts

.spellcheck.dict.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ FirebaseApp
7777
FirebaseCore
7878
firestore
7979
Firestore
80+
freeform
8081
GDPR
8182
GDPR-compliant
8283
getIdToken
@@ -187,6 +188,7 @@ signInTester
187188
Siri
188189
SMS
189190
SNS
191+
SPII
190192
src
191193
SSV
192194
stacktrace
@@ -219,6 +221,7 @@ v7
219221
v9
220222
v22
221223
Ventura
224+
VertexAI
222225
VPN
223226
VSCode
224227
Wix

docs/sidebar.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
- - KY Integration
130130
- '/perf/ky-integration'
131131
- '//static.invertase.io/assets/firebase/performance-monitoring.svg'
132+
- - VertexAi
133+
- - - Usage
134+
- '/vertexai/usage'
135+
- '//static.invertase.io/assets/social/firebase-logo.png'
132136
- - Legacy docs
133137
- - - Migrating to v6
134138
- '/migrating-to-v6'

0 commit comments

Comments
 (0)