Writes a draft of a poem.
(state: State)
| 47 | writes=["current_draft", "draft_history", "num_drafts"], |
| 48 | ) |
| 49 | def write(state: State) -> Tuple[dict, State]: |
| 50 | """Writes a draft of a poem.""" |
| 51 | poem_subject = state["prompt"] |
| 52 | poem_type = state["poem_type"] |
| 53 | current_draft = state.get("current_draft") |
| 54 | feedback = state.get("feedback") |
| 55 | |
| 56 | parts = [ |
| 57 | f'You are an AI poet. Create a {poem_type} poem on the following subject: "{poem_subject}". ' |
| 58 | "It is absolutely imperative that you respond with only the poem and no other text." |
| 59 | ] |
| 60 | |
| 61 | if current_draft: |
| 62 | parts.append(f'Here is the current draft of the poem: "{current_draft}".') |
| 63 | |
| 64 | if feedback: |
| 65 | parts.append(f'Please incorporate the following feedback: "{feedback}".') |
| 66 | |
| 67 | parts.append( |
| 68 | f"Ensure the poem is creative, adheres to the style of a {poem_type}, and improves upon the previous draft." |
| 69 | ) |
| 70 | |
| 71 | prompt = "\n".join(parts) |
| 72 | |
| 73 | draft = _query_llm(prompt) |
| 74 | |
| 75 | return {"draft": draft}, state.update( |
| 76 | current_draft=draft, |
| 77 | draft_history=state.get("draft_history", []) + [draft], |
| 78 | ).increment(num_drafts=1) |
| 79 | |
| 80 | |
| 81 | @action(reads=["current_draft", "poem_type", "prompt"], writes=["feedback"]) |
nothing calls this directly
no test coverage detected