From 341d05f78585eb1b3fd1da431757b0d71a6390e5 Mon Sep 17 00:00:00 2001
From: ali asaria <aliasaria@users.noreply.github.com>
Date: Wed, 26 Jun 2024 12:20:41 -0400
Subject: [PATCH] when you create a template, generate a friendly name

---
 .../Experiment/Train/TrainingModalLoRA.tsx    |   8 +-
 src/renderer/lib/utils.ts                     | 118 ++++++++++++++++++
 2 files changed, 122 insertions(+), 4 deletions(-)

diff --git a/src/renderer/components/Experiment/Train/TrainingModalLoRA.tsx b/src/renderer/components/Experiment/Train/TrainingModalLoRA.tsx
index 83684416..8276e5d2 100644
--- a/src/renderer/components/Experiment/Train/TrainingModalLoRA.tsx
+++ b/src/renderer/components/Experiment/Train/TrainingModalLoRA.tsx
@@ -31,6 +31,8 @@ const DefaultLoraConfig = {
   adaptor_name: '',
 };
 
+import { generateFriendlyName } from 'renderer/lib/utils';
+
 const fetcher = (url) => fetch(url).then((res) => res.json());
 
 export default function TrainingModalLoRA({
@@ -112,7 +114,7 @@ export default function TrainingModalLoRA({
       //This case is for when we are creating a new template
       setSelectedDataset(null);
       setConfig(DefaultLoraConfig);
-      setNameInput('');
+      setNameInput(generateFriendlyName());
     }
   }, [templateData]);
   // Once you have a dataset selected, we use SWR's dependency mode to fetch the
@@ -157,9 +159,6 @@ export default function TrainingModalLoRA({
           <Input
             required
             autoFocus
-            placeholder={
-              templateData ? templateData.name : 'Alpaca Training Job'
-            }
             value={nameInput} //Value needs to be stored in a state variable otherwise it will not update on change/update
             onChange={(e) => setNameInput(e.target.value)}
             name="template_name"
@@ -249,6 +248,7 @@ export default function TrainingModalLoRA({
                 JSON.stringify(formJson)
               );
             }
+            setNameInput(generateFriendlyName());
             onClose();
           }}
         >
diff --git a/src/renderer/lib/utils.ts b/src/renderer/lib/utils.ts
index d53d1f52..cb4b4984 100644
--- a/src/renderer/lib/utils.ts
+++ b/src/renderer/lib/utils.ts
@@ -66,3 +66,121 @@ export function filterByFilters(data, searchText = '', filters = {}) {
 }
 
 export const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
+
+function capFirst(string) {
+  return string.charAt(0).toUpperCase() + string.slice(1);
+}
+
+export function generateFriendlyName() {
+  console.log('Generating friendly name');
+  const adjectives = [
+    'adorable',
+    'beautiful',
+    'clean',
+    'drab',
+    'elegant',
+    'fancy',
+    'glamorous',
+    'handsome',
+    'long',
+    'magnificent',
+    'old-fashioned',
+    'plain',
+    'quaint',
+    'sparkling',
+    'ugliest',
+    'unsightly',
+    'angry',
+    'bewildered',
+    'clumsy',
+    'defeated',
+    'embarrassed',
+    'fierce',
+    'grumpy',
+    'helpless',
+    'itchy',
+    'jealous',
+    'lazy',
+    'mysterious',
+    'nervous',
+    'obnoxious',
+    'panicky',
+    'repulsive',
+    'scary',
+    'thoughtless',
+    'uptight',
+    'worried',
+  ];
+  const animals = [
+    'aardvark',
+    'alligator',
+    'alpaca',
+    'antelope',
+    'baboon',
+    'badger',
+    'bat',
+    'bear',
+    'beaver',
+    'buffalo',
+    'camel',
+    'cheetah',
+    'chimpanzee',
+    'chinchilla',
+    'chipmunk',
+    'cougar',
+    'cow',
+    'coyote',
+    'crocodile',
+    'crow',
+    'deer',
+    'dingo',
+    'dog',
+    'donkey',
+    'elephant',
+    'elk',
+    'ferret',
+    'fox',
+    'frog',
+    'gazelle',
+    'giraffe',
+    'gopher',
+    'grizzly',
+    'hedgehog',
+    'hippopotamus',
+    'hyena',
+    'ibex',
+    'iguana',
+    'impala',
+    'jackal',
+    'jaguar',
+    'kangaroo',
+    'koala',
+    'lemur',
+    'leopard',
+    'lion',
+    'llama',
+    'lynx',
+    'meerkat',
+    'mink',
+    'monkey',
+    'moose',
+    'narwhal',
+    'nyala',
+    'ocelot',
+    'opossum',
+    'otter',
+    'ox',
+    'panda',
+    'panther',
+    'porcupine',
+    'puma',
+    'rabbit',
+    'raccoon',
+    'ram',
+  ];
+
+  const name =
+    capFirst(adjectives[Math.floor(Math.random() * adjectives.length)]) +
+    capFirst(animals[Math.floor(Math.random() * animals.length)]);
+  return name;
+}
-- 
GitLab