File tree Expand file tree Collapse file tree 4 files changed +36
-14
lines changed
instrumentation-vertexai/src Expand file tree Collapse file tree 4 files changed +36
-14
lines changed Original file line number Diff line number Diff line change @@ -157,10 +157,22 @@ export class VertexAIInstrumentation extends InstrumentationBase {
157157 }
158158
159159 if ( this . _shouldSendPrompts ( ) && "contents" in params ) {
160- attributes [ `${ SpanAttributes . LLM_PROMPTS } .0.role` ] =
161- params . contents [ 0 ] . role ?? "user" ;
162- attributes [ `${ SpanAttributes . LLM_PROMPTS } .0.content` ] =
163- this . _formatPartsData ( params . contents [ 0 ] . parts ) ;
160+ let i = 0 ;
161+
162+ if ( instance [ "systemInstruction" ] ) {
163+ attributes [ `${ SpanAttributes . LLM_PROMPTS } .${ i } .role` ] = "system" ;
164+ attributes [ `${ SpanAttributes . LLM_PROMPTS } .${ i } .content` ] =
165+ this . _formatPartsData ( instance [ "systemInstruction" ] . parts ) ;
166+
167+ i ++ ;
168+ }
169+
170+ params . contents . forEach ( ( content , j ) => {
171+ attributes [ `${ SpanAttributes . LLM_PROMPTS } .${ i + j } .role` ] =
172+ content . role ?? "user" ;
173+ attributes [ `${ SpanAttributes . LLM_PROMPTS } .${ i + j } .content` ] =
174+ this . _formatPartsData ( content . parts ) ;
175+ } ) ;
164176 }
165177 } catch ( e ) {
166178 this . _diag . debug ( e ) ;
Original file line number Diff line number Diff line change 3636 "@anthropic-ai/sdk" : " ^0.27.1" ,
3737 "@aws-sdk/client-bedrock-runtime" : " ^3.499.0" ,
3838 "@azure/openai" : " ^1.0.0-beta.11" ,
39- "@google-cloud/aiplatform" : " ^3.10 .0" ,
40- "@google-cloud/vertexai" : " ^1.2 .0" ,
39+ "@google-cloud/aiplatform" : " ^3.32 .0" ,
40+ "@google-cloud/vertexai" : " ^1.9 .0" ,
4141 "@langchain/community" : " ^0.2.31" ,
4242 "@pinecone-database/pinecone" : " ^2.0.1" ,
4343 "@traceloop/node-server-sdk" : " *" ,
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ async function createNonStreamingContent() {
2020 // Instantiate the model
2121 const generativeModel = vertexAI . getGenerativeModel ( {
2222 model : "gemini-1.5-flash" ,
23+ systemInstruction : {
24+ role : "system" ,
25+ parts : [ { text : "You are a helpful assistant" } ] ,
26+ } ,
2327 } ) ;
2428
2529 const request = {
@@ -53,6 +57,10 @@ async function createStreamingContent() {
5357 // Instantiate the model
5458 const generativeModel = vertexAI . getGenerativeModel ( {
5559 model : "gemini-1.5-flash" ,
60+ systemInstruction : {
61+ role : "system" ,
62+ parts : [ { text : "You are a helpful assistant" } ] ,
63+ } ,
5664 } ) ;
5765
5866 const request = {
You can’t perform that action at this time.
0 commit comments