Skip to content

Commit

Permalink
Backport PR jupyterlab#1075: Fix magic commands when using non-chat p…
Browse files Browse the repository at this point in the history
…roviders w/ history (jupyterlab#1080)

Co-authored-by: Alan Meeson <[email protected]>
  • Loading branch information
meeseeksmachine and alanmeeson authored Nov 1, 2024
1 parent fb4a833 commit d42edd5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d42edd5

Please sign in to comment.