Skip to content

Commit

Permalink
feat: Fix content passing to openai
Browse files Browse the repository at this point in the history
  • Loading branch information
Estrada Irribarra, Rodrigo Andres committed Oct 19, 2024
1 parent 3db4259 commit 3e74e7a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/iterate.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ storycraftr iterate strengthen-argument "Ensure the argument of rebellion agains
Sometimes, you may need to insert a chapter between two existing ones. This command will **insert a new chapter** and automatically **adjust the numbering** of all subsequent chapters.

```bash
storycraftr iterate insert-chapter "Insert a new chapter between chapters 3 and 4." 3
storycraftr iterate insert-chapter 5 "just extend the idea in 3 chapters instead of 2"
```

### 5. Split a Chapter
Expand Down
2 changes: 1 addition & 1 deletion storycraftr/agent/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def create_message(
try:
# Send prompt to OpenAI API
avoid_cache_content = generate_prompt_with_hash(
f"content\n\n{FORMAT_OUTPUT.format(reference_author=config.reference_author, language=config.primary_language)}",
f"{FORMAT_OUTPUT.format(reference_author=config.reference_author, language=config.primary_language)}\n\n{content}",
datetime.now().strftime("%B %d, %Y"),
)
client.beta.threads.messages.create(
Expand Down
8 changes: 6 additions & 2 deletions storycraftr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from rich.console import Console
import storycraftr.templates.folder
from storycraftr.state import debug_state
from storycraftr.cmd.worldbuilding import worldbuilding
from storycraftr.cmd.outline import outline
from storycraftr.cmd.chapters import chapters
Expand Down Expand Up @@ -162,9 +163,12 @@ def init_structure(


@click.group()
def cli():
@click.option("--debug", is_flag=True, help="Enable debug mode")
def cli(debug):
"""StoryCraftr CLI - A tool to help you write books using OpenAI."""
pass
debug_state.set_debug(debug) # Configura el estado de debug
if debug:
click.echo("Debug mode is ON")


@click.command()
Expand Down
8 changes: 8 additions & 0 deletions storycraftr/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import json
from typing import NamedTuple
from rich.console import Console
from rich.markdown import Markdown # Importar soporte de Markdown de Rich
from storycraftr.prompts.permute import longer_date_formats
from storycraftr.state import debug_state # Importar el estado de debug

console = Console()

Expand All @@ -20,6 +22,12 @@ def generate_prompt_with_hash(original_prompt, date):
# Combina la frase seleccionada, un salto de línea, el hash y el prompt original
modified_prompt = f"{random_phrase}\n\n{hash_hex[:10]}: {original_prompt}" # Usa los primeros 10 caracteres del hash

# Si el modo debug está activado, imprime el prompt modificado en formato Markdown
if debug_state.is_debug():
console.print(
Markdown(modified_prompt)
) # Usa Rich para imprimir en formato Markdown

return modified_prompt


Expand Down

0 comments on commit 3e74e7a

Please sign in to comment.