From 9ef9c0e5bb96a0995c6e42b14ff3e2f3c2d41e04 Mon Sep 17 00:00:00 2001 From: Alan Meeson Date: Fri, 1 Nov 2024 22:11:43 +0000 Subject: [PATCH] Backport PR #1075: Fix magic commands when using non-chat providers w/ history --- .../jupyter_ai_magics/magics.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py index b27e1636e..1c797b5a2 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py @@ -603,17 +603,19 @@ def run_ai_cell(self, args: CellArgs, prompt: str): else: # generate output from model via provider if context: - inputs = [ - ( - f"AI: {message.content}" - if message.type == "ai" - else f"{message.type.title()}: {message.content}" - ) - for message in context + [HumanMessage(content=prompt)] - ] + inputs = "\n\n".join( + [ + ( + f"AI: {message.content}" + if message.type == "ai" + else f"{message.type.title()}: {message.content}" + ) + for message in context + [HumanMessage(content=prompt)] + ] + ) else: - inputs = [prompt] - result = provider.generate(inputs) + inputs = prompt + result = provider.generate([inputs]) output = result.generations[0][0].text