untested ollama

This commit is contained in:
2024-11-14 17:48:11 +10:00
parent 675c7d1701
commit 1bd0ae9b1b
3 changed files with 50 additions and 11 deletions
View File
+39
View File
@@ -0,0 +1,39 @@
import os
from ollama import Client
class OllamaGenerator:
def __init__(self, title: str, content: 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')}
"""
)
def generate_markdown(self) -> str:
prompt = f"""
Generate a 1000 word 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:
{self.content}
Only output markdown DO NOT GENERATE AN EXPLANATION
"""
try:
self.response = self.ollama_client.chat(model=self.ollama_model,
messages=[
{
'role': 'user',
'content': f'{prompt}',
},
])
except Exception as e:
raise Exception(f"Failed to generate markdown: {e}")
def save_to_file(self, filename: str) -> None:
with open(filename, "w") as f:
f.write(self.generate_markdown())