Skip to content

Commit

Permalink
prevent re-running the last step by adding a summary step
Browse files Browse the repository at this point in the history
closes #13
  • Loading branch information
haesleinhuepf committed Aug 10, 2023
1 parent db19be5 commit 08b3145
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion demo/pandas_plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{
"data": {
"text/markdown": [
"Here is the plot of x against y in the dataframe df."
"The plot shows the relationship between the variables x and y in the dataframe df."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down
23 changes: 12 additions & 11 deletions src/bia_bob/_machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class _context():

@register_line_cell_magic
def bob(line: str = None, cell: str = None):
import re
from IPython.display import display, Markdown
if _context.agent is None:
init_assistant({})

Expand All @@ -23,19 +23,21 @@ def bob(line: str = None, cell: str = None):
print("Variables:", len(_context.variables.keys()))

if line and cell:
result = _context.agent.run(input=line + "\n" + cell)
prompt = line + "\n" + cell
elif line:
result = _context.agent.run(input=line)
prompt = line
elif cell:
result = _context.agent.run(input=cell)
prompt = cell
else:
result = "Please enter a question behind %bob"
display("Please enter a question behind %bob")
return ""

# filter out markdown images from the response
pattern = r'!\[.*?\]\(.*?\)'
result = re.sub(pattern, '', result)
# why? https://github.com/haesleinhuepf/bia-bob/issues/13
if not prompt.strip().endswith("?"):
prompt = prompt + "\nSummarize the answers in maximum two sentences."

result = _context.agent.run(input=prompt)

from IPython.display import display, Markdown, Latex
display(Markdown(result))


Expand All @@ -61,12 +63,11 @@ def init_assistant(variables, temperature=0):
system_message = SystemMessage(content="""
You never produce sample data.
You never print out dataframes.
Do not answer questions that are not asked.
Answer the human's questions below and keep your answers short.
""")
agent_kwargs = {
"system_message": system_message,
"extra_prompt_messages": [MessagesPlaceholder(variable_name=MEMORY_KEY)],
"extra_prompt_messages": [MessagesPlaceholder(variable_name=MEMORY_KEY)]
}
_context.agent = initialize_agent(
_context.tools,
Expand Down

0 comments on commit 08b3145

Please sign in to comment.