untested ollama
This commit is contained in:
@@ -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())
|
||||
Reference in New Issue
Block a user