Skip to content

Commit

Permalink
Function calling (#32)
Browse files Browse the repository at this point in the history
* initial function calling

* working

* added sample

* changeset

* fixed text

* removed InputContent interface

* fixed validation

* reference for docs

* addressed comments

* copyright and docs

* fix
  • Loading branch information
alx13 authored Mar 12, 2024
1 parent 932e1be commit 9887465
Show file tree
Hide file tree
Showing 108 changed files with 2,393 additions and 517 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-knives-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": minor
---

Added support for function calling
4 changes: 2 additions & 2 deletions docs/reference/generative-ai.content.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Content type for both prompts and response candidates.
**Signature:**

```typescript
export interface Content extends InputContent
export interface Content
```
**Extends:** [InputContent](./generative-ai.inputcontent.md)

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [parts](./generative-ai.content.parts.md) | | [Part](./generative-ai.part.md)<!-- -->\[\] | |
| [role](./generative-ai.content.role.md) | | [Role](./generative-ai.role.md) | |

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [InputContent](./generative-ai.inputcontent.md) &gt; [role](./generative-ai.inputcontent.role.md)
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [Content](./generative-ai.content.md) &gt; [role](./generative-ai.content.role.md)

## InputContent.role property
## Content.role property

**Signature:**

```typescript
role: string;
role: Role;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [EnhancedGenerateContentResponse](./generative-ai.enhancedgeneratecontentresponse.md) &gt; [functionCall](./generative-ai.enhancedgeneratecontentresponse.functioncall.md)

## EnhancedGenerateContentResponse.functionCall property

**Signature:**

```typescript
functionCall: () => FunctionCall | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export interface EnhancedGenerateContentResponse extends GenerateContentResponse
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [functionCall](./generative-ai.enhancedgeneratecontentresponse.functioncall.md) | | () =&gt; [FunctionCall](./generative-ai.functioncall.md) \| undefined | |
| [text](./generative-ai.enhancedgeneratecontentresponse.text.md) | | () =&gt; string | Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. |
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncall.args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCall](./generative-ai.functioncall.md) &gt; [args](./generative-ai.functioncall.args.md)

## FunctionCall.args property

**Signature:**

```typescript
args: object;
```
21 changes: 21 additions & 0 deletions docs/reference/generative-ai.functioncall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCall](./generative-ai.functioncall.md)

## FunctionCall interface

A predicted \[FunctionCall\] returned from the model that contains a string representing the \[FunctionDeclaration.name\] and a structured JSON object containing the parameters and their values.

**Signature:**

```typescript
export interface FunctionCall
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [args](./generative-ai.functioncall.args.md) | | object | |
| [name](./generative-ai.functioncall.name.md) | | string | |

11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncall.name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCall](./generative-ai.functioncall.md) &gt; [name](./generative-ai.functioncall.name.md)

## FunctionCall.name property

**Signature:**

```typescript
name: string;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncallpart.functioncall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCallPart](./generative-ai.functioncallpart.md) &gt; [functionCall](./generative-ai.functioncallpart.functioncall.md)

## FunctionCallPart.functionCall property

**Signature:**

```typescript
functionCall: FunctionCall;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncallpart.functionresponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCallPart](./generative-ai.functioncallpart.md) &gt; [functionResponse](./generative-ai.functioncallpart.functionresponse.md)

## FunctionCallPart.functionResponse property

**Signature:**

```typescript
functionResponse?: never;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncallpart.inlinedata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCallPart](./generative-ai.functioncallpart.md) &gt; [inlineData](./generative-ai.functioncallpart.inlinedata.md)

## FunctionCallPart.inlineData property

**Signature:**

```typescript
inlineData?: never;
```
23 changes: 23 additions & 0 deletions docs/reference/generative-ai.functioncallpart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCallPart](./generative-ai.functioncallpart.md)

## FunctionCallPart interface

Content part interface if the part represents FunctionResponse.

**Signature:**

