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