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