@@ -140,8 +140,9 @@ func (c *Caller) Metadata() metadata.M {
140140
141141// GetInvoke returns the invoke response
142142func (c * Caller ) GetInvoke (ctx context.Context , userInstruction string , baseSystemMessage string , transID string , includeCallStack bool ) (* ai.InvokeResponse , error ) {
143+ md := c .md .Clone ()
143144 // read tools attached to the metadata
144- tcs , err := register .ListToolCalls (c . md )
145+ tcs , err := register .ListToolCalls (md )
145146 if err != nil {
146147 return & ai.InvokeResponse {}, err
147148 }
@@ -161,7 +162,7 @@ func (c *Caller) GetInvoke(ctx context.Context, userInstruction string, baseSyst
161162 promptUsage int
162163 completionUsage int
163164 )
164- chatCompletionResponse , err := c .provider .GetChatCompletions (ctx , req , c . md )
165+ chatCompletionResponse , err := c .provider .GetChatCompletions (ctx , req , md )
165166 if err != nil {
166167 return nil , err
167168 }
@@ -201,7 +202,7 @@ func (c *Caller) GetInvoke(ctx context.Context, userInstruction string, baseSyst
201202 req2 := openai.ChatCompletionRequest {
202203 Messages : messages2 ,
203204 }
204- chatCompletionResponse2 , err := c .provider .GetChatCompletions (ctx , req2 , c . md )
205+ chatCompletionResponse2 , err := c .provider .GetChatCompletions (ctx , req2 , md )
205206 if err != nil {
206207 return nil , err
207208 }
@@ -226,8 +227,9 @@ func (c *Caller) GetInvoke(ctx context.Context, userInstruction string, baseSyst
226227
227228// GetChatCompletions accepts openai.ChatCompletionRequest and responds to http.ResponseWriter.
228229func (c * Caller ) GetChatCompletions (ctx context.Context , req openai.ChatCompletionRequest , transID string , w http.ResponseWriter ) error {
230+ md := c .md .Clone ()
229231 // 1. find all hosting tool sfn
230- tagTools , err := register .ListToolCalls (c . md )
232+ tagTools , err := register .ListToolCalls (md )
231233 if err != nil {
232234 return err
233235 }
@@ -252,7 +254,7 @@ func (c *Caller) GetChatCompletions(ctx context.Context, req openai.ChatCompleti
252254 flusher = eventFlusher (w )
253255 isFunctionCall = false
254256 )
255- resStream , err := c .provider .GetChatCompletionsStream (ctx , req , c . md )
257+ resStream , err := c .provider .GetChatCompletionsStream (ctx , req , md )
256258 if err != nil {
257259 return err
258260 }
@@ -310,7 +312,7 @@ func (c *Caller) GetChatCompletions(ctx context.Context, req openai.ChatCompleti
310312 }
311313 flusher .Flush ()
312314 } else {
313- resp , err := c .provider .GetChatCompletions (ctx , req , c . md )
315+ resp , err := c .provider .GetChatCompletions (ctx , req , md )
314316 if err != nil {
315317 return err
316318 }
@@ -349,7 +351,7 @@ func (c *Caller) GetChatCompletions(ctx context.Context, req openai.ChatCompleti
349351
350352 if req .Stream {
351353 flusher := w .(http.Flusher )
352- resStream , err := c .provider .GetChatCompletionsStream (ctx , req , c . md )
354+ resStream , err := c .provider .GetChatCompletionsStream (ctx , req , md )
353355 if err != nil {
354356 return err
355357 }
@@ -369,7 +371,7 @@ func (c *Caller) GetChatCompletions(ctx context.Context, req openai.ChatCompleti
369371 _ = writeStreamEvent (w , flusher , streamRes )
370372 }
371373 } else {
372- resp , err := c .provider .GetChatCompletions (ctx , req , c . md )
374+ resp , err := c .provider .GetChatCompletions (ctx , req , md )
373375 if err != nil {
374376 return err
375377 }
0 commit comments