跳到主要内容

迁移指南

迁移到0.2版本

openai v1 是对库的完全重写,包含了许多重大变更。例如,推理过程需要实例化一个客户端,而不是使用全局类方法。 因此,pyautogen<0.2 的用户需要进行一些更改。

  • api_base -> base_url, request_timeout -> timeoutllm_configconfig_list 中。max_retry_periodretry_wait_time 已被弃用。可以为每个客户端设置 max_retries
  • MathChat 在未来版本中测试之前将不被支持。
  • autogen.Completionautogen.ChatCompletion 已弃用。主要功能已移至 autogen.OpenAIWrapper
from autogen import OpenAIWrapper
client = OpenAIWrapper(config_list=config_list)
response = client.create(messages=[{"role": "user", "content": "2+2="}])
print(client.extract_text_or_completion_object(response))
  • 推理参数调优和推理日志记录功能已更新:
import autogen.runtime_logging

# Start logging
autogen.runtime_logging.start()

# Stop logging
autogen.runtime_logging.stop()

查看Logging文档Logging示例笔记本以了解更多。

推理参数调优可以通过flaml.tune来完成。

  • seed in autogen is renamed into cache_seed to accommodate the newly added seed param in openai chat completion api. use_cache is removed as a kwarg in OpenAIWrapper.create() for being automatically decided by cache_seed: int | None. The difference between autogen's cache_seed and openai's seed is that:
    • autogen 使用本地磁盘缓存来确保相同的输入产生完全相同的输出,并且当命中缓存时,不会进行 openai api 调用。
    • openai的seed是一种尽力而为的确定性采样,并不保证完全的确定性。当使用openai的seed且将cache_seed设置为None时,即使对于相同的输入,也会调用openai api,并且无法保证获得完全相同的输出。