Skip to content

Commit

Permalink
Adds basic Ollama tests to others
Browse files Browse the repository at this point in the history
  • Loading branch information
edgararuiz committed Sep 12, 2024
1 parent b5e9fce commit 7b27f4c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/llm-custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Custom on Ollama works

Code
llm_custom(reviews_table(), review, my_prompt)
Output
review
1 This has been the best TV I've ever used. Great screen, and sound.
2 I regret buying this laptop. It is too slow and the keyboard is too noisy
3 Not sure how to feel about my new washing machine. Great color, but hard to figure
.pred
1 Yes
2 No
3 No

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/llm-extract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Extract on Ollama works

Code
llm_extract(reviews_table(), review, "product")
Output
review
1 This has been the best TV I've ever used. Great screen, and sound.
2 I regret buying this laptop. It is too slow and the keyboard is too noisy
3 Not sure how to feel about my new washing machine. Great color, but hard to figure
.extract
1 tv
2 laptop
3 washing machine

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/llm-summarize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Summarize on Ollama works

Code
llm_summarize(reviews_table(), review, max_words = 5)
Output
review
1 This has been the best TV I've ever used. Great screen, and sound.
2 I regret buying this laptop. It is too slow and the keyboard is too noisy
3 Not sure how to feel about my new washing machine. Great color, but hard to figure
.summary
1 very good tv experience overall
2 slow and noisy laptop purchase
3 mixed feelings about new washer

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/llm-translate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Translate on Ollama works

Code
llm_translate(reviews_table(), review, "spanish")
Output
review
1 This has been the best TV I've ever used. Great screen, and sound.
2 I regret buying this laptop. It is too slow and the keyboard is too noisy
3 Not sure how to feel about my new washing machine. Great color, but hard to figure
.translation
1 Este ha sido el mejor televisor que he utilizado. Gran pantalla y sonido.
2 Lamento haber comprado esta laptop. Está demasiado lenta y el teclado es demasiado ruidoso.
3 No estoy seguro de cómo sentirme sobre mi nueva lavadora. Color genial, pero difícil de manejar.

11 changes: 11 additions & 0 deletions tests/testthat/test-llm-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ test_that("Custom works", {
data.frame(x = test_text, new = test_text)
)
})

test_that("Custom on Ollama works",{
skip_if_no_ollama()
my_prompt <- paste(
"Answer a question.",
"Return only the answer, no explanation",
"Acceptable answers are 'yes', 'no'",
"Answer this about the following text, is this a happy customer?:"
)
expect_snapshot(llm_custom(reviews_table(), review, my_prompt))
})
5 changes: 5 additions & 0 deletions tests/testthat/test-llm-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ test_that("Extract works", {
data.frame(x = entries2, y = "toaster", z = "TV")
)
})

test_that("Extract on Ollama works",{
skip_if_no_ollama()
expect_snapshot(llm_extract(reviews_table(), review, "product"))
})
5 changes: 5 additions & 0 deletions tests/testthat/test-llm-summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ test_that("Summarize works", {
data.frame(x = test_text, new = test_text)
)
})

test_that("Summarize on Ollama works",{
skip_if_no_ollama()
expect_snapshot(llm_summarize(reviews_table(), review, max_words = 5))
})
5 changes: 5 additions & 0 deletions tests/testthat/test-llm-translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ test_that("Translate works", {
data.frame(x = test_text, new = test_text)
)
})

test_that("Translate on Ollama works",{
skip_if_no_ollama()
expect_snapshot(llm_translate(reviews_table(), review, "spanish"))
})

0 comments on commit 7b27f4c

Please sign in to comment.