MCPcopy Create free account
hub / github.com/apache/burr / write

Function write

examples/recursive/application.py:49–78  ·  view source on GitHub ↗

Writes a draft of a poem.

(state: State)

Source from the content-addressed store, hash-verified

47 writes=["current_draft", "draft_history", "num_drafts"],
48)
49def 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"])

Callers

nothing calls this directly

Calls 5

incrementMethod · 0.80
_query_llmFunction · 0.70
getMethod · 0.45
appendMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected