OpenAI: non-streaming tool call response. Verify the response is mapped to Reply.ChatDeltas[].ToolCalls with id/name/arguments intact, and usage tokens land on Reply.PromptTokens / Reply.Tokens.
(t *testing.T)
| 12 | // mapped to Reply.ChatDeltas[].ToolCalls with id/name/arguments intact, |
| 13 | // and usage tokens land on Reply.PromptTokens / Reply.Tokens. |
| 14 | func TestPredictRich_OpenAI_ToolCalls(t *testing.T) { |
| 15 | srv, _ := fakeOpenAIUpstream(t, func(_ openAIRequest) (int, string, string) { |
| 16 | return 200, `{ |
| 17 | "id":"resp-1", |
| 18 | "choices":[{ |
| 19 | "index":0, |
| 20 | "message":{ |
| 21 | "role":"assistant", |
| 22 | "content":"", |
| 23 | "tool_calls":[ |
| 24 | {"id":"call_abc","type":"function","function":{"name":"get_weather","arguments":"{\"location\":\"SF\"}"}}, |
| 25 | {"id":"call_def","type":"function","function":{"name":"get_time","arguments":"{\"tz\":\"PT\"}"}} |
| 26 | ] |
| 27 | }, |
| 28 | "finish_reason":"tool_calls" |
| 29 | }], |
| 30 | "usage":{"prompt_tokens":42,"completion_tokens":18,"total_tokens":60} |
| 31 | }`, "application/json" |
| 32 | }) |
| 33 | defer srv.Close() |
| 34 | g := NewWithT(t) |
| 35 | cp := newTranslateCloudProxy(t, srv.URL) |
| 36 | |
| 37 | reply, err := cp.PredictRich(&pb.PredictOptions{ |
| 38 | Messages: []*pb.Message{{Role: "user", Content: "what's the weather?"}}, |
| 39 | }) |
| 40 | g.Expect(err).NotTo(HaveOccurred()) |
| 41 | g.Expect(string(reply.GetMessage())).To(Equal("")) |
| 42 | g.Expect(reply.GetPromptTokens()).To(Equal(int32(42))) |
| 43 | g.Expect(reply.GetTokens()).To(Equal(int32(18))) |
| 44 | g.Expect(reply.GetChatDeltas()).To(HaveLen(1)) |
| 45 | tcs := reply.GetChatDeltas()[0].GetToolCalls() |
| 46 | g.Expect(tcs).To(HaveLen(2)) |
| 47 | g.Expect(tcs[0].GetId()).To(Equal("call_abc")) |
| 48 | g.Expect(tcs[0].GetName()).To(Equal("get_weather")) |
| 49 | g.Expect(tcs[0].GetArguments()).To(ContainSubstring(`"location":"SF"`)) |
| 50 | g.Expect(tcs[1].GetId()).To(Equal("call_def")) |
| 51 | g.Expect(tcs[1].GetName()).To(Equal("get_time")) |
| 52 | } |
| 53 | |
| 54 | // OpenAI: streaming tool call. Arguments arrive as a sequence of |
| 55 | // delta chunks; the consumer is expected to concatenate by tool index. |
nothing calls this directly
no test coverage detected