agentscope.utils.common module

Common utils.

agentscope.utils.common.timer(seconds: int | float | None = None) Generator[源代码]

A context manager that limits the execution time of a code block to a given number of seconds. The implementation of this contextmanager are borrowed from https://github.com/openai/human-eval/blob/master/human_eval/execution.py

备注

This function only works in Unix and MainThread, since signal.setitimer is only available in Unix.

agentscope.utils.common.create_tempdir() Generator[源代码]

A context manager that creates a temporary directory and changes the current working directory to it. The implementation of this contextmanager are borrowed from https://github.com/openai/human-eval/blob/master/human_eval/execution.py

agentscope.utils.common.to_openai_dict(item: dict) dict[源代码]

Convert Msg to dict for OpenAI API.

class agentscope.utils.common.ImportErrorReporter(error: ImportError, extras_require: str | None = None)[源代码]

基类:object

Used as a placeholder for missing packages. When called, an ImportError will be raised, prompting the user to install the specified extras requirement.

__init__(error: ImportError, extras_require: str | None = None) None[源代码]

Init the ImportErrorReporter.

参数:
  • error (ImportError) – the original ImportError.

  • extras_require (str) – the extras requirement.