Skip to content

Refactor: streamline tool handling in chat.py #85

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SyedaAnshrahGillani
Copy link
Contributor

This pull request refactors the tool-handling logic in gpt_oss/chat.py to
improve code quality, reduce redundancy, and enhance maintainability.

Previously, the code for processing browser and python tools was nearly
identical, leading to duplication. This refactor introduces a more generic
and unified approach by:

  • Creating a single run_tool async function to handle different tool calls.
  • Using a dictionary to map tool names to their respective tool objects.
  • Replacing the repetitive if/elif block with a streamlined lookup and
    execution flow.

These changes make the code cleaner, easier to read, and simplifies the
process of adding new tools in the future.

@balajirajput96
Copy link

This pull request refactors the tool selection logic in the main function of gpt_oss/chat.py to make it more concise and maintainable. The changes simplify how browser and python tools are handled by unifying their logic into a single code path.

Tool selection and processing improvements:

  • Combined the handling of browser and python tool calls by introducing a tool_map dictionary and a unified code path, reducing code duplication and improving maintainability.
  • Simplified the asynchronous tool processing by using a single run_tool function for both tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants