1- import { initializeApp } from "@firebase/app" ;
2- import { Content , GenerationConfig , HarmBlockMethod , HarmBlockThreshold , HarmCategory , Modality , SafetySetting , getGenerativeModel , getVertexAI } from "../src" ;
3- import { expect } from "chai" ;
1+ import { Content , GenerationConfig , HarmBlockMethod , HarmBlockThreshold , HarmCategory , SafetySetting } from "../src" ;
42
53// TODO (dlarocque): Use seperate Firebase config specifically for Vertex AI
64// TODO (dlarocque): Load this from environment variables, so we can set the config as a
@@ -16,17 +14,17 @@ export const config = {
1614 measurementId : "G-1VL38N8YFE"
1715} ;
1816
19- initializeApp ( config ) ;
20- const MODEL_NAME = 'gemini-1.5-pro' ;
17+ export const MODEL_NAME = 'gemini-1.5-pro' ;
2118
22- let generationConfig : GenerationConfig = {
19+ /// TODO (dlarocque): Fix the naming on these.
20+ export const generationConfig : GenerationConfig = {
2321 temperature : 0 ,
2422 topP : 0 ,
2523 topK : 1 ,
2624 responseMimeType : 'text/plain'
2725}
2826
29- let safetySettings : SafetySetting [ ] = [
27+ export const safetySettings : SafetySetting [ ] = [
3028 {
3129 category : HarmCategory . HARM_CATEGORY_HARASSMENT ,
3230 threshold : HarmBlockThreshold . BLOCK_LOW_AND_ABOVE ,
@@ -47,35 +45,11 @@ let safetySettings: SafetySetting[] = [
4745 } ,
4846] ;
4947
50- let systemInstruction : Content = {
48+ export const systemInstruction : Content = {
5149 role : 'system' ,
5250 parts : [
5351 {
5452 text : 'You are a friendly and helpful assistant.'
5553 }
5654 ]
57- } ;
58-
59- describe ( 'VertexAIService' , ( ) => {
60- it ( 'CountTokens text' , async ( ) => {
61- const vertexAI = getVertexAI ( ) ;
62- const model = getGenerativeModel (
63- vertexAI ,
64- {
65- model : MODEL_NAME ,
66- generationConfig,
67- systemInstruction,
68- safetySettings
69- }
70- ) ;
71-
72- let response = await model . countTokens ( 'Why is the sky blue?' ) ;
73-
74- expect ( response . totalTokens ) . to . equal ( 6 ) ;
75- expect ( response . totalBillableCharacters ) . to . equal ( 16 ) ;
76- expect ( response . promptTokensDetails ) . to . not . be . null ;
77- expect ( response . promptTokensDetails ! . length ) . to . equal ( 1 ) ;
78- expect ( response . promptTokensDetails ! [ 0 ] . modality ) . to . equal ( Modality . TEXT ) ;
79- expect ( response . promptTokensDetails ! [ 0 ] . tokenCount ) . to . equal ( 6 ) ;
80- } ) ;
81- } ) ;
55+ } ;
0 commit comments