Skip to content
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

Logging #1146

Merged
merged 92 commits into from
Feb 15, 2024
Merged

Logging #1146

merged 92 commits into from
Feb 15, 2024

Conversation

cheng-tan
Copy link
Contributor

@cheng-tan cheng-tan commented Jan 4, 2024

Why are these changes needed?

Adding the logging capability for openai >= 1, 4 tables get logged:

  • chat_completions: tracking each llm run
  • agents: tracking the agent's name, type, configurations
  • oai_client: tracking the AzureOpenAI or OpenAI client configurations
  • oai_wrapper: tracking OpenAIWrapper configurations

Related issue number

#7

TODO:

  • track cost in db
  • track session id
  • pass in db name as argument
  • start logging/stop logging
  • logging oai wrapper in a new table
  • logging oai client in a new table
  • improve error handling
  • update doc
  • tests
  • versioning db schema?
  • option to dump logging to console

Checks

@codecov-commenter
Copy link

codecov-commenter commented Jan 4, 2024

Codecov Report

Attention: 58 lines in your changes are missing coverage. Please review.

Comparison is base (f68c09b) 37.85% compared to head (9adf462) 61.92%.

Files Patch % Lines
autogen/logger/sqlite_logger.py 74.19% 23 Missing and 9 partials ⚠️
autogen/logger/base_logger.py 70.96% 8 Missing and 1 partial ⚠️
autogen/oai/client.py 71.42% 4 Missing and 2 partials ⚠️
autogen/logger/logger_factory.py 66.66% 2 Missing and 2 partials ⚠️
autogen/runtime_logging.py 90.90% 1 Missing and 2 partials ⚠️
autogen/agentchat/groupchat.py 33.33% 1 Missing and 1 partial ⚠️
autogen/agentchat/user_proxy_agent.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1146       +/-   ##
===========================================
+ Coverage   37.85%   61.92%   +24.07%     
===========================================
  Files          50       56        +6     
  Lines        5733     5985      +252     
  Branches     1297     1450      +153     
