agentscope.utils.common module

Common utils.

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

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

Note

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

agentscope.utils.common.create_tempdir() Generator[source]

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[source]

Convert Msg to dict for OpenAI API.

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

Bases: 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[source]

Init the ImportErrorReporter.

Parameters:
  • error (ImportError) – the original ImportError.

  • extras_require (str) – the extras requirement.