@firebase/ai 2.8.0 → 2.9.0-canary.78384d32c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Content, GenerateContentResult, GenerateContentStreamResult, Part, RequestOptions, SingleRequestOptions, StartChatParams } from '../types';
17
+ import { Content, FunctionCall, FunctionResponsePart, GenerateContentRequest, GenerateContentResponse, GenerateContentResult, GenerateContentStreamResult, Part, RequestOptions, SingleRequestOptions, StartChatParams } from '../types';
18
18
  import { ApiSettings } from '../types/internal';
19
19
  import { ChromeAdapter } from '../types/chrome-adapter';
20
20
  /**
@@ -42,6 +42,12 @@ export declare class ChatSession {
42
42
  * to history.
43
43
  */
44
44
  getHistory(): Promise<Content[]>;
45
+ /**
46
+ * Format Content into a request for generateContent or
47
+ * generateContentStream.
48
+ * @internal
49
+ */
50
+ _formatRequest(incomingContent: Content, tempHistory: Content[]): GenerateContentRequest;
45
51
  /**
46
52
  * Sends a chat message and receives a non-streaming
47
53
  * {@link GenerateContentResult}
@@ -53,4 +59,19 @@ export declare class ChatSession {
53
59
  * and a response promise.
54
60
  */
55
61
  sendMessageStream(request: string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
62
+ /**
63
+ * Get function calls that the SDK has references to actually call.
64
+ * This is all-or-nothing. If the model is requesting multiple
65
+ * function calls, all of them must have references in order for
66
+ * automatic function calling to work.
67
+ *
68
+ * @internal
69
+ */
70
+ _getCallableFunctionCalls(response?: GenerateContentResponse): FunctionCall[] | undefined;
71
+ /**
72
+ * Call user-defined functions if requested by the model, and return
73
+ * the response that should be sent to the model.
74
+ * @internal
75
+ */
76
+ _callFunctionsAsNeeded(functionCalls: FunctionCall[]): Promise<FunctionResponsePart[]>;
56
77
  }
@@ -14,10 +14,12 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { GenerateContentRequest, GenerateContentResult, GenerateContentStreamResult, SingleRequestOptions } from '../types';
17
+ import { GenerateContentRequest, GenerateContentResponse, GenerateContentResult, GenerateContentStreamResult, SingleRequestOptions } from '../types';
18
18
  import { ApiSettings } from '../types/internal';
19
19
  import { ChromeAdapter } from '../types/chrome-adapter';
20
- export declare function generateContentStream(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, chromeAdapter?: ChromeAdapter, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
20
+ export declare function generateContentStream(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, chromeAdapter?: ChromeAdapter, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult & {
21
+ firstValue?: GenerateContentResponse;
22
+ }>;
21
23
  export declare function templateGenerateContent(apiSettings: ApiSettings, templateId: string, templateParams: object, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
22
24
  export declare function templateGenerateContentStream(apiSettings: ApiSettings, templateId: string, templateParams: object, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
23
25
  export declare function generateContent(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, chromeAdapter?: ChromeAdapter, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
@@ -36,7 +36,7 @@ export declare function getText(response: GenerateContentResponse, partFilter: (
36
36
  /**
37
37
  * Returns every {@link FunctionCall} associated with first candidate.
38
38
  */
39
- export declare function getFunctionCalls(response: GenerateContentResponse): FunctionCall[] | undefined;
39
+ export declare function getFunctionCalls(response?: GenerateContentResponse): FunctionCall[] | undefined;
40
40
  /**
41
41
  * Returns every {@link InlineDataPart} in the first candidate if present.
42
42
  *
@@ -25,7 +25,9 @@ import { InferenceSource } from '../public-types';
25
25
  *
26
26
  * @param response - Response from a fetch call
27
27
  */
28
- export declare function processStream(response: Response, apiSettings: ApiSettings, inferenceSource?: InferenceSource): GenerateContentStreamResult;
28
+ export declare function processStream(response: Response, apiSettings: ApiSettings, inferenceSource?: InferenceSource): Promise<GenerateContentStreamResult & {
29
+ firstValue?: GenerateContentResponse;
30
+ }>;
29
31
  /**
30
32
  * Reads a raw string stream, buffers incomplete chunks, and yields parsed JSON objects.
31
33
  */
@@ -243,6 +243,7 @@ export interface FunctionResponse {
243
243
  id?: string;
244
244
  name: string;
245
245
  response: object;
246
+ parts?: Part[];
246
247
  }
247
248
  /**
248
249
  * Interface for sending an image.
@@ -231,6 +231,15 @@ export interface RequestOptions {
231
231
  * (used regardless of your chosen Gemini API provider).
232
232
  */
233
233
  baseUrl?: string;
234
+ /**
235
+ * Limits amount of sequential function calls the SDK can make during automatic
236
+ * function calling, in order to prevent infinite loops. If not specified,
237
+ * this value defaults to 10.
238
+ *
239
+ * When it reaches this limit, it will return the last response received
240
+ * from the model, whether it is a text response or further function calls.
241
+ */
242
+ maxSequentalFunctionCalls?: number;
234
243
  }
235
244
  /**
236
245
  * Options that can be provided per-request.
@@ -304,6 +313,11 @@ export interface FunctionDeclaration {
304
313
  * case-sensitive. For a function with no parameters, this can be left unset.
305
314
  */
306
315
  parameters?: ObjectSchema | ObjectSchemaRequest;
316
+ /**
317
+ * Reference to an actual function to call. Specifying this will cause the
318
+ * function to be called automatically when requested by the model.
319
+ */
320
+ functionReference?: Function;
307
321
  }
308
322
  /**
309
323
  * A tool that allows a Gemini model to connect to Google Search to access and incorporate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/ai",
3
- "version": "2.8.0",
3
+ "version": "2.9.0-canary.78384d32c",
4
4
  "description": "The Firebase AI SDK",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "engines": {
@@ -48,19 +48,19 @@
48
48
  "trusted-type-check": "tsec -p tsconfig.json --noEmit"
49
49
  },
50
50
  "peerDependencies": {
51
- "@firebase/app": "0.x",
52
- "@firebase/app-types": "0.x"
51
+ "@firebase/app": "0.14.9-canary.78384d32c",
52
+ "@firebase/app-types": "0.9.3-canary.78384d32c"
53
53
  },
54
54
  "dependencies": {
55
- "@firebase/app-check-interop-types": "0.3.3",
56
- "@firebase/component": "0.7.0",
57
- "@firebase/logger": "0.5.0",
58
- "@firebase/util": "1.13.0",
55
+ "@firebase/app-check-interop-types": "0.3.3-canary.78384d32c",
56
+ "@firebase/component": "0.7.1-canary.78384d32c",
57
+ "@firebase/logger": "0.5.0-canary.78384d32c",
58
+ "@firebase/util": "1.14.0-canary.78384d32c",
59
59
  "tslib": "^2.1.0"
60
60
  },
61
61
  "license": "Apache-2.0",
62
62
  "devDependencies": {
63
- "@firebase/app": "0.14.8",
63
+ "@firebase/app": "0.14.9-canary.78384d32c",
64
64
  "@rollup/plugin-json": "6.1.0",
65
65
  "rollup": "2.79.2",
66
66
  "rollup-plugin-replace": "2.2.0",