===========================================
+ Hits         2170     3706     +1536     
+ Misses       3391     1946     -1445     
- Partials      172      333      +161     
Flag Coverage Δ
unittests 61.73% <76.77%> (+23.88%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ekzhu ekzhu added the dev development experience/productivity label Jan 4, 2024
autogen/oai/client.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@sonichi sonichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin666aa do you think the usage summary should be part of the telemetry or separate?
@cheng-tan adding tests + docs early can help others and yourself clarify the way of using it and I generally recommend those to be written even before any implementation. For code formatting, use pre-commit.

autogen/oai/client.py Outdated Show resolved Hide resolved
autogen/oai/client.py Outdated Show resolved Hide resolved
autogen/oai/client.py Outdated Show resolved Hide resolved
autogen/oai/client.py Outdated Show resolved Hide resolved
autogen/oai/telemetry.py Outdated Show resolved Hide resolved
autogen/oai/telemetry.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@radman-x radman-x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok with this, given my previous comments are addressed (even if in a future release).

@sonichi sonichi added this pull request to the merge queue Feb 15, 2024
Merged via the queue into microsoft:main with commit 4ccff54 Feb 15, 2024
55 of 57 checks passed
afourney added a commit that referenced this pull request Feb 15, 2024
* Logging (#1146)

* WIP:logging

* serialize request, response and client

* Fixed code formatting.

* Updated to use a global package, and added some test cases. Still very-much a draft.

* Update work in progress.

* adding cost

* log new agent

* update log_completion test in test_agent_telemetry

* tests

* fix formatting

* Added additional telemetry for wrappers and clients.

* WIP: add test for oai client and oai wrapper table

* update test_telemetry

* fix format

* More tests, update doc and clean up

* small fix for session id - moved to start_logging and return from start_logging

* update start_logging type to return str, add notebook to demonstrate use of telemetry

* add ability to get log dataframe

* precommit formatting fixes

* formatting fix

* Remove pandas dependency from telemetry and only use in notebook

* formatting fixes

* log query exceptions

* fix formatting

* fix ci

* fix comment - add notebook link in doc and fix groupchat serialization

* small fix

* do not serialize Agent

* formatting

* wip

* fix test

* serialization bug fix for soc moderator

* fix test and clean up

* wip: add version table

* fix test

* fix test

* fix test

* make the logging interface more general and fix client model logging

* fix format

* fix formatting and tests

* fix

* fix comment

* Renaming telemetry to logging

* update notebook

* update doc

* formatting

* formatting and clean up

* fix doc

* fix link and title

* fix notebook format and fix comment

* format

* try fixing agent test and update migration guide

* fix link

* debug print

* debug

* format

* add back tests

* fix tests

---------

Co-authored-by: Adam Fourney <adamfo@microsoft.com>
Co-authored-by: Victor Dibia <victordibia@microsoft.com>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>

* Validate llm_config passed to ConversableAgent (issue #1522) (#1654)

* Validate llm_config passed to ConversableAgent

Based on #1522, this commit implements the additional validation checks in
`ConversableAgent.`

Add the following validation and `raise ValueError` if:

 - The `llm_config` is `None`.
 - The `llm_config` is valid, but `config_list` is missing or lacks elements.
 - The `config_list` is valid, but no `model` is specified.

The rest of the changes are code churn to adjust or add the test cases.

* Validate llm_config passed to ConversableAgent

Based on #1522, this commit implements the additional validation checks in
`ConversableAgent.`

Add the following validation and `raise ValueError` if:

 - The `llm_config` is `None` (validated in `ConversableAgent`).
 - The `llm_config` has no `model` specified and `config_list` is empty
   (validated in `OpenAIWrapper`).
 - The `config_list` has at least one entry, but not all the entries have
   the `model` is specified (validated in `OpenAIWrapper`).

The rest of the changes are code churn to adjust or add the test cases.

* Validate llm_config passed to ConversableAgent

Based on #1522, this commit implements the additional validation checks in
`ConversableAgent.`

Add the following validation and `raise ValueError` if:

 - The `llm_config` is `None` (validated in `ConversableAgent`).
 - The `llm_config` has no `model` specified and `config_list` is empty
   (validated in `OpenAIWrapper`).
 - The `config_list` has at least one entry, but not all the entries have
   the `model` is specified (validated in `OpenAIWrapper`).

The rest of the changes are code churn to adjust or add the test cases.

* Validate llm_config passed to ConversableAgent

Based on #1522, this commit implements the additional validation checks in
`ConversableAgent.`

Add the following validation and `raise ValueError` if:

 - The `llm_config` is `None` (validated in `ConversableAgent`).
 - The `llm_config` has no `model` specified and `config_list` is empty
   (validated in `OpenAIWrapper`).
 - The `config_list` has at least one entry, but not all the entries have
   the `model` is specified (validated in `OpenAIWrapper`).

The rest of the changes are code churn to adjust or add the test cases.

* Validate llm_config passed to ConversableAgent

Based on #1522, this commit implements the additional validation checks in
`ConversableAgent.`

Add the following validation and `raise ValueError` if:

 - The `llm_config` is `None` (validated in `ConversableAgent`).
 - The `llm_config` has no `model` specified and `config_list` is empty
   (validated in `OpenAIWrapper`).
 - The `config_list` has at least one entry, but not all the entries have
   the `model` is specified (validated in `OpenAIWrapper`).

The rest of the changes are code churn to adjust or add the test cases.

* Fix the test_web_surfer issue

For anyone reading this: you need to `pip install markdownify` for the
`import WebSurferAgent` to succeed. That is needed to run the
`test_web_surfer.py` locally.

Test logic needs `llm_config` that is not `None` and that is not
`False`.

Let us pray that this works as part of GitHub actions ...

* One more fix for llm_config validation contract

* update test_utils

* remove stale files

---------

Co-authored-by: Adam Fourney <adamfo@microsoft.com>
Co-authored-by: Victor Dibia <victordibia@microsoft.com>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Co-authored-by: Gunnar Kudrjavets <gunnarku@users.noreply.github.com>
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* rename GenericAgent -> ResponsiveAgent

* always
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* WIP:logging

* serialize request, response and client

* Fixed code formatting.

* Updated to use a global package, and added some test cases. Still very-much a draft.

* Update work in progress.

* adding cost

* log new agent

* update log_completion test in test_agent_telemetry

* tests

* fix formatting

* Added additional telemetry for wrappers and clients.

* WIP: add test for oai client and oai wrapper table

* update test_telemetry

* fix format

* More tests, update doc and clean up

* small fix for session id - moved to start_logging and return from start_logging

* update start_logging type to return str, add notebook to demonstrate use of telemetry

* add ability to get log dataframe

* precommit formatting fixes

* formatting fix

* Remove pandas dependency from telemetry and only use in notebook

* formatting fixes

* log query exceptions

* fix formatting

* fix ci

* fix comment - add notebook link in doc and fix groupchat serialization

* small fix

* do not serialize Agent

* formatting

* wip

* fix test

* serialization bug fix for soc moderator

* fix test and clean up

* wip: add version table

* fix test

* fix test

* fix test

* make the logging interface more general and fix client model logging

* fix format

* fix formatting and tests

* fix

* fix comment

* Renaming telemetry to logging

* update notebook

* update doc

* formatting

* formatting and clean up

* fix doc

* fix link and title

* fix notebook format and fix comment

* format

* try fixing agent test and update migration guide

* fix link

* debug print

* debug

* format

* add back tests

* fix tests

---------

Co-authored-by: Adam Fourney <adamfo@microsoft.com>
Co-authored-by: Victor Dibia <victordibia@microsoft.com>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev development experience/productivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants