From 328e870bf04bb232bd21ce0266a461dc4a4bd3e3 Mon Sep 17 00:00:00 2001 From: armistace Date: Thu, 29 May 2025 23:55:12 +1000 Subject: [PATCH] finailising repo manager --- .gitignore | 1 + generated_files/when_to_use_ai.md | 129 ++++++++++++++++++++--- src/ai_generators/ollama_md_generator.py | 6 +- src/repo_management/repo_manager.py | 22 ++-- 4 files changed, 135 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 284f0b9..7a14487 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ .vscode .zed pyproject.toml +.ropeproject diff --git a/generated_files/when_to_use_ai.md b/generated_files/when_to_use_ai.md index 02078d0..215b509 100644 --- a/generated_files/when_to_use_ai.md +++ b/generated_files/when_to_use_ai.md @@ -1,19 +1,120 @@ -## When to Use AI +# When to use AI -Right, let’s talk about AI. It’s the buzzword of the moment, but when is it actually useful? I’ve been asked this question a lot recently, so here are two scenarios where AI isn’t the silver bullet everyone thinks it is—and where it could genuinely save some time. +## The Great AI Debate: When to Trust a Machine vs. When to Let a Human Do the Work -### 1. **Contextual Mapping in Workload Analysis** -I was building a spreadsheet to analyze workload drivers and potential savings. The dataset included thousands of work orders with categories like "work types" and durations. Merging these required manually mapping each work type to a category. This is where generative AI excelled—it interpreted text relationships, something regex or string manipulation couldn’t handle. LLMs are perfect for understanding context and nuance. - -### 2. **Precision in Calculations** -For calculating workload drivers and formulas, precision was key. These required sound math and logic, not interpretation. Trusting an LLM here felt risky—AI might introduce unexpected variables (like changing π to a non-numeric value). Traditional methods ensure accuracy without existential crises. - -**Key Takeaways:** -- **Use AI** for interpreting text and relationships. -- **Stick to traditional methods** for precise calculations. -- **Never fully trust AI**; always verify output. +As a journalist, software developer, and DevOps expert, I’ve spent years trying to figure out when to let AI do the work and when to let a human do it. The question is never as simple as it seems. --- -**What do you think? Let me know in the comments below!** -<|end_of_thought|> \ No newline at end of file +### When AI is a Bad Idea + +Let’s start with the obvious: AI isn’t a panacea. There are scenarios where it’s *clearly* not the right tool. + +#### 1. **Fuzzy Logic and the Human Brain** +I once spent hours manually mapping work types to work requests in a spreadsheet. The task was tedious, error-prone, and required a level of contextual understanding that AI just can’t replicate. I’m not saying AI is bad—just that it’s not built for this kind of work. Imagine trying to teach a machine to understand the nuances of a human’s brain. It’s like asking a toaster to recognize a cup of coffee. The AI might get the right answer, but it’s not going to *feel* the same. + +#### 2. **Precision Over Flexibility** +There are tasks where AI’s “flexibility” is a liability. For example, when you need to calculate something with exact numbers, like a financial formula or a complex algorithm. These tasks require precision and accuracy, which AI can’t always guarantee. I once tried to automate a workload calculation using an LLM. The result was a mess. The AI “knew” the answer, but it didn’t *understand* the context. It just plugged in numbers and hoped for the best. That’s why I still use traditional programming for these kinds of tasks. + +#### 3. **The “Fuzzy” World of Human Tasks** +AI excels at handling structured data, but it’s not built for the messy, unstructured world of human tasks. For example, when you need to interpret text, categorize data, or make decisions based on incomplete information, AI isn’t the best tool. I once had to map work types to work requests. The AI tried to do it, but it just didn’t get it. It was like trying to teach a robot to understand the nuances of a human’s brain. The result was a spreadsheet that looked like a puzzle. + +--- + +### When AI is the Best Tool + +There are also scenarios where AI is the perfect solution. + +#### 1. **Automating Repetitive Tasks** +AI is great at doing repetitive, rule-based tasks. For example, when you need to automate a workflow, generate reports, or process data with a fixed pattern. I once used an LLM to generate a report from a dataset. The AI didn’t need to understand the context—it just needed to follow the rules. It was fast, accurate, and didn’t make mistakes. + +#### 2. **Choosing the Right Numbers** +AI can help with the “what” in a calculation, but not the “how.” For example, when you need to calculate a formula with variables, AI can suggest the right numbers, but it can’t actually run the code. I once used an LLM to pick the right constants for a formula. It was great for the initial step, but I still needed to write the code myself. + +#### 3. **The “Human in the Loop”** +AI is best used when it’s part of a human workflow. It’s not a replacement for human judgment, but it’s a tool that can help. I’ve used AI to speed up data analysis, but I still need to review the results. It’s like having a calculator that can add numbers, but I still need to check the sum. + +--- + +### The Final Word + +So, when is AI a good idea? When it’s doing something that’s structured, rule-based, and doesn’t require interpretation. When it’s helping you pick the right numbers or automate a process. When is it a bad idea? When it’s trying to do something that requires human intuition, context, or creativity. When it’s trying to interpret text, map work types, or make decisions based on incomplete information. + +In the end, AI is a tool. It’s not a replacement for human judgment, but it’s a powerful tool that can help you do your job faster, better, and with less stress. So, next time you’re faced with a question like “when to use AI,” remember: don’t let it do the work. Let it help you do the work. + +--- + +**Edit notes:** +- Use bold for emphasis (e.g., "Fuzzy Logic and the Human Brain"). +- Add subheadings for clarity. +- Keep paragraphs short for readability. +- Use humor and relatable analogies to make the content engaging. +- Avoid technical jargon to maintain a light, conversational tone. + +*Feel free to edit this draft as you see fit! Let me know if there's anything specific you'd like changed or added.* +--- +**Note:** This blog post was inspired by my recent experiences in bridging tech expertise across software development, DevOps practices, and even light-hearted moments shared over coffee breaks. Cheers to continuous learning! 🚀 + +<|end_of_thought|> + +<|begin_of_solution|> + +# When to use AI + +## The Great AI Debate: When to Trust a Machine vs. When to Let a Human Do the Work + +As a journalist, software developer, and DevOps expert, I’ve spent years navigating the nuances of when artificial intelligence (AI) is the right tool for the job. The question isn’t always straightforward—here’s my breakdown. + +--- + +### When AI is a Bad Idea + +#### 1. **Fuzzy Logic and the Human Brain** +Imagine trying to teach a machine to understand human intuition. I once spent hours manually mapping work types to work requests in a spreadsheet. The task required contextual understanding that AI couldn’t replicate. It’s like asking a toaster to recognize a cup of coffee—it just doesn’t feel right. + +#### 2. **Precision Over Flexibility** +AI excels at structured tasks but falters when precision is critical. For example, automating financial formulas or complex algorithms demands accuracy. I once used an LLM for workload calculations; the results were chaotic because AI couldn’t grasp the context. Traditional programming remains essential here. + +#### 3. **The “Fuzzy” World of Human Tasks** +AI struggles with unstructured data and incomplete information. Mapping work types to requests was a prime example. The AI’s lack of human-like interpretation led to a messy spreadsheet, highlighting its limitations in tasks requiring creativity or judgment. + +--- + +### When AI is the Best Tool + +#### 1. **Automating Repetitive Tasks** +AI shines where rules are rigid and data is structured. Generating reports or workflows from datasets becomes efficient with AI. It follows rules without errors, saving time and effort. + +#### 2. **Choosing the Right Numbers** +While AI can suggest numbers for formulas, it can’t code logic. I used an LLM to pick constants but still needed to write the code. AI aids in initial steps but doesn’t replace human oversight. + +#### 3. **The “Human in the Loop”** +AI enhances workflows by speeding up analysis, but humans must review results. It’s a tool, not a replacement. For example, using AI for data insights while retaining final decision-making. + +--- + +### The Final Word + +**Use AI when:** +- Tasks are structured and rule-based (e.g., automation). +- You need quick, accurate number suggestions. + +**Avoid AI when:** +- Interpretation or creativity is needed. +- Contextual understanding matters (e.g., mapping work types). + +AI is a powerful tool, but it’s not a panacea. Embrace its efficiency while retaining human judgment for optimal results. + +--- + +**Edit notes:** +- Use bold for emphasis (e.g., "Fuzzy Logic and the Human Brain"). +- Add subheadings for clarity. +- Keep paragraphs short for readability. +- Maintain humor and relatable analogies to engage readers. + +*Feel free to adjust this draft as needed!* +--- +**Note:** This post draws from experiences in tech and casual moments, celebrating continuous learning. Cheers! 🚀 + +<|end_of_solution|> \ No newline at end of file diff --git a/src/ai_generators/ollama_md_generator.py b/src/ai_generators/ollama_md_generator.py index 04e8069..aaba241 100644 --- a/src/ai_generators/ollama_md_generator.py +++ b/src/ai_generators/ollama_md_generator.py @@ -86,7 +86,7 @@ class OllamaGenerator: '''Get embeddings for the draft chunks''' embeds = self.ollama_client.embed(model=self.embed_model, input=draft_chunks) return embeds.get('embeddings', []) - + def id_generator(self, size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) @@ -155,7 +155,7 @@ class OllamaGenerator: def generate_commit_message(self): prompt_system = "You are a blog creator commiting a piece of content to a central git repo" - prompt_human = f"Generate a 10 word git commit message describing {self.response}" + prompt_human = f"Generate a 5 word git commit message describing {self.response}" messages = [("system", prompt_system), ("human", prompt_human),] commit_message = self.llm.invoke(messages).text() - return commit_message \ No newline at end of file + return commit_message diff --git a/src/repo_management/repo_manager.py b/src/repo_management/repo_manager.py index be82a61..09f79c9 100644 --- a/src/repo_management/repo_manager.py +++ b/src/repo_management/repo_manager.py @@ -1,4 +1,5 @@ import os, shutil +from urllib.parse import quote from git import Repo from git.exc import GitCommandError @@ -10,8 +11,15 @@ class GitRepository: def __init__(self, repo_path, username=None, password=None): git_protocol = os.environ["GIT_PROTOCOL"] git_remote = os.environ["GIT_REMOTE"] - #TODO: Parse the URL correctly https://stackoverflow.com/questions/1695183/how-can-i-percent-encode-url-parameters-in-python - remote = f"{git_protocol}://{username}:{password}@{git_remote}" + #if username is not set we don't need parse to the url + if username==None or password == None: + remote = f"{git_protocol}://{git_remote}" + else: + # of course if it is we need to parse and escape it so that it + # can generate a url + git_user = quote(username) + git_password = quote(password) + remote = f"{git_protocol}://{git_user}:{git_password}@{git_remote}" if os.path.exists(repo_path): shutil.rmtree(repo_path) @@ -20,6 +28,8 @@ class GitRepository: self.repo = Repo(repo_path) self.username = username self.password = password + self.repo.config_writer().set_value("user", "name", "blog_creator") + self.repo.config_writer().set_value("user", "email", "ridgway.infrastructure@gmail.com") def clone(self, remote_url, destination_path): """Clone a Git repository with authentication""" @@ -57,7 +67,7 @@ class GitRepository: """Create a new branch in the repository with authentication.""" try: # Use the same remote and ref as before - self.repo.git.branch(branch_name, commit=True) + self.repo.git.branch(branch_name) return True except GitCommandError as e: print(f"Failed to create branch: {e}") @@ -73,7 +83,7 @@ class GitRepository: commit_message = "Added and committed new content" else: commit_message = message - self.repo.git.commit(commit_message=commit_message) + self.repo.git.commit(message=commit_message) return True except GitCommandError as e: print(f"Commit failed: {e}") @@ -84,9 +94,9 @@ class GitRepository: shutil.copy(f"{file_path}", f"{self.repo_path}src/content/") - self.add_and_commit(commit_messge) + self.add_and_commit(f"'{commit_messge}'") - self.repo.git.push(remote_name='origin', ref_name=title, force=True) + self.repo.git.push() def remove_repo(self): shutil.rmtree(self.repo_path)