```typescript
export interface FunctionCallPart
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [functionCall](./generative-ai.functioncallpart.functioncall.md) | | [FunctionCall](./generative-ai.functioncall.md) | |
| [functionResponse?](./generative-ai.functioncallpart.functionresponse.md) | | never | _(Optional)_ |
| [inlineData?](./generative-ai.functioncallpart.inlinedata.md) | | never | _(Optional)_ |
| [text?](./generative-ai.functioncallpart.text.md) | | never | _(Optional)_ |

11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncallpart.text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionCallPart](./generative-ai.functioncallpart.md) &gt; [text](./generative-ai.functioncallpart.text.md)

## FunctionCallPart.text property

**Signature:**

```typescript
text?: never;
```
13 changes: 13 additions & 0 deletions docs/reference/generative-ai.functiondeclaration.description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclaration](./generative-ai.functiondeclaration.md) &gt; [description](./generative-ai.functiondeclaration.description.md)

## FunctionDeclaration.description property

Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.

**Signature:**

```typescript
description?: string;
```
22 changes: 22 additions & 0 deletions docs/reference/generative-ai.functiondeclaration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclaration](./generative-ai.functiondeclaration.md)

## FunctionDeclaration interface

Structured representation of a function declaration as defined by the \[OpenAPI 3.0 specification\](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client.

**Signature:**

```typescript
export declare interface FunctionDeclaration
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [description?](./generative-ai.functiondeclaration.description.md) | | string | _(Optional)_ Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function. |
| [name](./generative-ai.functiondeclaration.name.md) | | string | The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64. |
| [parameters?](./generative-ai.functiondeclaration.parameters.md) | | [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | _(Optional)_ Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. |

13 changes: 13 additions & 0 deletions docs/reference/generative-ai.functiondeclaration.name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclaration](./generative-ai.functiondeclaration.md) &gt; [name](./generative-ai.functiondeclaration.name.md)

## FunctionDeclaration.name property

The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64.

**Signature:**

```typescript
name: string;
```
30 changes: 30 additions & 0 deletions docs/reference/generative-ai.functiondeclaration.parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclaration](./generative-ai.functiondeclaration.md) &gt; [parameters](./generative-ai.functiondeclaration.parameters.md)

## FunctionDeclaration.parameters property

Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset.

**Signature:**

```typescript
parameters?: FunctionDeclarationSchema;
```

## Example

with 1 required and 1 optional parameter: type: OBJECT properties:

```
param1:
type: STRING
param2:
type: INTEGER
required:
- param1
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) &gt; [description](./generative-ai.functiondeclarationschema.description.md)

## FunctionDeclarationSchema.description property

Optional. Description of the parameter.

**Signature:**

```typescript
description?: string;
```
23 changes: 23 additions & 0 deletions docs/reference/generative-ai.functiondeclarationschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md)

## FunctionDeclarationSchema interface

Schema for parameters passed to [FunctionDeclaration.parameters](./generative-ai.functiondeclaration.parameters.md)<!-- -->.

**Signature:**

```typescript
export interface FunctionDeclarationSchema
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [description?](./generative-ai.functiondeclarationschema.description.md) | | string | _(Optional)_ Optional. Description of the parameter. |
| [properties](./generative-ai.functiondeclarationschema.properties.md) | | { \[k: string\]: [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md)<!-- -->; } | The format of the parameter. |
| [required?](./generative-ai.functiondeclarationschema.required.md) | | string\[\] | _(Optional)_ Optional. Array of required parameters. |
| [type](./generative-ai.functiondeclarationschema.type.md) | | [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | The type of the parameter. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) &gt; [properties](./generative-ai.functiondeclarationschema.properties.md)

## FunctionDeclarationSchema.properties property

The format of the parameter.

**Signature:**

```typescript
properties: {
[k: string]: FunctionDeclarationSchemaProperty;
};
```
13 changes: 13 additions & 0 deletions docs/reference/generative-ai.functiondeclarationschema.required.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) &gt; [required](./generative-ai.functiondeclarationschema.required.md)

## FunctionDeclarationSchema.required property

Optional. Array of required parameters.

**Signature:**

```typescript
required?: string[];
```
13 changes: 13 additions & 0 deletions docs/reference/generative-ai.functiondeclarationschema.type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) &gt; [type](./generative-ai.functiondeclarationschema.type.md)

## FunctionDeclarationSchema.type property

The type of the parameter.

**Signature:**

```typescript
type: FunctionDeclarationSchemaType;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) &gt; [description](./generative-ai.functiondeclarationschemaproperty.description.md)

## FunctionDeclarationSchemaProperty.description property

Optional. The description of the property.

**Signature:**

```typescript
description?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) &gt; [enum](./generative-ai.functiondeclarationschemaproperty.enum.md)

## FunctionDeclarationSchemaProperty.enum property

Optional. The enum of the property.

**Signature:**

```typescript
enum?: string[];
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) &gt; [example](./generative-ai.functiondeclarationschemaproperty.example.md)

## FunctionDeclarationSchemaProperty.example property

Optional. The example of the property.

**Signature:**

```typescript
example?: unknown;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) &gt; [format](./generative-ai.functiondeclarationschemaproperty.format.md)

## FunctionDeclarationSchemaProperty.format property

Optional. The format of the property.

**Signature:**

```typescript
format?: string;
```
Loading

0 comments on commit 9887465

Please sign in to comment.