JBGruber / rollama

https://jbgruber.github.io/rollama/
GNU General Public License v3.0
91 stars 2 forks source link

chat_history() content is sorted incorrectly #12

Closed reijmerniek closed 6 months ago

reijmerniek commented 6 months ago

Hey! Really love your package, super nice! I have found however a problem with the chat_history() function.

It reps 'user' and 'assistant' into a tibble, but the content is not sorted by repping, but first shows all user messages and then all assistant messages.

JBGruber commented 6 months ago

Thank you for reporting this! I think originally I meant to write hist <- c(rbind(the$prompts, the$responses)) and left out the rbind part. But I wrote something more robust now:

library(rollama)
chat("What is 1 + 1?", model = "orca-mini")  # this one retains the conversation
#> 
#> ── Answer from orca-mini ───────────────────────────────────────────────────────
#> The answer to the question "What is 1 + 1?" is 2.
chat("Now take the result and add 1. What is it?", model = "orca-mini")
#> 
#> ── Answer from orca-mini ───────────────────────────────────────────────────────
#> The answer to the question "What is it" is not applicable as it is asking for a
#> specific operation to be performed, which is addition. Adding 1 to the result
#> of 1 + 1 would give 2.
chat_history()
#> # A tibble: 4 × 3
#>   role      content                                          time               
#>   <chr>     <chr>                                            <dttm>             
#> 1 user      "What is 1 + 1?"                                 2024-05-17 12:28:46
#> 2 assistant " The answer to the question \"What is 1 + 1?\"… 2024-05-17 12:28:47
#> 3 user      "Now take the result and add 1. What is it?"     2024-05-17 12:28:47
#> 4 assistant " The answer to the question \"What is it\" is … 2024-05-17 12:28:48

Created on 2024-05-17 with reprex v2.1.0