-
[OPIK-2068] [P SDK] LangGraph Studio Failed to extract token usage from presumably Google LLM langchain run. (#2798)
发布于
2025-07-23 13:04:02 +00:00 - [OPIK-2068]: Refactored token usage logic and added LangChain integration support.
- Extracted common token flattening and filtering logic into
flatten_result_and_add_model_extrafor reuse across providers. - Added the
LangChainUsagemodel for handling LangChain responses, supporting token details and backend-compatible dictionary conversion. - Integrated
LangChainUsageinto theOpikUsagefactory, enabling seamless support for LangChain responses in the usage pipeline.
- [OPIK-2068]: Added unit tests for
LangChainUsage.
- Introduced comprehensive test coverage for
LangChainUsagemodel. - Validated happy paths, missing input/output token details, and invalid data scenarios.
- Added tests for backend-compatible flat dictionary conversion.
- [OPIK-2068]: Refactored LangChain integration and enhanced token usage extraction.
- Added
_assert_chat_usage_validityand updated tests to validate additional token usage keys. - Introduced
langchain_run_helpersfor modular handling of LangChain-specific token usage and metadata extraction. - Refactored token usage logic across integrations to leverage
langchain_run_helpers. - Fixed
completion_tokenshandling inOpikUsageto address token calculation inaccuracies. - Improved maintainability by reducing code duplication and centralizing LangChain token extraction logic.
- [OPIK-2068]: Added Google GenAI integration tests and updated LangChain configuration.
- Introduced
ensure_google_api_configuredfixture to verifyGOOGLE_API_KEYenvironment variable setup. - Added tests validating LangChain's Google GenAI token usage and integration.
- Updated GitHub Actions to include
GOOGLE_API_KEYas a secret. - Added
langchain_google_genaito library integration requirements.
- [OPIK-2068]: Updated library requirements to fix the Python 3.9 type annotation evaluation issue.
- Added
eval-type-backporttoopenaiintegration test requirements for compatibility with Python 3.9.
- [OPIK-2068]: Updated
geminimodel version in sample agent SSE.
- Changed model from
gemini-2.5-flash-preview-05-20togemini-2.5-flashinweather_time_agent.
- [OPIK-2068]: Trimmed leading and trailing spaces from feedback score reasons in E2E tests.
- Applied
strip()toscore.reasoninverifiers.pyandtest_threads_evaluate.pyto ensure consistent formatting.
- [OPIK-2068]: Removed
LangChainUsageand refactored token usage handling across integrations.
- Deleted
LangChainUsagemodel and related tests. - Refactored
OpikUsageto directly handle LangChain token usage via Google Gemini mapping. - Consolidated token usage logic into integration-specific helpers for consistent extraction.
- Added
google_helpers.pyfor reusable token usage validation utilities in tests.
- [OPIK-2068]: Removed
LangChainUsageand refactored token usage handling across integrations.
- Deleted
LangChainUsagemodel and related tests. - Refactored
OpikUsageto directly handle LangChain token usage via Google Gemini mapping. - Consolidated token usage logic into integration-specific helpers for consistent extraction.
- Added
google_helpers.pyfor reusable token usage validation utilities in tests.
下载附件