Skip to content

Commit fcdeef4

Browse files
speedstorm1copybara-github
authored andcommitted
feat: allow users to configure max wait time for prompt management queries
PiperOrigin-RevId: 944229591
1 parent 0697f79 commit fcdeef4

8 files changed

Lines changed: 2530 additions & 20 deletions

File tree

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,82 @@ const client: Client = new Client({
4848
});
4949
```
5050
51+
## Prompts
52+
53+
First define your prompt as a JS object or `Prompt` object. Then call `createVersion`.
54+
55+
```typescript
56+
const prompt = {
57+
promptData: {
58+
contents: [{ parts: [{ text: 'Hello, {name}! How are you?' }] }],
59+
systemInstruction: { parts: [{ text: 'Please answer in a short sentence.' }] },
60+
variables: [
61+
{ name: { text: 'Alice' } },
62+
],
63+
model: 'gemini-2.5-flash',
64+
},
65+
};
66+
67+
const promptResource = await client.prompts.createVersion({
68+
prompt: prompt,
69+
});
70+
```
71+
72+
Note that you can also use typed objects to define your prompt. Some of the types used to do this (`Content`, `Part`) are from the Gen AI SDK (`@google/genai`).
73+
74+
```typescript
75+
import { Prompt } from '@google-cloud/agentplatform';
76+
import { Part, Content } from '@google/genai';
77+
78+
const prompt: Prompt = {
79+
promptData: {
80+
contents: [{ parts: [{ text: 'Hello, {name}! How are you?' } as Part] } as Content],
81+
systemInstruction: { parts: [{ text: 'Please answer in a short sentence.' } as Part] } as Content,
82+
variables: [
83+
{ name: { text: 'Alice' } as Part },
84+
],
85+
model: 'gemini-2.5-flash',
86+
},
87+
};
88+
89+
const promptResource = await client.prompts.createVersion({
90+
prompt: prompt,
91+
});
92+
```
93+
94+
Retrieve a prompt by calling `get()` with the `promptId`.
95+
96+
```typescript
97+
const dataset = (promptResource as any)._dataset;
98+
const promptId = dataset?.name?.split('/').pop() || 'YOUR_PROMPT_ID';
99+
100+
const retrievedPrompt = await client.prompts.get({
101+
promptId: promptId,
102+
});
103+
```
104+
105+
After creating or retrieving a prompt, you can call `models.generateContent()` with that prompt using the Gen AI SDK (`@google/genai`).
106+
107+
```typescript
108+
import { GoogleGenAI } from '@google/genai';
109+
110+
// Create a Client in the Gen AI SDK
111+
const genaiClient = new GoogleGenAI({ vertexai: true, project: 'your-project', location: 'your-location' });
112+
113+
// Call generateContent() with the prompt
114+
if (retrievedPrompt.promptData?.contents) {
115+
const response = await genaiClient.models.generateContent({
116+
model: retrievedPrompt.promptData.model || 'gemini-2.5-flash',
117+
contents: retrievedPrompt.promptData.contents,
118+
config: {
119+
systemInstruction: retrievedPrompt.promptData.systemInstruction,
120+
...(retrievedPrompt.promptData.generationConfig || {}),
121+
},
122+
});
123+
console.log(response.text);
124+
}
125+
```
126+
51127
## License
52128
53129
The contents of this repository are licensed under the

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {ApiClient, NodeAuth, NodeDownloader, NodeUploader,} from '@google/genai/
77

88
import {AgentEngines} from './agentengines';
99
import {Skills} from './skills';
10+
import {Prompts} from './prompts';
1011

1112
export const SDK_VERSION = '0.9.0'; // x-release-please-version
1213

@@ -16,6 +17,7 @@ export class Client {
1617
protected readonly apiClient: ApiClient;
1718
public readonly _agentEnginesInternal: AgentEngines;
1819
public readonly skills: Skills;
20+
public readonly prompts: Prompts;
1921

2022
constructor(
2123
options: {project?: string; location?: string; apiEndpoint?: string;}) {
@@ -61,6 +63,7 @@ export class Client {
6163

6264
this._agentEnginesInternal = new AgentEngines(this.apiClient);
6365
this.skills = new Skills(this.apiClient);
66+
this.prompts = new Prompts(this.apiClient);
6467
}
6568

6669
/**

0 commit comments

Comments
 (0)