testing
This commit is contained in:
@@ -4,21 +4,24 @@ from ollama import Client
|
||||
|
||||
class OllamaGenerator:
|
||||
|
||||
def __init__(self, title: str, content: str):
|
||||
def __init__(self, title: str, content: str, model: str):
|
||||
self.title = title
|
||||
self.content = content
|
||||
self.ollama_client = Client(host=f"""
|
||||
{os.getenv('OLLAMA_PROTOCOL')}://{os.getenv('OLLAMA_HOST')}:{os.getenv('OLLAMA_PORT')}
|
||||
"""
|
||||
)
|
||||
ollama_url = f"{os.environ["OLLAMA_PROTOCOL"]}://{os.environ["OLLAMA_HOST"]}:{os.environ["OLLAMA_PORT"]}"
|
||||
self.ollama_client = Client(host=ollama_url)
|
||||
self.ollama_model = model
|
||||
|
||||
def generate_markdown(self) -> str:
|
||||
|
||||
prompt = f"""
|
||||
Generate a 1000 word blog as a markdown document.
|
||||
You are a Software Developer and DevOps expert
|
||||
writing a 1000 word blog for other engineers.
|
||||
You like to use very small and minimal code examples and prefer to talk
|
||||
in a light comedic tone
|
||||
As this person write this blog as a markdown document.
|
||||
The title for the blog is {self.title}.
|
||||
Do not output the title in the markdown.
|
||||
The content for the blog is:
|
||||
The basis for the content of the blog is:
|
||||
{self.content}
|
||||
Only output markdown DO NOT GENERATE AN EXPLANATION
|
||||
"""
|
||||
@@ -30,6 +33,7 @@ class OllamaGenerator:
|
||||
'content': f'{prompt}',
|
||||
},
|
||||
])
|
||||
return self.response['message']['content']
|
||||
|
||||
except Exception as e:
|
||||
raise Exception(f"Failed to generate markdown: {e}")
|
||||
|
||||
+5
-6
@@ -6,6 +6,7 @@ tril = tn.TrilumNotes()
|
||||
tril.get_new_notes()
|
||||
tril_notes = tril.get_notes_content()
|
||||
|
||||
|
||||
def convert_to_lowercase_with_underscores(string):
|
||||
return string.lower().replace(" ", "_")
|
||||
|
||||
@@ -14,10 +15,8 @@ for note in tril_notes:
|
||||
print(tril_notes[note]['title'])
|
||||
print(tril_notes[note]['content'])
|
||||
print("Generating Document")
|
||||
ai_gen = omg.OllamaGenerator(tril_notes[note]['title'],
|
||||
tril_notes[note]['content'])
|
||||
ai_gen = omg.OllamaGenerator(tril_notes[note]['title'],
|
||||
tril_notes[note]['content'],
|
||||
"zephyr")
|
||||
os_friendly_title = convert_to_lowercase_with_underscores(tril_notes[note]['title'])
|
||||
omg.save_to_file(f"{os_friendly_title}.md")
|
||||
|
||||
|
||||
|
||||
ai_gen.save_to_file(f"/blog_creator/generated_files/{os_friendly_title}.md")
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
import sys
|
||||
from git import Repo
|
||||
|
||||
# Set these variables accordingly
|
||||
REPO_OWNER = "your_repo_owner"
|
||||
REPO_NAME = "your_repo_name"
|
||||
|
||||
def clone_repo(repo_url, branch="main"):
|
||||
Repo.clone_from(repo_url, ".", branch=branch)
|
||||
|
||||
def create_markdown_file(file_name, content):
|
||||
with open(f"{file_name}.md", "w") as f:
|
||||
f.write(content)
|
||||
|
||||
def commit_and_push(file_name, message):
|
||||
repo = Repo(".")
|
||||
repo.index.add([f"{file_name}.md"])
|
||||
repo.index.commit(message)
|
||||
repo.remote().push()
|
||||
|
||||
def create_new_branch(branch_name):
|
||||
repo = Repo(".")
|
||||
repo.create_head(branch_name).checkout()
|
||||
repo.head.reference.set_tracking_url(f"https://your_git_server/{REPO_OWNER}/{REPO_NAME}.git/{branch_name}")
|
||||
repo.remote().push()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python push_markdown.py <repo_url> <markdown_file_name>")
|
||||
sys.exit(1)
|
||||
|
||||
repo_url = sys.argv[1]
|
||||
file_name = sys.argv[2]
|
||||
|
||||
# Clone the repository
|
||||
clone_repo(repo_url)
|
||||
|
||||
# Create a new Markdown file with content
|
||||
create_markdown_file(file_name, "Hello, World!\n")
|
||||
|
||||
# Commit and push changes to the main branch
|
||||
commit_and_push(file_name, f"Add {file_name}.md")
|
||||
|
||||
# Create a new branch named after the Markdown file
|
||||
create_new_branch(file_name)
|
||||
|
||||
print(f"Successfully created '{file_name}' branch with '{file_name}.md'.")
|
||||
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from git import Git
|
||||
from git.repo import BaseRepository
|
||||
from git.exc import InvalidGitRepositoryError
|
||||
from git.remote import RemoteAction
|
||||
|
||||
# Set the path to your blog repo here
|
||||
blog_repo = "/path/to/your/blog/repo"
|
||||
|
||||
# Checkout a new branch and create a new file for our blog post
|
||||
branch_name = "new-post"
|
||||
try:
|
||||
repo = Git(blog_repo)
|
||||
repo.checkout("-b", branch_name, "origin/main")
|
||||
with open("my-blog-post.md", "w") as f:
|
||||
f.write(content)
|
||||
except InvalidGitRepositoryError:
|
||||
# Handle repository errors gracefully
|
||||
pass
|
||||
|
||||
# Add and commit the changes to Git
|
||||
repo.add("my-blog-post.md")
|
||||
repo.commit("-m", "Added new blog post about DevOps best practices.")
|
||||
|
||||
# Push the changes to Git and create a PR
|
||||
repo.remote().push("refs/heads/{0}:refs/for/main".format(branch_name), "--set-upstream")
|
||||
base_branch = "origin/main"
|
||||
target_branch = "main"
|
||||
pr_title = "DevOps best practices"
|
||||
try:
|
||||
repo.create_head("{0}-{1}", base=base_branch, message="{}".format(pr_title))
|
||||
except RemoteAction.GitExitStatus as e:
|
||||
# Handle Git exit status errors gracefully
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user