Skip to content

Commit ec83a6c

Browse files
author
Guiners
committed
adding samples, test, lints
1 parent 6fdf714 commit ec83a6c

File tree

5 files changed

+18
-33
lines changed

5 files changed

+18
-33
lines changed

genai/live/live-audio-with-txt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function generateContent(
2626
projectId = GOOGLE_CLOUD_PROJECT,
2727
location = GOOGLE_CLOUD_LOCATION
2828
) {
29-
const ai = new GoogleGenAI({
29+
const client = new GoogleGenAI({
3030
vertexai: true,
3131
project: projectId,
3232
location: location,
@@ -78,7 +78,7 @@ async function generateContent(
7878
return audioChunks;
7979
}
8080

81-
const session = await ai.live.connect({
81+
const session = await client.live.connect({
8282
model: modelId,
8383
config: config,
8484
callbacks: {

genai/live/live-ground-ragengine-with-txt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function generateContent(
3030
projectId = GOOGLE_CLOUD_PROJECT,
3131
location = GOOGLE_CLOUD_LOCATION
3232
) {
33-
const ai = new GoogleGenAI({
33+
const client = new GoogleGenAI({
3434
vertexai: true,
3535
project: projectId,
3636
location: location,
@@ -81,7 +81,7 @@ async function generateContent(
8181
return turns;
8282
}
8383

84-
const session = await ai.live.connect({
84+
const session = await client.live.connect({
8585
model: modelId,
8686
config: config,
8787
callbacks: {

genai/live/live-structured-ouput-with-txt.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
// [START googlegenaisdk_live_structured_output_with_txt]
1616

1717
'use strict';
18-
// todo not working
1918
const {OpenAI} = require('openai');
2019
const {GoogleAuth} = require('google-auth-library');
2120

2221
const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
23-
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';
22+
const GOOGLE_CLOUD_LOCATION =
23+
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';
2424

2525
const CalendarEventSchema = {
2626
type: 'object',
@@ -39,28 +39,23 @@ async function generateContent(
3939
projectId = GOOGLE_CLOUD_PROJECT,
4040
location = GOOGLE_CLOUD_LOCATION
4141
) {
42-
console.log('[Init] Starting structured output sample...');
43-
console.log(`[Init] Project: ${projectId}, Location: ${location}`);
44-
4542
const auth = new GoogleAuth({
4643
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
4744
});
4845
const client = await auth.getClient();
49-
const token = await client.getAccessToken();
46+
const tokenResponse = await client.getAccessToken();
47+
48+
const token = tokenResponse.token;
5049

5150
const ENDPOINT_ID = 'openapi';
5251
const baseURL = `https://${location}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/${ENDPOINT_ID}`;
5352

54-
console.log('[Auth] Successfully retrieved access token');
55-
56-
const ai = new OpenAI({
53+
const openAI = new OpenAI({
5754
apiKey: token,
5855
baseURL: baseURL,
5956
});
6057

61-
console.log('[Session] Sending structured output request...');
62-
63-
const completion = await ai.chat.completions.create({
58+
const completion = await openAI.chat.completions.create({
6459
model: 'google/gemini-2.0-flash-001',
6560
messages: [
6661
{role: 'system', content: 'Extract the event information.'},
@@ -78,18 +73,8 @@ async function generateContent(
7873
},
7974
});
8075

81-
const response = completion.choices[0].message;
82-
console.log('[Response] Raw structured output:', response);
83-
84-
let parsed;
85-
try {
86-
parsed = JSON.parse(response.content[0].text);
87-
} catch (err) {
88-
console.error('[Error] Failed to parse structured response:', err);
89-
throw err;
90-
}
91-
92-
console.log('[Parsed Response]', parsed);
76+
const response = completion.choices[0].message.content;
77+
console.log(response);
9378

9479
// Example expected output:
9580
// {
@@ -98,7 +83,7 @@ async function generateContent(
9883
// participants: ['Alice', 'Bob']
9984
// }
10085

101-
return parsed;
86+
return response;
10287
}
10388

10489
// [END googlegenaisdk_live_structured_output_with_txt]

genai/live/live-transcribe-with-audio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function generateContent(
2525
projectId = GOOGLE_CLOUD_PROJECT,
2626
location = GOOGLE_CLOUD_LOCATION
2727
) {
28-
const ai = new GoogleGenAI({
28+
const client = new GoogleGenAI({
2929
vertexai: true,
3030
project: projectId,
3131
location: location,
@@ -74,7 +74,7 @@ async function generateContent(
7474
return turns;
7575
}
7676

77-
const session = await ai.live.connect({
77+
const session = await client.live.connect({
7878
model: modelId,
7979
config: config,
8080
callbacks: {

genai/live/live-txt-with-audio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function generateContent(
2626
projectId = GOOGLE_CLOUD_PROJECT,
2727
location = GOOGLE_CLOUD_LOCATION
2828
) {
29-
const ai = new GoogleGenAI({
29+
const client = new GoogleGenAI({
3030
vertexai: true,
3131
project: projectId,
3232
location: location,
@@ -59,7 +59,7 @@ async function generateContent(
5959
return turns;
6060
}
6161

62-
const session = await ai.live.connect({
62+
const session = await client.live.connect({
6363
model: modelId,
6464
config: config,
6565
callbacks: {

0 commit comments

Comments
 (0)