File size: 830 Bytes
d2c6ae0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# Answer a math problem with code.
# Adapted from Dust [maths-generate-code](https://dust.tt/spolu/a/d12ac33169)
from minichain import Backend, JinjaPrompt, Prompt, start_chain, SimplePrompt, show_log
# Prompt that asks LLM for code from math.
class ColorPrompt(Prompt[str, bool]):
def parse(inp: str) -> str:
return f"Answer 'Yes' if this is a color, {inp}. Answer:"
def parse(out: str, inp) -> bool:
# Encode the parsing logic
return out.strip() == "Yes"
ColorPrompt().show({"inp": "dog"}, "No")
with start_chain("math") as backend:
question = 'What is the sum of the powers of 3 (3^i) that are smaller than 100?'
prompt = MathPrompt(backend.OpenAI()).chain(SimplePrompt(backend.Python()))
result = prompt({"question": question})
print(result)
show_log("math.log")
|