-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat: log wrap_openai runs with unified usage_metadata #1071
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
360d77b
[draft]: openai token counting
agola11 07cb5b9
reformat and fix tests
agola11 5d6cb5f
fix files
agola11 e376a3d
revert deleted code
agola11 cb1c129
change test name
agola11 03d9e1a
address comments and update tests
agola11 30ef951
take out excessive sleeps and fix filenames
agola11 9e68a5f
add extra test files
agola11 9a4a041
fix key error
agola11 394b2d8
lint
agola11 610de6d
skip unbelievably flakey test....
agola11 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
This file contains 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
This file contains 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
This file contains 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
120 changes: 120 additions & 0 deletions
120
python/tests/integration_tests/test_data/langsmith_py_wrap_openai_.json
This file contains 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,120 @@ | ||
{ | ||
"post": [ | ||
{ | ||
"id": "d0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"start_time": "2024-10-11T20:58:23.298773+00:00", | ||
"extra": { | ||
"metadata": { | ||
"ls_method": "traceable", | ||
"ls_provider": "openai", | ||
"ls_model_type": "chat", | ||
"ls_model_name": "gpt-4o-mini", | ||
"revision_id": "v0.1.82-381-g03d9e1a-dirty" | ||
}, | ||
"runtime": { | ||
"sdk": "langsmith-py", | ||
"sdk_version": "0.1.131", | ||
"library": "langsmith", | ||
"platform": "macOS-13.2-arm64-arm-64bit", | ||
"runtime": "python", | ||
"py_implementation": "CPython", | ||
"runtime_version": "3.11.7", | ||
"langchain_version": "0.2.9", | ||
"langchain_core_version": "0.2.21" | ||
} | ||
}, | ||
"serialized": { | ||
"name": "ChatOpenAI", | ||
"signature": "(*, messages: 'Iterable[ChatCompletionMessageParam]', model: 'Union[str, ChatModel]', frequency_penalty: 'Optional[float] | NotGiven' = NOT_GIVEN, function_call: 'completion_create_params.FunctionCall | NotGiven' = NOT_GIVEN, functions: 'Iterable[completion_create_params.Function] | NotGiven' = NOT_GIVEN, logit_bias: 'Optional[Dict[str, int]] | NotGiven' = NOT_GIVEN, logprobs: 'Optional[bool] | NotGiven' = NOT_GIVEN, max_completion_tokens: 'Optional[int] | NotGiven' = NOT_GIVEN, max_tokens: 'Optional[int] | NotGiven' = NOT_GIVEN, n: 'Optional[int] | NotGiven' = NOT_GIVEN, parallel_tool_calls: 'bool | NotGiven' = NOT_GIVEN, presence_penalty: 'Optional[float] | NotGiven' = NOT_GIVEN, response_format: 'completion_create_params.ResponseFormat | NotGiven' = NOT_GIVEN, seed: 'Optional[int] | NotGiven' = NOT_GIVEN, service_tier: \"Optional[Literal['auto', 'default']] | NotGiven\" = NOT_GIVEN, stop: 'Union[Optional[str], List[str]] | NotGiven' = NOT_GIVEN, stream: 'Optional[Literal[False]] | Literal[True] | NotGiven' = NOT_GIVEN, stream_options: 'Optional[ChatCompletionStreamOptionsParam] | NotGiven' = NOT_GIVEN, temperature: 'Optional[float] | NotGiven' = NOT_GIVEN, tool_choice: 'ChatCompletionToolChoiceOptionParam | NotGiven' = NOT_GIVEN, tools: 'Iterable[ChatCompletionToolParam] | NotGiven' = NOT_GIVEN, top_logprobs: 'Optional[int] | NotGiven' = NOT_GIVEN, top_p: 'Optional[float] | NotGiven' = NOT_GIVEN, user: 'str | NotGiven' = NOT_GIVEN, extra_headers: 'Headers | None' = None, extra_query: 'Query | None' = None, extra_body: 'Body | None' = None, timeout: 'float | httpx.Timeout | None | NotGiven' = NOT_GIVEN) -> 'ChatCompletion | AsyncStream[ChatCompletionChunk]'", | ||
"doc": null | ||
}, | ||
"events": [], | ||
"tags": [], | ||
"attachments": {}, | ||
"dotted_order": "20241011T205823298773Zd0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"trace_id": "d0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"outputs": {}, | ||
"session_name": "default", | ||
"name": "ChatOpenAI", | ||
"inputs": { | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": "howdy" | ||
} | ||
], | ||
"model": "gpt-4o-mini", | ||
"stream": false, | ||
"extra_headers": null, | ||
"extra_query": null, | ||
"extra_body": null | ||
}, | ||
"run_type": "llm" | ||
} | ||
], | ||
"patch": [ | ||
{ | ||
"id": "d0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"name": "ChatOpenAI", | ||
"trace_id": "d0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"parent_run_id": null, | ||
"dotted_order": "20241011T205823298773Zd0d84d31-923d-4cb5-94a8-40a0a0087578", | ||
"tags": [], | ||
"extra": { | ||
"metadata": { | ||
"ls_method": "traceable", | ||
"ls_provider": "openai", | ||
"ls_model_type": "chat", | ||
"ls_model_name": "gpt-4o-mini", | ||
"revision_id": "v0.1.82-381-g03d9e1a-dirty" | ||
}, | ||
"runtime": { | ||
"sdk": "langsmith-py", | ||
"sdk_version": "0.1.131", | ||
"library": "langsmith", | ||
"platform": "macOS-13.2-arm64-arm-64bit", | ||
"runtime": "python", | ||
"py_implementation": "CPython", | ||
"runtime_version": "3.11.7", | ||
"langchain_version": "0.2.9", | ||
"langchain_core_version": "0.2.21" | ||
} | ||
}, | ||
"end_time": "2024-10-11T20:58:24.417106+00:00", | ||
"outputs": { | ||
"id": "chatcmpl-AHH0KBvLG7Wq3wfSEGQuxh0xE07Fl", | ||
"choices": [ | ||
{ | ||
"finish_reason": "stop", | ||
"index": 0, | ||
"logprobs": null, | ||
"message": { | ||
"content": "Howdy! How can I assist you today?", | ||
"refusal": null, | ||
"role": "assistant", | ||
"function_call": null, | ||
"tool_calls": null | ||
} | ||
} | ||
], | ||
"created": 1728680304, | ||
"model": "gpt-4o-mini-2024-07-18", | ||
"object": "chat.completion", | ||
"service_tier": null, | ||
"system_fingerprint": "fp_e2bde53e6e", | ||
"usage_metadata": { | ||
"input_tokens": 9, | ||
"output_tokens": 9, | ||
"total_tokens": 18, | ||
"input_token_details": { | ||
"cache_read": 0 | ||
}, | ||
"output_token_details": { | ||
"reasoning": 0 | ||
} | ||
} | ||
}, | ||
"events": [] | ||
} | ||
] | ||
} |
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.
unrelated to this pr — wonder if langchain-core should import these from langsmith sdk now