From 568813f9daaa3f0761d2d8fa5afbf3cdb3897fda Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 16 Jun 2023 09:38:11 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(tabsContext.tsx):=20add=20func?= =?UTF-8?q?tions=20to=20generate=20random=20names=20and=20descriptions=20f?= =?UTF-8?q?or=20new=20flows=20=F0=9F=90=9B=20fix(utils.ts):=20fix=20import?= =?UTF-8?q?=20statement=20for=20ADJECTIVES,=20DESCRIPTIONS,=20and=20NOUNS?= =?UTF-8?q?=20constants=20The=20constants.tsx=20file=20now=20contains=20ar?= =?UTF-8?q?rays=20of=20adjectives,=20nouns,=20and=20descriptions=20that=20?= =?UTF-8?q?can=20be=20used=20to=20generate=20random=20names=20and=20descri?= =?UTF-8?q?ptions=20for=20new=20flows.=20The=20tabsContext.tsx=20file=20no?= =?UTF-8?q?w=20has=20functions=20that=20use=20these=20arrays=20to=20genera?= =?UTF-8?q?te=20random=20names=20and=20descriptions=20for=20new=20flows.?= =?UTF-8?q?=20The=20utils.ts=20file=20has=20been=20updated=20to=20fix=20th?= =?UTF-8?q?e=20import=20statement=20for=20the=20ADJECTIVES,=20DESCRIPTIONS?= =?UTF-8?q?,=20and=20NOUNS=20constants.=20=E2=9C=A8=20feat(constants.tsx):?= =?UTF-8?q?=20add=20arrays=20of=20adjectives,=20nouns,=20and=20description?= =?UTF-8?q?s=20for=20generating=20random=20names=20and=20descriptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/constants.tsx | 251 ++++++++++++++++++++++ src/frontend/src/contexts/tabsContext.tsx | 20 +- src/frontend/src/utils.ts | 42 +++- 3 files changed, 303 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/constants.tsx b/src/frontend/src/constants.tsx index e32336578..8dc05e7d9 100644 --- a/src/frontend/src/constants.tsx +++ b/src/frontend/src/constants.tsx @@ -148,3 +148,254 @@ export const EXPORT_CODE_DIALOG = */ export const INPUT_STYLE = " focus:ring-1 focus:ring-offset-1 focus:ring-ring focus:outline-none "; + +/** + * Default description for the flow + * @constant + */ +export const DESCRIPTIONS: string[] = [ + "Chain the Words, Master Language!", + "Language Architect at Work!", + "Empowering Language Engineering.", + "Craft Language Connections Here.", + "Create, Connect, Converse.", + "Smart Chains, Smarter Conversations.", + "Bridging Prompts for Brilliance.", + "Language Models, Unleashed.", + "Your Hub for Text Generation.", + "Promptly Ingenious!", + "Building Linguistic Labyrinths.", + "LangFlow: Create, Chain, Communicate.", + "Connect the Dots, Craft Language.", + "Interactive Language Weaving.", + "Generate, Innovate, Communicate.", + "Conversation Catalyst Engine.", + "Language Chainlink Master.", + "Design Dialogues with LangFlow.", + "Nurture NLP Nodes Here.", + "Conversational Cartography Unlocked.", + "Design, Develop, Dialogize.", +]; + +/** + * Adjectives for the name of the flow + * @constant + * + */ +export const ADJECTIVES: string[] = [ + "admiring", + "adoring", + "agitated", + "amazing", + "angry", + "awesome", + "backstabbing", + "berserk", + "big", + "boring", + "clever", + "cocky", + "compassionate", + "condescending", + "cranky", + "desperate", + "determined", + "distracted", + "dreamy", + "drunk", + "ecstatic", + "elated", + "elegant", + "evil", + "fervent", + "focused", + "furious", + "gigantic", + "gloomy", + "goofy", + "grave", + "happy", + "high", + "hopeful", + "hungry", + "insane", + "jolly", + "jovial", + "kickass", + "lonely", + "loving", + "mad", + "modest", + "naughty", + "nauseous", + "nostalgic", + "pedantic", + "pensive", + "prickly", + "reverent", + "romantic", + "sad", + "serene", + "sharp", + "sick", + "silly", + "sleepy", + "small", + "stoic", + "stupefied", + "suspicious", + "tender", + "thirsty", + "tiny", + "trusting", +]; + +/** + * Nouns for the name of the flow + * @constant + * + */ +export const NOUNS: string[] = [ + "albattani", + "allen", + "almeida", + "archimedes", + "ardinghelli", + "aryabhata", + "austin", + "babbage", + "banach", + "bardeen", + "bartik", + "bassi", + "bell", + "bhabha", + "bhaskara", + "blackwell", + "bohr", + "booth", + "borg", + "bose", + "boyd", + "brahmagupta", + "brattain", + "brown", + "carson", + "chandrasekhar", + "colden", + "cori", + "cray", + "curie", + "darwin", + "davinci", + "dijkstra", + "dubinsky", + "easley", + "einstein", + "elion", + "engelbart", + "euclid", + "euler", + "fermat", + "fermi", + "feynman", + "franklin", + "galileo", + "gates", + "goldberg", + "goldstine", + "goldwasser", + "golick", + "goodall", + "hamilton", + "hawking", + "heisenberg", + "heyrovsky", + "hodgkin", + "hoover", + "hopper", + "hugle", + "hypatia", + "jang", + "jennings", + "jepsen", + "joliot", + "jones", + "kalam", + "kare", + "keller", + "khorana", + "kilby", + "kirch", + "knuth", + "kowalevski", + "lalande", + "lamarr", + "leakey", + "leavitt", + "lichterman", + "liskov", + "lovelace", + "lumiere", + "mahavira", + "mayer", + "mccarthy", + "mcclintock", + "mclean", + "mcnulty", + "meitner", + "meninsky", + "mestorf", + "minsky", + "mirzakhani", + "morse", + "murdock", + "newton", + "nobel", + "noether", + "northcutt", + "noyce", + "panini", + "pare", + "pasteur", + "payne", + "perlman", + "pike", + "poincare", + "poitras", + "ptolemy", + "raman", + "ramanujan", + "ride", + "ritchie", + "roentgen", + "rosalind", + "saha", + "sammet", + "shaw", + "shirley", + "shockley", + "sinoussi", + "snyder", + "spence", + "stallman", + "stonebraker", + "swanson", + "swartz", + "swirles", + "tesla", + "thompson", + "torvalds", + "turing", + "varahamihira", + "visvesvaraya", + "volhard", + "wescoff", + "williams", + "wilson", + "wing", + "wozniak", + "wright", + "yalow", + "yonath", +]; diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index e9ef6e415..ba31a5621 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -8,7 +8,12 @@ import { } from "react"; import { FlowType, NodeType } from "../types/flow"; import { TabsContextType, TabsState } from "../types/tabs"; -import { updateIds, updateTemplate } from "../utils"; +import { + updateIds, + updateTemplate, + getRandomDescription, + getRandomName, +} from "../utils"; import { alertContext } from "./alertContext"; import { typesContext } from "./typesContext"; import { APITemplateType } from "../types/api"; @@ -40,7 +45,7 @@ const TabsContextInitialValue: TabsContextType = { uploadFlows: () => {}, uploadFlow: () => {}, hardReset: () => {}, - saveFlow: async (flow:FlowType) => {}, + saveFlow: async (flow: FlowType) => {}, disableCopyPaste: false, setDisableCopyPaste: (state: boolean) => {}, lastCopiedSelection: null, @@ -453,7 +458,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { if (newProject) { let flowData = extractDataFromFlow(flow); if (flowData.description == "") { - flowData.description = "This is a new flow."; + flowData.description = getRandomDescription(); } // Create a new flow with a default name if no flow is provided. @@ -535,7 +540,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { const createNewFlow = (flowData, flow) => ({ description: flowData.description, - name: flow?.name ?? "New Flow", + name: flow?.name ?? getRandomName(), data: flowData.data, id: "", }); @@ -564,10 +569,10 @@ export function TabsProvider({ children }: { children: ReactNode }) { } async function saveFlow(newFlow: FlowType) { - try{ + try { // updates flow in db const updatedFlow = await updateFlowInDatabase(newFlow); - if (updatedFlow){ + if (updatedFlow) { // updates flow in state setFlows((prevState) => { const newFlows = [...prevState]; @@ -589,8 +594,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { }; }); } - } - catch(err){ + } catch (err) { setErrorData(err); } } diff --git a/src/frontend/src/utils.ts b/src/frontend/src/utils.ts index 8859b3050..f391fd8c0 100644 --- a/src/frontend/src/utils.ts +++ b/src/frontend/src/utils.ts @@ -41,7 +41,7 @@ import { SearxIcon } from "./icons/Searx"; import { SlackIcon } from "./icons/Slack"; import clsx, { ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; -import { WeaviateIcon } from "./icons/Weaviate"; +import { ADJECTIVES, DESCRIPTIONS, NOUNS } from "./constants"; export function classNames(...classes: Array) { return classes.filter(Boolean).join(" "); @@ -213,7 +213,6 @@ export const gradients = [ "bg-gradient-to-br from-green-500 to-green-700", "bg-gradient-to-br from-rose-400 via-fuchsia-500 to-indigo-500", "bg-gradient-to-br from-sky-400 to-blue-500", - ]; export const bgColors = { @@ -773,3 +772,42 @@ export function validateNodes(reactFlowInstance: ReactFlowInstance) { .getNodes() .flatMap((n: NodeType) => validateNode(n, reactFlowInstance)); } + +export function getRandomElement(array: T[]): T { + return array[Math.floor(Math.random() * array.length)]; +} +export function getRandomDescription(): string { + return getRandomElement(DESCRIPTIONS); +} + +export function getRandomName( + retry: number = 0, + noSpace: boolean = false, + maxRetries: number = 3 +): string { + const left: string[] = ADJECTIVES; + const right: string[] = NOUNS; + + const lv = getRandomElement(left); + const rv = getRandomElement(right); + + // Condition to avoid "boring wozniak" + if (lv === "boring" && rv === "wozniak") { + if (retry < maxRetries) { + return getRandomName(retry + 1, noSpace, maxRetries); + } else { + console.warn("Max retries reached, returning as is"); + } + } + + // Append a suffix if retrying and noSpace is true + if (retry > 0 && noSpace) { + const retrySuffix = Math.floor(Math.random() * 10); + return `${lv}_${rv}${retrySuffix}`; + } + + // Construct the final name + let final_name = noSpace ? `${lv}_${rv}` : `${lv} ${rv}`; + // Return title case final name + return toTitleCase(final_name); +}