File tree Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Original file line number Diff line number Diff line change 7
7
from langchain_core .runnables import RunnableLambda
8
8
from langchain_core .prompts import ChatPromptTemplate
9
9
from langchain_core .output_parsers .string import StrOutputParser
10
+ from langchain_cohere import ChatCohere
11
+ from langchain_openai import ChatOpenAI , OpenAI
12
+ from langchain_google_genai import ChatGoogleGenerativeAI
10
13
11
14
from cat .auth .auth_utils import hash_password , DEFAULT_USER_USERNAME
12
15
from cat .auth .permissions import get_base_permissions
Original file line number Diff line number Diff line change 5
5
from fastapi import UploadFile
6
6
import inspect
7
7
from pydantic import BaseModel , ConfigDict
8
- from langchain . evaluation import StringDistance , load_evaluator , EvaluatorType
8
+ from rapidfuzz . distance import Levenshtein
9
9
from langchain_core .embeddings import Embeddings
10
10
from langchain_core .output_parsers import JsonOutputParser
11
11
from langchain_core .prompts import PromptTemplate
@@ -232,25 +232,18 @@ def explicit_error_message(e):
232
232
return error_description
233
233
234
234
235
- def levenshtein_distance (prediction : str , reference : str ) -> int :
236
- jaro_evaluator = load_evaluator (
237
- EvaluatorType .STRING_DISTANCE , distance = StringDistance .LEVENSHTEIN
238
- )
239
- result = jaro_evaluator .evaluate_strings (
240
- prediction = prediction ,
241
- reference = reference ,
242
- )
243
- return result ["score" ]
244
-
235
+ def levenshtein_distance (prediction : str , reference : str ) -> float :
236
+ res = Levenshtein .normalized_distance (prediction , reference )
237
+ return res
245
238
246
239
def parse_json (json_string : str , pydantic_model : BaseModel = None ) -> Dict :
247
240
# instantiate parser
248
241
parser = JsonOutputParser (pydantic_object = pydantic_model )
249
242
250
243
# clean to help small LLMs
251
244
replaces = {
252
- "\_" : "_" ,
253
- "\-" : "-" ,
245
+ "\\ _" : "_" ,
246
+ "\\ -" : "-" ,
254
247
"None" : "null" ,
255
248
"{{" : "{" ,
256
249
"}}" : "}" ,
You can’t perform that action at this time.
0 commit comments