-
Notifications
You must be signed in to change notification settings - Fork 46
fix(openai): streaming tool_call + logging multiple tool_call #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b454c2a
handle null text in streaming chunks, handle tools in streaming chunk…
guillaumefontan e672c8a
test added
guillaumefontan aa45b3c
cleanup
guillaumefontan cb14dcc
remove semicolon
guillaumefontan 234c972
Remove comments
guillaumefontan a598aae
update to tool_calls
guillaumefontan 11661d4
prettier
guillaumefontan c696b10
ci: fix broken ci
nirga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
231 changes: 231 additions & 0 deletions
231
...attributes-in-span-for-stream-completion-when-multiple-tools-cal_2278551756/recording.har
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| { | ||
| "log": { | ||
| "_recordingName": "Test OpenAI instrumentation/should set function_call attributes in span for stream completion when multiple tools called", | ||
| "creator": { | ||
| "comment": "persister:fs", | ||
| "name": "Polly.JS", | ||
| "version": "6.0.6" | ||
| }, | ||
| "entries": [ | ||
| { | ||
| "_id": "4e7f1c094bf406a3975b24c0c8857547", | ||
| "_order": 0, | ||
| "cache": {}, | ||
| "request": { | ||
| "bodySize": 1516, | ||
| "cookies": [], | ||
| "headers": [ | ||
| { | ||
| "_fromType": "array", | ||
| "name": "content-length", | ||
| "value": "1516" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "accept", | ||
| "value": "application/json" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "content-type", | ||
| "value": "application/json" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "user-agent", | ||
| "value": "OpenAI/JS 4.57.0" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-lang", | ||
| "value": "js" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-package-version", | ||
| "value": "4.57.0" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-os", | ||
| "value": "MacOS" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-arch", | ||
| "value": "arm64" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-runtime", | ||
| "value": "node" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "x-stainless-runtime-version", | ||
| "value": "v22.1.0" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "accept-encoding", | ||
| "value": "gzip,deflate" | ||
| }, | ||
| { | ||
| "name": "host", | ||
| "value": "api.openai.com" | ||
| } | ||
| ], | ||
| "headersSize": 470, | ||
| "httpVersion": "HTTP/1.1", | ||
| "method": "POST", | ||
| "postData": { | ||
| "mimeType": "application/json", | ||
| "params": [], | ||
| "text": "{\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What's the weather today in Boston and what will the weather be tomorrow in Chicago?\"\n }\n ],\n \"stream\": true,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_current_weather\",\n \"description\": \"Get the current weather in a given location\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"location\": {\n \"type\": \"string\",\n \"description\": \"The city and state, e.g. San Francisco, CA\"\n },\n \"unit\": {\n \"type\": \"string\",\n \"enum\": [\n \"celsius\",\n \"fahrenheit\"\n ]\n }\n },\n \"required\": [\n \"location\"\n ]\n }\n }\n },\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_tomorrow_weather\",\n \"description\": \"Get tomorrow's weather in a given location\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"location\": {\n \"type\": \"string\",\n \"description\": \"The city and state, e.g. San Francisco, CA\"\n },\n \"unit\": {\n \"type\": \"string\",\n \"enum\": [\n \"celsius\",\n \"fahrenheit\"\n ]\n }\n },\n \"required\": [\n \"location\"\n ]\n }\n }\n }\n ]\n}" | ||
| }, | ||
| "queryString": [], | ||
| "url": "https://api.openai.com/v1/chat/completions" | ||
| }, | ||
| "response": { | ||
| "bodySize": 5057, | ||
| "content": { | ||
| "mimeType": "text/event-stream; charset=utf-8", | ||
| "size": 5057, | ||
| "text": "data: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":null},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"id\":\"call_5LSV532rbNrhEKj3XddxLXKb\",\"type\":\"function\",\"function\":{\"name\":\"get_current_weather\",\"arguments\":\"\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"{\\\"lo\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"catio\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"n\\\": \\\"B\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"osto\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"n, MA\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":0,\"function\":{\"arguments\":\"\\\"}\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"id\":\"call_8rndUDfjLo174WcwdN7aT7mP\",\"type\":\"function\",\"function\":{\"name\":\"get_tomorrow_weather\",\"arguments\":\"\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"{\\\"lo\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"catio\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"n\\\": \\\"C\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"hica\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"go, I\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{\"tool_calls\":[{\"index\":1,\"function\":{\"arguments\":\"L\\\"}\"}}]},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AFzJUI0700ButGSyUudPGR9IqmGJi\",\"object\":\"chat.completion.chunk\",\"created\":1728373972,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_f85bea6784\",\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"tool_calls\"}]}\n\ndata: [DONE]\n\n" | ||
| }, | ||
| "cookies": [ | ||
| { | ||
| "domain": ".api.openai.com", | ||
| "expires": "2024-10-08T08:22:52.000Z", | ||
| "httpOnly": true, | ||
| "name": "__cf_bm", | ||
| "path": "/", | ||
| "sameSite": "None", | ||
| "secure": true, | ||
| "value": "7VLzjD6bk2vl3dQ1buulluBXUcZWRHRf3FMpMkNfDe4-1728373972-1.0.1.1-M5XcPulIjIntr0YG3dvI4hnwTDHLaXKHuLZd_JUTOH40kvNyQnhrPvm2PB12Tf7rR.E_D7F80cPaEEHKxli0SA" | ||
| }, | ||
| { | ||
| "domain": ".api.openai.com", | ||
| "httpOnly": true, | ||
| "name": "_cfuvid", | ||
| "path": "/", | ||
| "sameSite": "None", | ||
| "secure": true, | ||
| "value": "M4JyAwhhEaoDpYpUXniLhAW_YlQUIJCcsDEx1ZsVvTs-1728373972937-0.0.1.1-604800000" | ||
| } | ||
| ], | ||
| "headers": [ | ||
| { | ||
| "name": "date", | ||
| "value": "Tue, 08 Oct 2024 07:52:52 GMT" | ||
| }, | ||
| { | ||
| "name": "content-type", | ||
| "value": "text/event-stream; charset=utf-8" | ||
| }, | ||
| { | ||
| "name": "transfer-encoding", | ||
| "value": "chunked" | ||
| }, | ||
| { | ||
| "name": "connection", | ||
| "value": "keep-alive" | ||
| }, | ||
| { | ||
| "name": "access-control-expose-headers", | ||
| "value": "X-Request-ID" | ||
| }, | ||
| { | ||
| "name": "openai-organization", | ||
| "value": "trubrics" | ||
| }, | ||
| { | ||
| "name": "openai-processing-ms", | ||
| "value": "625" | ||
| }, | ||
| { | ||
| "name": "openai-version", | ||
| "value": "2020-10-01" | ||
| }, | ||
| { | ||
| "name": "strict-transport-security", | ||
| "value": "max-age=31536000; includeSubDomains; preload" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-limit-requests", | ||
| "value": "10000" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-limit-tokens", | ||
| "value": "10000000" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-remaining-requests", | ||
| "value": "9999" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-remaining-tokens", | ||
| "value": "9999961" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-reset-requests", | ||
| "value": "6ms" | ||
| }, | ||
| { | ||
| "name": "x-ratelimit-reset-tokens", | ||
| "value": "0s" | ||
| }, | ||
| { | ||
| "name": "x-request-id", | ||
| "value": "req_a89738719c34e11ea192e73a5497d00a" | ||
| }, | ||
| { | ||
| "name": "cf-cache-status", | ||
| "value": "DYNAMIC" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "set-cookie", | ||
| "value": "__cf_bm=7VLzjD6bk2vl3dQ1buulluBXUcZWRHRf3FMpMkNfDe4-1728373972-1.0.1.1-M5XcPulIjIntr0YG3dvI4hnwTDHLaXKHuLZd_JUTOH40kvNyQnhrPvm2PB12Tf7rR.E_D7F80cPaEEHKxli0SA; path=/; expires=Tue, 08-Oct-24 08:22:52 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None" | ||
| }, | ||
| { | ||
| "_fromType": "array", | ||
| "name": "set-cookie", | ||
| "value": "_cfuvid=M4JyAwhhEaoDpYpUXniLhAW_YlQUIJCcsDEx1ZsVvTs-1728373972937-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None" | ||
| }, | ||
| { | ||
| "name": "x-content-type-options", | ||
| "value": "nosniff" | ||
| }, | ||
| { | ||
| "name": "server", | ||
| "value": "cloudflare" | ||
| }, | ||
| { | ||
| "name": "cf-ray", | ||
| "value": "8cf48dcd0a786fdb-CDG" | ||
| } | ||
| ], | ||
| "headersSize": 1150, | ||
| "httpVersion": "HTTP/1.1", | ||
| "redirectURL": "", | ||
| "status": 200, | ||
| "statusText": "OK" | ||
| }, | ||
| "startedDateTime": "2024-10-08T07:52:51.703Z", | ||
| "time": 1328, | ||
| "timings": { | ||
| "blocked": -1, | ||
| "connect": -1, | ||
| "dns": -1, | ||
| "receive": 0, | ||
| "send": 0, | ||
| "ssl": -1, | ||
| "wait": 1328 | ||
| } | ||
| } | ||
| ], | ||
| "pages": [], | ||
| "version": "1.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All done thanks!