microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
34.52k stars 4.99k forks source link

[Issue]: Any good way to turn off the warning from autogen.oai.client ? #3513

Open MicDonald opened 2 months ago

MicDonald commented 2 months ago

Describe the issue

I am running autogen with local LLMs. Is there any good way to turn off the warning from autogen.oai.client or any other warning like:

[autogen.oai.client: 09-11 21:12:41] {349} WARNING - Model LLM is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing. [autogen.oai.client: 09-11 21:12:48] {349} WARNING - Model LLM is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing. [autogen.oai.client: 09-11 21:12:59] {349} WARNING - Model LLM is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.

Thanks!

Steps to reproduce

No response

Screenshots and logs

No response

Additional Information

No response

aswny commented 2 months ago

I have the same question. I have tried creating a logger and changing log levels but not able to turn it off.

autogptfreak commented 2 months ago

Instead of installing autogen with pip install autogen you can download the autogen project locally and reinstall it with pip but in editable mode: pip install -e "c:/path/to/autogen-folder"

Then in openai_utils.py you can add your config to the OAI_PRICE1K dictionary

You may have to close your IDE and open it again for changes to take effect.

image

aswny commented 2 weeks ago

While this is not supported by the library, this hack works for me.

class ModuleLoggingFilter(logging.Filter):
    """Block the logging statements from module names"""
    def __init__(self, blocked_module_names: List[str]):
        super().__init__()
        self.blocked_module_names = blocked_module_names

    def filter(self, record):
        return record.module not in self.blocked_module_names

import logging
import autogen

logger = logging.getLogger("autogen.oai.client")
logger.handlers = []
logger.propagate = True

root_logger = logging.getLogger()
root_logger.setLevel(logging.ERROR)

handler = logging.StreamHandler()
handler.setLevel(logging.ERROR)
handler.addFilter(ModuleLoggingFilter(["client"]))
root_logger.addHandler(handler)