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

Method ask

firebase-ai-logic-angular-example/src/app/ai.service.ts:84–137  ·  view source on GitHub ↗
(prompt: string)

Source from the content-addressed store, hash-verified

82 }
83
84 async ask(prompt: string) {
85 let result = await this.chat.sendMessage(prompt);
86 const functionCalls = result.response.functionCalls();
87
88 if (functionCalls && functionCalls.length > 0) {
89 for (const functionCall of functionCalls) {
90 switch (functionCall.name) {
91 case "getNumberOfProducts": {
92 const functionResult = this.getNumberOfProducts();
93 result = await this.chat.sendMessage([
94 {
95 functionResponse: {
96 name: functionCall.name,
97 response: { numberOfItems: functionResult },
98 },
99 },
100 ]);
101 break;
102 }
103 case "getProducts": {
104 const functionResult = this.getProducts();
105 result = await this.chat.sendMessage([
106 {
107 functionResponse: {
108 name: functionCall.name,
109 response: { products: functionResult },
110 },
111 },
112 ]);
113 break;
114 }
115 case "addToCart": {
116 console.log(functionCall.args);
117
118 const args = functionCall.args as { productsToAdd: Product[]}
119
120 const functionResult = this.addToCart(args.productsToAdd);
121
122 result = await this.chat.sendMessage([
123 {
124 functionResponse: {
125 name: functionCall.name,
126 response: { numberOfProductsAdded: functionResult },
127 },
128 }
129 ]);
130 break;
131 }
132 }
133 }
134 }
135
136 return result.response.text();
137 }
138
139 getProducts() {
140 return this.products.getProducts();

Callers 1

submitMessageMethod · 0.80

Calls 4

getNumberOfProductsMethod · 0.95
getProductsMethod · 0.95
addToCartMethod · 0.95
sendMessageMethod · 0.80

Tested by

no test coverage detected