Skip to content

Commit

Permalink
Add systemInstruction and toolConfig (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Apr 11, 2024
1 parent 0931d2c commit ccdc4f8
Show file tree
Hide file tree
Showing 26 changed files with 424 additions and 4 deletions.
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; [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) &gt; [allowedFunctionNames](./generative-ai.functioncallingconfig.allowedfunctionnames.md)

## FunctionCallingConfig.allowedFunctionNames property

**Signature:**

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

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

## FunctionCallingConfig interface


**Signature:**

```typescript
export interface FunctionCallingConfig
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [allowedFunctionNames?](./generative-ai.functioncallingconfig.allowedfunctionnames.md) | | string\[\] | _(Optional)_ |
| [mode?](./generative-ai.functioncallingconfig.mode.md) | | [FunctionCallingMode](./generative-ai.functioncallingmode.md) | _(Optional)_ |

11 changes: 11 additions & 0 deletions docs/reference/generative-ai.functioncallingconfig.mode.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; [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) &gt; [mode](./generative-ai.functioncallingconfig.mode.md)

## FunctionCallingConfig.mode property

**Signature:**

```typescript
mode?: FunctionCallingMode;
```
22 changes: 22 additions & 0 deletions docs/reference/generative-ai.functioncallingmode.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; [FunctionCallingMode](./generative-ai.functioncallingmode.md)

## FunctionCallingMode enum


**Signature:**

```typescript
export declare enum FunctionCallingMode
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| ANY | <code>&quot;ANY&quot;</code> | |
| AUTO | <code>&quot;AUTO&quot;</code> | |
| MODE\_UNSPECIFIED | <code>&quot;MODE_UNSPECIFIED&quot;</code> | |
| NONE | <code>&quot;NONE&quot;</code> | |

2 changes: 2 additions & 0 deletions docs/reference/generative-ai.generatecontentrequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export interface GenerateContentRequest extends BaseParams
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [contents](./generative-ai.generatecontentrequest.contents.md) | | [Content](./generative-ai.content.md)<!-- -->\[\] | |
| [systemInstruction?](./generative-ai.generatecontentrequest.systeminstruction.md) | | [Content](./generative-ai.content.md) | _(Optional)_ |
| [toolConfig?](./generative-ai.generatecontentrequest.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ |
| [tools?](./generative-ai.generatecontentrequest.tools.md) | | [Tool](./generative-ai.tool.md)<!-- -->\[\] | _(Optional)_ |
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; [GenerateContentRequest](./generative-ai.generatecontentrequest.md) &gt; [systemInstruction](./generative-ai.generatecontentrequest.systeminstruction.md)

## GenerateContentRequest.systemInstruction property

**Signature:**

```typescript
systemInstruction?: Content;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.generatecontentrequest.toolconfig.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; [GenerateContentRequest](./generative-ai.generatecontentrequest.md) &gt; [toolConfig](./generative-ai.generatecontentrequest.toolconfig.md)

## GenerateContentRequest.toolConfig property

**Signature:**

```typescript
toolConfig?: ToolConfig;
```
2 changes: 2 additions & 0 deletions docs/reference/generative-ai.generativemodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export declare class GenerativeModel
| [model](./generative-ai.generativemodel.model.md) | | string | |
| [requestOptions](./generative-ai.generativemodel.requestoptions.md) | | [RequestOptions](./generative-ai.requestoptions.md) | |
| [safetySettings](./generative-ai.generativemodel.safetysettings.md) | | [SafetySetting](./generative-ai.safetysetting.md)<!-- -->\[\] | |
| [systemInstruction?](./generative-ai.generativemodel.systeminstruction.md) | | [Content](./generative-ai.content.md) | _(Optional)_ |
| [toolConfig?](./generative-ai.generativemodel.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ |
| [tools?](./generative-ai.generativemodel.tools.md) | | [Tool](./generative-ai.tool.md)<!-- -->\[\] | _(Optional)_ |

## Methods
Expand Down
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.generativemodel.systeminstruction.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; [GenerativeModel](./generative-ai.generativemodel.md) &gt; [systemInstruction](./generative-ai.generativemodel.systeminstruction.md)

## GenerativeModel.systemInstruction property

**Signature:**

```typescript
systemInstruction?: Content;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.generativemodel.toolconfig.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; [GenerativeModel](./generative-ai.generativemodel.md) &gt; [toolConfig](./generative-ai.generativemodel.toolconfig.md)

## GenerativeModel.toolConfig property

**Signature:**

```typescript
toolConfig?: ToolConfig;
```
3 changes: 3 additions & 0 deletions docs/reference/generative-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| --- | --- |
| [BlockReason](./generative-ai.blockreason.md) | Reason that a prompt was blocked. |
| [FinishReason](./generative-ai.finishreason.md) | Reason that a candidate finished. |
| [FunctionCallingMode](./generative-ai.functioncallingmode.md) | |
| [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |
| [HarmBlockThreshold](./generative-ai.harmblockthreshold.md) | Threshold above which a prompt or candidate will be blocked. |
| [HarmCategory](./generative-ai.harmcategory.md) | Harm categories that would cause prompts or candidates to be blocked. |
Expand All @@ -41,6 +42,7 @@
| [EmbedContentResponse](./generative-ai.embedcontentresponse.md) | Response from calling [GenerativeModel.embedContent()](./generative-ai.generativemodel.embedcontent.md)<!-- -->. |
| [EnhancedGenerateContentResponse](./generative-ai.enhancedgeneratecontentresponse.md) | Response object wrapped with helper methods. |
| [FunctionCall](./generative-ai.functioncall.md) | 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. |
| [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) | |
| [FunctionCallPart](./generative-ai.functioncallpart.md) | Content part interface if the part represents FunctionResponse. |
| [FunctionDeclaration](./generative-ai.functiondeclaration.md) | 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. |
| [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | Schema for parameters passed to [FunctionDeclaration.parameters](./generative-ai.functiondeclaration.parameters.md)<!-- -->. |
Expand All @@ -63,6 +65,7 @@
| [SafetySetting](./generative-ai.safetysetting.md) | Safety setting that can be sent as part of request parameters. |
| [StartChatParams](./generative-ai.startchatparams.md) | Params for [GenerativeModel.startChat()](./generative-ai.generativemodel.startchat.md)<!-- -->. |
| [TextPart](./generative-ai.textpart.md) | Content part interface if the part represents a text string. |
| [ToolConfig](./generative-ai.toolconfig.md) | Tool config. This config is shared for all tools provided in the request. |

## Variables

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/generative-ai.modelparams.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export interface ModelParams extends BaseParams
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [model](./generative-ai.modelparams.model.md) | | string | |
| [systemInstruction?](./generative-ai.modelparams.systeminstruction.md) | | [Content](./generative-ai.content.md) | _(Optional)_ |
| [toolConfig?](./generative-ai.modelparams.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ |
| [tools?](./generative-ai.modelparams.tools.md) | | [Tool](./generative-ai.tool.md)<!-- -->\[\] | _(Optional)_ |
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.modelparams.systeminstruction.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; [ModelParams](./generative-ai.modelparams.md) &gt; [systemInstruction](./generative-ai.modelparams.systeminstruction.md)

## ModelParams.systemInstruction property

**Signature:**

```typescript
systemInstruction?: Content;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.modelparams.toolconfig.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; [ModelParams](./generative-ai.modelparams.md) &gt; [toolConfig](./generative-ai.modelparams.toolconfig.md)

## ModelParams.toolConfig property

**Signature:**

```typescript
toolConfig?: ToolConfig;
```
2 changes: 1 addition & 1 deletion docs/reference/generative-ai.possible_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Possible roles.
**Signature:**

```typescript
POSSIBLE_ROLES: readonly ["user", "model", "function"]
POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]
```
2 changes: 2 additions & 0 deletions docs/reference/generative-ai.startchatparams.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export interface StartChatParams extends BaseParams
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [history?](./generative-ai.startchatparams.history.md) | | [Content](./generative-ai.content.md)<!-- -->\[\] | _(Optional)_ |
| [systemInstruction?](./generative-ai.startchatparams.systeminstruction.md) | | [Content](./generative-ai.content.md) | _(Optional)_ |
| [toolConfig?](./generative-ai.startchatparams.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ |
| [tools?](./generative-ai.startchatparams.tools.md) | | [Tool](./generative-ai.tool.md)<!-- -->\[\] | _(Optional)_ |
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.startchatparams.systeminstruction.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; [StartChatParams](./generative-ai.startchatparams.md) &gt; [systemInstruction](./generative-ai.startchatparams.systeminstruction.md)

## StartChatParams.systemInstruction property

**Signature:**

```typescript
systemInstruction?: Content;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.startchatparams.toolconfig.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; [StartChatParams](./generative-ai.startchatparams.md) &gt; [toolConfig](./generative-ai.startchatparams.toolconfig.md)

## StartChatParams.toolConfig property

**Signature:**

```typescript
toolConfig?: ToolConfig;
```
11 changes: 11 additions & 0 deletions docs/reference/generative-ai.toolconfig.functioncallingconfig.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; [ToolConfig](./generative-ai.toolconfig.md) &gt; [functionCallingConfig](./generative-ai.toolconfig.functioncallingconfig.md)

## ToolConfig.functionCallingConfig property

**Signature:**

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

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

## ToolConfig interface

Tool config. This config is shared for all tools provided in the request.

**Signature:**

```typescript
export interface ToolConfig
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [functionCallingConfig](./generative-ai.toolconfig.functioncallingconfig.md) | | [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) | |

4 changes: 4 additions & 0 deletions packages/main/src/methods/chat-session-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ const VALID_PARTS_PER_ROLE: { [key in Role]: Array<keyof Part> } = {
user: ["text", "inlineData"],
function: ["functionResponse"],
model: ["text", "functionCall"],
// System instructions shouldn't be in history anyway.
system: ["text"],
};

const VALID_PREVIOUS_CONTENT_ROLES: { [key in Role]: Role[] } = {
user: ["model"],
function: ["model"],
model: ["user", "function"],
// System instructions shouldn't be in history.
system: [],
};

export function validateChatHistory(history: Content[]): void {
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/methods/chat-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export class ChatSession {
safetySettings: this.params?.safetySettings,
generationConfig: this.params?.generationConfig,
tools: this.params?.tools,
toolConfig: this.params?.toolConfig,
systemInstruction: this.params?.systemInstruction,
contents: [...this._history, newContent],
};
let finalResult;
Expand Down Expand Up @@ -135,6 +137,8 @@ export class ChatSession {
safetySettings: this.params?.safetySettings,
generationConfig: this.params?.generationConfig,
tools: this.params?.tools,
toolConfig: this.params?.toolConfig,
systemInstruction: this.params?.systemInstruction,
contents: [...this._history, newContent],
};
const streamPromise = generateContentStream(
Expand Down
Loading

0 comments on commit ccdc4f8

Please sign in to comment.