Skip to content

Commit

Permalink
update code notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
0thernet committed May 4, 2024
1 parent f309ea7 commit 9515e0a
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions examples/notebooks/run-code-chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,47 +50,42 @@ def __(mo):


@app.cell
def __(GenerateText, RunCode, question):
def __(GenerateText, RunCode, question, sb):
prompt = f"""
{question.value}
{question.value or 'What is the 88th fibonacci number?'}
Think step by step and run Python code to check your work or solve problems before returning an answer. Print the output. The Python runtime does not have network or filesystem access, but does include the entire standard library. Read input from stdin and write output to stdout. Remember to print the output in your code. Wrap the code in your response inside a <code></code> tag.
Think step by step and run Python code to check your work or solve problems before returning an answer. Print the output inside json in a "result" key with json.dumps. The Python runtime does not have network or filesystem access, but does include the entire standard library. Read input from stdin and write output to stdout. Remember to print the output in your code inside json with json.dumps. Wrap the code in your response inside a <code></code> tag.
"""
text = GenerateText(
{
"prompt": prompt,
"node": "Llama3Instruct70B",
# "node": "Mistral7BInstruct",
}
)
get_code = RunCode(
run_code = RunCode(
{
"code": """import re
import sys
s = sys.argv[1]
match = re.search(r'<code>(.*?)</code>', s, re.DOTALL)
print(match.group(1) if match else "")
""",
"args": [text.future.text],
"code": sb.jq(
text.future.text,
'split("<code>") | .[1] | split("</code>") | .[0]',
)
}
)
run_code = RunCode({"code": get_code.future.output})
return get_code, prompt, run_code, text
return prompt, run_code, text


@app.cell
def __(get_code, mo, run_code, substrate, text):
res = substrate.run(text, get_code, run_code)
viz = substrate.visualize(text, get_code, run_code)
def __(Substrate, mo, run_code, substrate, text):
res = substrate.run(text, run_code)
d = Substrate.serialize(text, run_code)
viz = substrate.visualize(text, run_code)
mo.md(f"[visualize]({viz})")
return res, viz
return d, res, viz


@app.cell
def __(json, mo, res, run_code):
def __(json, res):
print(json.dumps(res.json, indent=2))
mo.md(res.get(run_code).output)
# mo.md(res.get(run_code).output)
return


Expand Down

0 comments on commit 9515e0a

Please sign in to comment.