This commit is contained in:
2024-11-26 00:20:03 +10:00
parent 0314472620
commit 20c2a7e335
10 changed files with 166 additions and 42 deletions
+11 -7
View File
@@ -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}")