build(ui/): show created tags in dropdown

makes it easier for admin to add tags to keys
This commit is contained in:
Krrish Dholakia 2024-11-23 18:03:39 +05:30
parent 43e0b52f6f
commit 829199d538
2 changed files with 32 additions and 2 deletions

View file

@ -160,7 +160,10 @@ def key_generation_check(
""" """
Check if admin has restricted key creation to certain roles for teams or individuals Check if admin has restricted key creation to certain roles for teams or individuals
""" """
if litellm.key_generation_settings is None: if (
litellm.key_generation_settings is None
or user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN.value
):
return True return True
## check if key is for team or individual ## check if key is for team or individual

View file

@ -40,6 +40,31 @@ interface CreateKeyProps {
setData: React.Dispatch<React.SetStateAction<any[] | null>>; setData: React.Dispatch<React.SetStateAction<any[] | null>>;
} }
const getPredefinedTags = (data: any[] | null) => {
let allTags = [];
console.log("data:", JSON.stringify(data));
if (data) {
for (let key of data) {
if (key["metadata"] && key["metadata"]["tags"]) {
allTags.push(...key["metadata"]["tags"]);
}
}
}
// Deduplicate using Set
const uniqueTags = Array.from(new Set(allTags)).map(tag => ({
value: tag,
label: tag,
}));
console.log("uniqueTags:", uniqueTags);
return uniqueTags;
}
const CreateKey: React.FC<CreateKeyProps> = ({ const CreateKey: React.FC<CreateKeyProps> = ({
userID, userID,
team, team,
@ -55,6 +80,8 @@ const CreateKey: React.FC<CreateKeyProps> = ({
const [userModels, setUserModels] = useState([]); const [userModels, setUserModels] = useState([]);
const [modelsToPick, setModelsToPick] = useState([]); const [modelsToPick, setModelsToPick] = useState([]);
const [keyOwner, setKeyOwner] = useState("you"); const [keyOwner, setKeyOwner] = useState("you");
const [predefinedTags, setPredefinedTags] = useState(getPredefinedTags(data));
const handleOk = () => { const handleOk = () => {
setIsModalVisible(false); setIsModalVisible(false);
@ -361,7 +388,7 @@ const CreateKey: React.FC<CreateKeyProps> = ({
style={{ width: '100%' }} style={{ width: '100%' }}
placeholder="Enter tags" placeholder="Enter tags"
tokenSeparators={[',']} tokenSeparators={[',']}
open={false} options={predefinedTags}
/> />
</Form.Item> </Form.Item>
</AccordionBody> </AccordionBody>