Skip to content

Commit d6c8581

Browse files
committed
consistent naming of message/messages in line with official ollama api
1 parent 735a69d commit d6c8581

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: quackingllama
22
Title: Process text with Ollama, retrieve structured results, cache them locally in DuckDB
3-
Version: 0.0.0.9014
3+
Version: 0.0.0.9015
44
Authors@R:
55
c(person(given = "Giorgio",
66
family = "Comai",

R/ql_generate.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ql_generate <- function(
2525
prompt_df,
2626
only_cached = FALSE,
2727
host = NULL,
28-
message = NULL,
28+
messages = NULL,
2929
keep_alive = NULL,
3030
timeout = NULL,
3131
error = c("fail", "warn")
@@ -144,7 +144,7 @@ ql_generate <- function(
144144
prompt_df = current_prompt,
145145
endpoint = "generate",
146146
host = host,
147-
message = message,
147+
messages = messages,
148148
keep_alive = keep_alive,
149149
timeout = timeout
150150
)

R/ql_request.R

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#' @param endpoint Defaults to "generate". Must be either "generate" or "chat".
44
#' @param timeout If not set with [ql_set_options()], defaults to 300 seconds (5
55
#' minutes).
6+
#' @param messages Defaults to NULL. If given, in line with official Ollama
7+
#' documentation: "the messages of the chat, this can be used to keep a chat
8+
#' memory".
69
#'
710
#' @inheritParams ql_set_options
811
#'
@@ -15,12 +18,14 @@
1518
#' ql_prompt(prompt = "a haiku") |>
1619
#' ql_request() |>
1720
#' httr2::req_dry_run()
18-
ql_request <- function(prompt_df,
19-
endpoint = "generate",
20-
host = NULL,
21-
message = NULL,
22-
keep_alive = NULL,
23-
timeout = NULL) {
21+
ql_request <- function(
22+
prompt_df,
23+
endpoint = "generate",
24+
host = NULL,
25+
messages = NULL,
26+
keep_alive = NULL,
27+
timeout = NULL
28+
) {
2429
rlang::arg_match(
2530
arg = endpoint,
2631
values = c(
@@ -31,11 +36,13 @@ ql_request <- function(prompt_df,
3136
)
3237
)
3338

34-
if (stringr::str_starts(
35-
string = endpoint,
36-
pattern = "api",
37-
negate = TRUE
38-
)) {
39+
if (
40+
stringr::str_starts(
41+
string = endpoint,
42+
pattern = "api",
43+
negate = TRUE
44+
)
45+
) {
3946
endpoint <- stringr::str_c("api/", endpoint)
4047
}
4148

@@ -51,7 +58,6 @@ ql_request <- function(prompt_df,
5158
format_schema <- prompt_df[["format"]]
5259
}
5360

54-
5561
req_01 <- httr2::request(options_l[["host"]]) |>
5662
httr2::req_url_path(endpoint) |>
5763
httr2::req_headers("Content-Type" = "application/json")
@@ -98,7 +104,7 @@ ql_request <- function(prompt_df,
98104
list(
99105
model = prompt_df[["model"]],
100106
prompt = prompt_df[["prompt"]],
101-
messages = message,
107+
messages = messages,
102108
format = yyjsonr::read_json_str(format_schema),
103109
stream = FALSE,
104110
raw = FALSE,

man/ql_generate.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ql_request.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)