mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
correctly add modified tool names to cache
This commit is contained in:
parent
42617c207a
commit
d445f3967d
1 changed files with 12 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import copy
|
||||
import json
|
||||
import re
|
||||
import traceback
|
||||
|
|
@ -2310,13 +2311,20 @@ def make_valid_bedrock_tool_name(input_tool_name: str) -> str:
|
|||
# If the string is empty, return a default valid identifier
|
||||
if input_tool_name is None or len(input_tool_name) == 0:
|
||||
return input_tool_name
|
||||
|
||||
bedrock_tool_name = copy.copy(input_tool_name)
|
||||
# If it doesn't start with a letter, prepend 'a'
|
||||
if not input_tool_name[0].isalpha():
|
||||
input_tool_name = "a" + input_tool_name
|
||||
if not bedrock_tool_name[0].isalpha():
|
||||
bedrock_tool_name = "a" + bedrock_tool_name
|
||||
|
||||
# Replace any invalid characters with underscores
|
||||
valid_string = "".join(replace_invalid(char) for char in input_tool_name)
|
||||
valid_string = "".join(replace_invalid(char) for char in bedrock_tool_name)
|
||||
|
||||
if input_tool_name != valid_string:
|
||||
# passed tool name was formatted to become valid
|
||||
# store it internally so we can use for the response
|
||||
litellm.bedrock_tool_name_mappings.set_cache(
|
||||
key=valid_string, value=input_tool_name
|
||||
)
|
||||
|
||||
return valid_string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue