Skip to content

Commit

Permalink
Merge pull request #848 from garylin2099/ci_dev
Browse files Browse the repository at this point in the history
add async fn type to tool schema
  • Loading branch information
garylin2099 authored Feb 6, 2024
2 parents cb402b7 + 5abc5c3 commit d2ed0da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions metagpt/environment/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
from enum import Enum
from typing import TYPE_CHECKING, Any, Iterable, Optional, Set, Union
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Set, Union

from pydantic import BaseModel, ConfigDict, Field, SerializeAsAny, model_validator

Expand Down Expand Up @@ -104,7 +104,7 @@ class Environment(ExtEnv):

desc: str = Field(default="") # 环境描述
roles: dict[str, SerializeAsAny["Role"]] = Field(default_factory=dict, validate_default=True)
member_addrs: dict["Role", Set] = Field(default_factory=dict, exclude=True)
member_addrs: Dict["Role", Set] = Field(default_factory=dict, exclude=True)
history: str = "" # For debug
context: Context = Field(default_factory=Context, exclude=True)

Expand Down
13 changes: 7 additions & 6 deletions metagpt/tools/tool_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ def convert_code_to_tool_schema(obj, include: list[str] = []):
# method_doc = inspect.getdoc(method)
method_doc = get_class_method_docstring(obj, name)
if method_doc:
function_type = "function" if not inspect.iscoroutinefunction(method) else "async_function"
schema["methods"][name] = {"type": function_type, **docstring_to_schema(method_doc)}
schema["methods"][name] = function_docstring_to_schema(method, method_doc)

elif inspect.isfunction(obj):
schema = {
"type": "function",
**docstring_to_schema(docstring),
}
schema = function_docstring_to_schema(obj, docstring)

return schema


def function_docstring_to_schema(fn_obj, docstring):
function_type = "function" if not inspect.iscoroutinefunction(fn_obj) else "async_function"
return {"type": function_type, **docstring_to_schema(docstring)}


def docstring_to_schema(docstring: str):
if docstring is None:
return {}
Expand Down
Loading

0 comments on commit d2ed0da

Please sign in to comment.