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

feat: Multiple functions in openai dynamic routes #265

Merged
merged 59 commits into from
May 13, 2024

Conversation

Siraj-Aizlewood
Copy link
Contributor

@Siraj-Aizlewood Siraj-Aizlewood commented May 1, 2024

Type

enhancement, bug_fix


Description

  • Updated various components to support handling multiple function schemas instead of a single schema.
  • Enhanced the OpenAI LLM integration to handle multiple function schemas, including adjustments in input validation and response handling.
  • Refactored utility functions to support the generation of schemas for multiple items and added new tests for these changes.
  • Updated documentation and example notebooks to align with the new handling of multiple function schemas.

Changes walkthrough

Relevant files
Enhancement
6 files
layer.py
Update Layer Call Logic to Handle Multiple Function Schemas

semantic_router/layer.py

  • Updated conditional checks to use function_schemas instead of
    function_schema.
  • Adjusted error messages to align with the new schema handling.
  • +2/-2     
    base.py
    Refactor Base LLM for Multiple Function Schemas Support   

    semantic_router/llms/base.py

  • Refactored input validation to support multiple function schemas.
  • Added a method to extract parameter information from function
    signatures.
  • Updated the LLM input prompt to handle multiple function schemas.
  • +101/-43
    openai.py
    Enhance OpenAI LLM to Support Multiple Function Schemas   

    semantic_router/llms/openai.py

  • Added handling for multiple function schemas in the OpenAI LLM calls.
  • Implemented a method to extract tool calls information from OpenAI
    responses.
  • Adjusted the OpenAI LLM call method to optionally include function
    schemas.
  • +54/-5   
    route.py
    Update Route Handling to Support Multiple Function Schemas

    semantic_router/route.py

  • Changed function_schema to function_schemas to support multiple
    schemas.
  • Updated the dynamic route generation to handle a list of function
    schemas.
  • +20/-19 
    schema.py
    Update RouteChoice Model for Multiple Function Calls         

    semantic_router/schema.py

  • Updated RouteChoice model to potentially handle multiple function
    calls.
  • +1/-1     
    function_call.py
    Refactor Function Call Utilities for Multiple Schemas       

    semantic_router/utils/function_call.py

  • Refactored to generate schemas for multiple items.
  • Added utility functions to convert parameter types to JSON types.
  • +93/-25 
    Tests
    1 files
    test_llm_openai.py
    Extend Tests for OpenAI LLM with Multiple Function Schemas

    tests/unit/llms/test_llm_openai.py

  • Added tests for handling multiple function schemas in OpenAI LLM.
  • Tested new utility functions for parameter type conversion.
  • +152/-0 
    Documentation
    4 files
    02-dynamic-routes.ipynb
    Update Documentation for Dynamic Routes with Multiple Function Schemas

    docs/02-dynamic-routes.ipynb

  • Updated documentation to reflect the handling of multiple function
    schemas in dynamic routes.
  • +179/-30
    05-local-execution.ipynb
    Documentation Update for Local Execution with Multiple Schemas

    docs/05-local-execution.ipynb

    • Adjusted example code to use a list of function schemas.
    +2/-2     
    function_calling.ipynb
    Update Example Notebook for Function Calling                         

    docs/examples/function_calling.ipynb

  • Updated example notebook to reflect no specific function schema being
    used.
  • +1/-1     
    ollama-local-execution.ipynb
    Update Ollama Local Execution Example for Multiple Schemas

    docs/examples/ollama-local-execution.ipynb

    • Updated example to use a list of function schemas.
    +1/-1     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Siraj-Aizlewood and others added 27 commits April 27, 2024 02:24
    Also showcasing that other (non-dynamic) routes, and choosing no route work as expected.
    It was previously (incorrectly) stating that the dynamic route generates functions.
    We don't have OpenAI Function Calling Dynamic Routes as an alternative to regular dynamic routes any more, it is now the default.
    we don't use openai_function_schema anymore.
    @github-actions github-actions bot added enhancement Enhancement to existing features bug_fix labels May 1, 2024
    Copy link

    github-actions bot commented May 1, 2024

    PR Description updated to latest commit (a9af91a)

    If a single function schema is provided for a Route, then we use OpenAIs inbuilt function calling to determine arguments from the utterance.
    
    if more than one function schema is provided then we use our custom prompt.
    Also testing and minor bug fixing in Notebook 04 regarding Conversation object and calling the splitter.
    @Siraj-Aizlewood Siraj-Aizlewood changed the title WIP - Multiple functions in openai dynamic routes feat: Multiple functions in openai dynamic routes May 7, 2024
    Copy link

    codecov bot commented May 7, 2024

    Codecov Report

    Attention: Patch coverage is 93.01075% with 13 lines in your changes are missing coverage. Please review.

    Project coverage is 80.90%. Comparing base (705e604) to head (0de054c).

    Files Patch % Lines
    semantic_router/utils/function_call.py 57.14% 9 Missing ⚠️
    semantic_router/llms/openai.py 96.00% 4 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main     #265      +/-   ##
    ==========================================
    + Coverage   80.31%   80.90%   +0.59%     
    ==========================================
      Files          44       44              
      Lines        2443     2582     +139     
    ==========================================
    + Hits         1962     2089     +127     
    - Misses        481      493      +12     

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @jamescalam jamescalam merged commit 8cf0234 into main May 13, 2024
    8 checks passed
    @jamescalam jamescalam deleted the multiple_functions_in_openai_dynamic_routes branch May 13, 2024 12:43
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    bug_fix enhancement Enhancement to existing features Review effort [1-5]: 4
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants