File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change 7
7
from typing import Dict , Tuple
8
8
from pydantic import BaseModel , ConfigDict
9
9
10
- from langchain .evaluation import StringDistance , load_evaluator , EvaluatorType
10
+ from rapidfuzz .fuzz import ratio
11
+ from rapidfuzz .distance import Levenshtein
11
12
from langchain_core .output_parsers import JsonOutputParser
12
13
from langchain_core .prompts import PromptTemplate
13
14
from langchain_core .utils import get_colored_text
@@ -155,15 +156,8 @@ def deprecation_warning(message: str, skip=3):
155
156
156
157
157
158
def levenshtein_distance (prediction : str , reference : str ) -> int :
158
- jaro_evaluator = load_evaluator (
159
- EvaluatorType .STRING_DISTANCE , distance = StringDistance .LEVENSHTEIN
160
- )
161
- result = jaro_evaluator .evaluate_strings (
162
- prediction = prediction ,
163
- reference = reference ,
164
- )
165
- return result ["score" ]
166
-
159
+ res = Levenshtein .normalized_distance (prediction , reference )
160
+ return res
167
161
168
162
def parse_json (json_string : str , pydantic_model : BaseModel = None ) -> dict :
169
163
# instantiate parser
You can’t perform that action at this time.
0 commit comments