Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServiceFactory to support quick setup for tools model&agent. #26

Merged
merged 8 commits into from
Feb 26, 2024

Conversation

DavdGao
Copy link
Collaborator

@DavdGao DavdGao commented Feb 4, 2024

Description

Target: Use ServiceFactory to help generate functions and JSON SCHEMA format dictionary that models can use.

Usage: Taking bing search as an example, the first argument to ServiceFactory.get is the function, following by keyword arguments that should be specified by developers. Then ServiceFactory.get returns

  • a function for llms to use and
  • a dict to introduce the function in JSON Schema format, which is compatible to OpenAI API

For open-source models, developers need to convert doc_dict to their required format.

_, doc_dict = ServiceFactory.get(
          bing_search,
          num_results=3,
          bing_api_key="xxx",
      )

print(doc_dict)
{
    "type": "function",
    "function": {
    "name": "bing_search",
    "description": "Search question in Bing Search API and return the searching results",
      "parameters": {
          "type": "object",
          "properties": {
              "question": {
                  "type": "string",
                  "description": "The search query string.",
              }
          },
          "required": ["question"],
      }
   }
}

Note

  • The descriptions are extracted from docstring, which means for developer-defined functions, docstring is required.
  • The types and default values of the arguments are extracted from function definition rather than docstring, which may be more accurate.
  • Documents will be updated after the modifications are confirmed.

Besides the major modification, these changes are also included in this PR:

  1. Add unit tests for service factory.
  2. Rename service/code to service/code_ to avoid duplicated name during debug in pycharm.
  3. Modify some service functions for llm to use.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

…into two functions to make the description more clear for model; 3. Rewrite partial docstring for model; 4. Add `ServiceFactory` for developers to extract tools from function and its docstring.
Copy link
Collaborator

@pan-x-c pan-x-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pan-x-c pan-x-c merged commit 7e2ceaa into modelscope:main Feb 26, 2024
3 checks passed
rayrayraykk pushed a commit that referenced this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants