diff --git a/package-lock.json b/package-lock.json index bab50026..357eb671 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7364,9 +7364,10 @@ } }, "node_modules/@google-cloud/aiplatform": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/@google-cloud/aiplatform/-/aiplatform-3.14.0.tgz", - "integrity": "sha512-Ajfbgj4YMn1xmHHwDSxgMxDB5LV3uXSd2KOwD5kvaaMkden2kJPhIhDNFyjYpeytrY+dFnGX+LlKm/Xv5H92Rg==", + "version": "3.32.0", + "resolved": "https://registry.npmjs.org/@google-cloud/aiplatform/-/aiplatform-3.32.0.tgz", + "integrity": "sha512-Ujvvpp5YWGRV2PzeJnZQfIkWiKtivVMxAsAmeWGOoMKfKzrUPqMc6ZL8kAc+ZuPjw3pZELjKzET0oylPrQGF2A==", + "license": "Apache-2.0", "dependencies": { "google-gax": "^4.0.3", "protobuf.js": "^1.1.2" @@ -7376,9 +7377,10 @@ } }, "node_modules/@google-cloud/vertexai": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@google-cloud/vertexai/-/vertexai-1.2.0.tgz", - "integrity": "sha512-EH0dnoMRIBQzJEEOUWN03eWPSdLBFdsZA/am3eU+qYrnNyY9okUueOajZd79U48KwgFbqoFrCA9yHQ30DgfD8Q==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@google-cloud/vertexai/-/vertexai-1.9.0.tgz", + "integrity": "sha512-8brlcJwFXI4fPuBtsDNQqCdWZmz8gV9jeEKOU0vc5H2SjehCQpXK/NwuSEr916zbhlBHtg/sU37qQQdgvh5BRA==", + "license": "Apache-2.0", "dependencies": { "google-auth-library": "^9.1.0" }, @@ -29349,8 +29351,8 @@ "@anthropic-ai/sdk": "^0.27.1", "@aws-sdk/client-bedrock-runtime": "^3.499.0", "@azure/openai": "^1.0.0-beta.11", - "@google-cloud/aiplatform": "^3.10.0", - "@google-cloud/vertexai": "^1.2.0", + "@google-cloud/aiplatform": "^3.32.0", + "@google-cloud/vertexai": "^1.9.0", "@langchain/community": "^0.2.31", "@pinecone-database/pinecone": "^2.0.1", "@traceloop/node-server-sdk": "*", diff --git a/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts b/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts index 2bdfea83..00a5bf40 100644 --- a/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts +++ b/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts @@ -157,10 +157,22 @@ export class VertexAIInstrumentation extends InstrumentationBase { } if (this._shouldSendPrompts() && "contents" in params) { - attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = - params.contents[0].role ?? "user"; - attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] = - this._formatPartsData(params.contents[0].parts); + let i = 0; + + if (instance["systemInstruction"]) { + attributes[`${SpanAttributes.LLM_PROMPTS}.${i}.role`] = "system"; + attributes[`${SpanAttributes.LLM_PROMPTS}.${i}.content`] = + this._formatPartsData(instance["systemInstruction"].parts); + + i++; + } + + params.contents.forEach((content, j) => { + attributes[`${SpanAttributes.LLM_PROMPTS}.${i + j}.role`] = + content.role ?? "user"; + attributes[`${SpanAttributes.LLM_PROMPTS}.${i + j}.content`] = + this._formatPartsData(content.parts); + }); } } catch (e) { this._diag.debug(e); diff --git a/packages/sample-app/package.json b/packages/sample-app/package.json index 738cc19d..9222f8c0 100644 --- a/packages/sample-app/package.json +++ b/packages/sample-app/package.json @@ -36,8 +36,8 @@ "@anthropic-ai/sdk": "^0.27.1", "@aws-sdk/client-bedrock-runtime": "^3.499.0", "@azure/openai": "^1.0.0-beta.11", - "@google-cloud/aiplatform": "^3.10.0", - "@google-cloud/vertexai": "^1.2.0", + "@google-cloud/aiplatform": "^3.32.0", + "@google-cloud/vertexai": "^1.9.0", "@langchain/community": "^0.2.31", "@pinecone-database/pinecone": "^2.0.1", "@traceloop/node-server-sdk": "*", diff --git a/packages/sample-app/src/vertexai/gemini.ts b/packages/sample-app/src/vertexai/gemini.ts index b5b2afe5..f88c9dff 100644 --- a/packages/sample-app/src/vertexai/gemini.ts +++ b/packages/sample-app/src/vertexai/gemini.ts @@ -20,6 +20,10 @@ async function createNonStreamingContent() { // Instantiate the model const generativeModel = vertexAI.getGenerativeModel({ model: "gemini-1.5-flash", + systemInstruction: { + role: "system", + parts: [{ text: "You are a helpful assistant" }], + }, }); const request = { @@ -53,6 +57,10 @@ async function createStreamingContent() { // Instantiate the model const generativeModel = vertexAI.getGenerativeModel({ model: "gemini-1.5-flash", + systemInstruction: { + role: "system", + parts: [{ text: "You are a helpful assistant" }], + }, }); const request = {