mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-19 04:37:54 +00:00
ebnhanced writing
This commit is contained in:
parent
d6a102bf2c
commit
e9e7b441b3
@ -11,6 +11,20 @@ def markdown_to_latex(file_path: str) -> str:
|
||||
# Load the markdown file
|
||||
markdown_text = Path(file_path).read_text()
|
||||
|
||||
# Extract title, author, and prompted by information
|
||||
title_match = re.search(r'^# (.*)', markdown_text, re.MULTILINE)
|
||||
author_match = re.search(r'^Author: (.*)', markdown_text, re.MULTILINE)
|
||||
prompted_by_match = re.search(r'^Prompted by: (.*)', markdown_text, re.MULTILINE)
|
||||
|
||||
title = title_match.group(1) if title_match else "Untitled"
|
||||
author = author_match.group(1) if author_match else ""
|
||||
prompted_by = prompted_by_match.group(1) if prompted_by_match else ""
|
||||
|
||||
# Remove the extracted parts from the markdown text
|
||||
markdown_text = re.sub(r'^# .*\n', '', markdown_text, flags=re.MULTILINE)
|
||||
markdown_text = re.sub(r'^Author: .*\n', '', markdown_text, flags=re.MULTILINE)
|
||||
markdown_text = re.sub(r'^Prompted by: .*\n', '', markdown_text, flags=re.MULTILINE)
|
||||
|
||||
# Define conversion rules from markdown to LaTeX
|
||||
conversion_rules = [
|
||||
(r'\\', r'\\textbackslash{}'), # Escape backslashes
|
||||
@ -31,11 +45,35 @@ def markdown_to_latex(file_path: str) -> str:
|
||||
for pattern, replacement in conversion_rules:
|
||||
latex_text = re.sub(pattern, replacement, latex_text, flags=re.MULTILINE)
|
||||
|
||||
# Create the LaTeX document structure
|
||||
latex_document = f"""
|
||||
\\documentclass{{book}}
|
||||
\\usepackage{{hyperref}}
|
||||
\\usepackage{{graphicx}}
|
||||
\\usepackage{{verbatim}}
|
||||
|
||||
\\begin{{document}}
|
||||
|
||||
\\title{{{title}}}
|
||||
\\author{{{author}}}
|
||||
\\date{{}}
|
||||
|
||||
\\maketitle
|
||||
|
||||
\\begin{{flushleft}}
|
||||
\\textbf{{Prompted by:}} {prompted_by}
|
||||
\\end{{flushleft}}
|
||||
|
||||
{latex_text}
|
||||
|
||||
\\end{{document}}
|
||||
"""
|
||||
|
||||
# Define output file path
|
||||
output_path = Path(file_path).with_suffix('.tex')
|
||||
|
||||
# Save the LaTeX text to a file
|
||||
output_path.write_text(latex_text)
|
||||
output_path.write_text(latex_document)
|
||||
|
||||
# Finally we return the path to the LaTeX file
|
||||
return str(output_path)
|
||||
@ -50,3 +88,9 @@ def markdown_to_latex_function():
|
||||
"function_description": "Converts a markdown file to a LaTeX file.", # Description
|
||||
"function_parameters": [{"name": "file_path", "type": "str"}] # The set of parameters
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Test the function with a sample file
|
||||
test_file_path = "story.md"
|
||||
result = markdown_to_latex(test_file_path)
|
||||
print(f"Generated LaTeX file: {result}")
|
||||
|
@ -70,13 +70,12 @@ def start_writing_story(prompt_ideas: str, llm: Any, story_file_path: str, build
|
||||
llm.step_start(f'Building section: {section["section_name"]}')
|
||||
|
||||
section_name = section["section_name"]
|
||||
section_description = section["section_description"]
|
||||
|
||||
new_section = write_story_section(
|
||||
llm=llm,
|
||||
story_file_path=story_file_path,
|
||||
story_plan=story_plan,
|
||||
current_section=section_description,
|
||||
current_section=section_name,
|
||||
prompt_ideas=prompt_ideas
|
||||
)
|
||||
|
||||
@ -139,6 +138,9 @@ def write_story_section(prompt_ideas: str, llm: Any, story_file_path: str, story
|
||||
|
||||
# Initialize the story with the title and the first section
|
||||
new_section = f"# {story_title}\n\n"
|
||||
new_section += f"Author: {llm.personality.name}\n"
|
||||
new_section += f"Prompter: {llm.config.user_name}\n\n"
|
||||
|
||||
new_section += f"## {current_section}\n\n"
|
||||
|
||||
prompt = "\n".join([
|
||||
|
Loading…
Reference in New Issue
Block a user