MCPcopy Create free account
hub / github.com/angular/examples / AiService

Class AiService

firebase-ai-logic-angular-example/src/app/ai.service.ts:25–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 providedIn: "root",
24})
25export class AiService {
26 private readonly model: GenerativeModel;
27 private readonly products: ProductService = inject(ProductService);
28 private readonly chat: ChatSession;
29
30 constructor(@Inject("FIREBASE_APP") private firebaseApp: FirebaseApp) {
31 const productsToolSet: FunctionDeclarationsTool = {
32 functionDeclarations: [
33 {
34 name: "getNumberOfProducts",
35 description:
36 "Get a count of the number of products available in the inventory.",
37 },
38 {
39 name: "getProducts",
40 description:
41 "Get an array of the products with the name and price of each product.",
42 },
43 {
44 name: "addToCart",
45 description: "Add one or more products to the cart.",
46 parameters: Schema.object({
47 properties: {
48 productsToAdd: Schema.array({
49 items: Schema.object({
50 description: "A single product with its name and price.",
51 properties: {
52 name: Schema.string({
53 description: "The name of the product.",
54 }),
55 price: Schema.number({
56 description: "The numerical price of the product.",
57 }),
58 },
59 // Specify which properties within each product object are required
60 required: ["name", "price"],
61 }),
62 }),
63 },
64 }) as ObjectSchemaInterface,
65 },
66 ],
67 };
68
69 // Initialize the Vertex AI service
70 const vertexAI = getVertexAI(this.firebaseApp);
71 const systemInstruction =
72 "Welcome to ng-produce. You are a superstar agent for this ecommerce store. you will assist users by answering questions about the inventory and event being able to add items to the cart.";
73
74 // Initialize the generative model with a model that supports your use case
75 this.model = getGenerativeModel(vertexAI, {
76 model: "gemini-2.0-flash",
77 systemInstruction: systemInstruction,
78 tools: [productsToolSet],
79 });
80
81 this.chat = this.model.startChat();
82 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected