- 
                Notifications
    
You must be signed in to change notification settings  - Fork 35
 
add bfcl utility #174
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
      
      
            lchen001
  wants to merge
  6
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
lingjiao/bfcl_util
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    add bfcl utility #174
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      682b1cc
              
                add bfcl utility
              
              
                lchen001 1f56767
              
                update the doc strings and add some comments
              
              
                lchen001 0469c8f
              
                update setup for bfcl_eval
              
              
                lchen001 03c5867
              
                add bfcl_eval
              
              
                lchen001 a65926e
              
                incorporate feedback
              
              
                lchen001 96c65d7
              
                Merge branch 'main' into lingjiao/bfcl_util
              
              
                lchen001 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import re, ast | ||
| from dataclasses import dataclass | ||
| 
     | 
||
| import pandas as pd | ||
| from bfcl_eval.eval_checker.multi_turn_eval.multi_turn_utils import ( | ||
| execute_multi_turn_func_call, | ||
| ) | ||
| 
     | 
||
| from .transform import DFTransformBase | ||
| 
     | 
||
| 
     | 
||
| @dataclass | ||
| class BFCLMultiturnExecuteCall(DFTransformBase): | ||
| model_output_column: str | ||
| model_answer_column: str | ||
| 
     | 
||
| def transform(self, df: pd.DataFrame) -> pd.DataFrame: | ||
| df[self.model_answer_column] = df.apply(self.execuate_model_output, axis=1) | ||
| return df | ||
| 
     | 
||
| @staticmethod | ||
| def execuate_model_output(df_row): | ||
| """ | ||
| Execute the model output to get the function output. | ||
| 
     | 
||
| Parameters: | ||
| df_row (a row in dataframe): Input is a dataframe row containing model_output, initial_config, and, involved_classes. | ||
| Returns: | ||
| " ".join(execution_results) (str): A string denoting the execution of the function calls. | ||
| """ | ||
| test_entry = df_row | ||
| response_text = test_entry["model_output"] | ||
| try: | ||
| initial_config = ast.literal_eval(test_entry["initial_config"]) | ||
| except (ValueError, SyntaxError) as e: | ||
| raise ValueError(f"Invalid initial_config format: {test_entry['initial_config']}") from e | ||
| try: | ||
| involved_classes: list = eval(test_entry["involved_classes"]) | ||
| except (ValueError, SyntaxError) as e: | ||
| raise ValueError(f"Invalid involved_classes format: {test_entry['involved_classes']}") from e | ||
| test_entry_id: str = test_entry["id"] | ||
| test_category: str = test_entry_id.rsplit("_", 1)[0] | ||
| 
     | 
||
| func_calls = re.findall(r"\w+\([^)]*\)", response_text) | ||
| if len(func_calls) == 0: | ||
| return "No call executed" | ||
| 
     | 
||
| execution_results, involved_instances = execute_multi_turn_func_call( | ||
| func_call_list=func_calls, | ||
| initial_config=initial_config, | ||
| involved_classes=involved_classes, | ||
| model_name="", | ||
| test_entry_id=test_entry_id, | ||
| long_context=("long_context" in test_category or "composite" in test_category), | ||
| is_evaL_run=False, | ||
| ) | ||
| return " ".join(execution_results) | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from bfcl_eval.eval_checker.multi_turn_eval.multi_turn_checker import ( | ||
| multi_turn_checker, | ||
| ) | ||
| 
     | 
||
| from eureka_ml_insights.metrics.metrics_base import ClassicMetric | ||
| 
     | 
||
| 
     | 
||
| class BFCLMultiturnMatch(ClassicMetric): | ||
                
      
                  lchen001 marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| """This metric class checks if the generated function calls match the ground-truth.""" | ||
| 
     | 
||
| def __init__( | ||
| self, | ||
| model_output_col: str = "model_output", | ||
| ground_truth_col: str = "ground_truth", | ||
| initial_config_col: str = "initial_config", | ||
| involved_classes_col: str = "involved_classes", | ||
| test_entry_id_col: str = "id", | ||
| ): | ||
| super().__init__() | ||
| self.model_output_col = model_output_col | ||
| self.ground_truth_col = ground_truth_col | ||
| self.initial_config_col = initial_config_col | ||
| self.involved_classes_col = involved_classes_col | ||
| self.test_entry_id_col = test_entry_id_col | ||
| 
     | 
||
| def __evaluate__(self, answer_text, target_text, initial_config, involved_classes, test_entry_id): | ||
| test_entry = { | ||
| "initial_config": eval(initial_config), | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also?  | 
||
| "involved_classes": eval(involved_classes), | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these also?  | 
||
| "id": test_entry_id, | ||
| } | ||
| test_category = "" # following the bfcl_eval's original eval code. | ||
| model_name = "" # following the bfcl_eval's original eval code. | ||
| multi_turn_ground_truth_list = eval(target_text) | ||
                
      
                  lchen001 marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| accuracy_checker_result = multi_turn_checker( | ||
| answer_text, | ||
| multi_turn_ground_truth_list, | ||
| test_entry, | ||
| test_category, | ||
| model_name, | ||
| ) | ||
| return str(accuracy_checker_result["valid"]) | ||
| 
     | 
||
| def evaluate(self, data): | ||
| self.validate_data(data) | ||
| data[self.__class__.__name__ + "_result"] = data.apply( | ||
| lambda x: self.__evaluate__( | ||
| x[self.model_output_col], | ||
| x[self.ground_truth_col], | ||
| x[self.initial_config_col], | ||
| x[self.involved_classes_col], | ||
| x[self.test_entry_id_col], | ||
| ), | ||
| axis=1, | ||
| ) | ||
| return data | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be literal_eval too?