Skip to content

Commit afff36f

Browse files
committed
Update utils and changelog
1 parent 9f5c13b commit afff36f

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

NEWS.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# ollamar 1.2.0
2+
3+
- All functions calling API endpoints have `endpoint` parameter.
4+
- All functions calling API endpoints have `...` parameter to pass additional model options to the API.
5+
- All functions calling API endpoints have `host` parameter to specify the host URL. Default is `NULL`, which uses the default Ollama URL.
6+
- Add `req` as an output format for `generate()` and `chat()`.
7+
- Add new functions for calling APIs: `create()`, `show()`, `copy()`, `delete()`, `push()`, `embed()` (supercedes `embeddings()`), `ps()`.
8+
- Add helper functions to manipulate chat/conversation history for `chat()` function (or other APIs like OpenAI): `create_message()`, `append_message()`, `prepend_message()`, `delete_message()`, `insert_message()`.
9+
- Add `ohelp()` function to chat with models in real-time.
10+
- Add helper functions: `model_avail()`, `image_encode_base64()`, `check_option_valid()`, `check_options()`, `search_options()`, `validate_options()`
11+
112
# ollamar 1.1.1
213

314
## Bug fixes
@@ -11,13 +22,13 @@
1122

1223
## New features
1324

14-
- Integrated R with Ollama to run language models locally on your own machine.
15-
- Included `test_connection()` function to test connection to Ollama server.
16-
- Included `list_models()` function to list available models.
17-
- Included `pull()` function to pull a model from Ollama server.
18-
- Included `delete()` function to delete a model from Ollama server.
19-
- Included `chat()` function to chat with a model.
20-
- Included `generate()` function to generate text from a model.
21-
- Included `embeddings()` function to get embeddings from a model.
22-
- Included `resp_process()` function to process `httr2_response` objects.
25+
- Integrate R with Ollama to run language models locally on your own machine.
26+
- Include `test_connection()` function to test connection to Ollama server.
27+
- Include `list_models()` function to list available models.
28+
- Include `pull()` function to pull a model from Ollama server.
29+
- Include `delete()` function to delete a model from Ollama server.
30+
- Include `chat()` function to chat with a model.
31+
- Include `generate()` function to generate text from a model.
32+
- Include `embeddings()` function to get embeddings from a model.
33+
- Include `resp_process()` function to process `httr2_response` objects.
2334

R/utils.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ stream_handler <- function(x, env, endpoint) {
8686
#' resp_process(resp, "resp") # return input response object
8787
#' resp_process(resp, "text") # return text/character vector
8888
resp_process <- function(resp, output = c("df", "jsonlist", "raw", "resp", "text")) {
89+
90+
if (!inherits(resp, "httr2_response")) {
91+
stop("Input must be a httr2 response object")
92+
}
93+
8994
if (is.null(resp) || resp$status_code != 200) {
90-
warning("Cannot process response")
91-
return(NULL)
95+
stop("Cannot process response")
9296
}
9397

9498
endpoints_to_skip <- c("api/delete", "api/embed", "api/embeddings", "api/create")

README.Rmd

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,22 @@ messages <- delete_message(messages, 2)
289289

290290
### Parallel requests
291291

292-
For the `generate()` and `chat()` endpoints/functions, you can make parallel requests with the `req_perform_parallel` function from the `httr2` library. You need to specify `output = 'req'` in the function so the functions return `httr2_request` objects instead of `httr2_response` objects.
292+
For the `generate()` and `chat()` endpoints/functions, you can specify `output = 'req'` in the function so the functions return `httr2_request` objects instead of `httr2_response` objects.
293+
294+
```{r eval=FALSE}
295+
prompt <- "Tell me a 10-word story"
296+
req <- generate("llama3.1", prompt, output = "req") # returns a httr2_request object
297+
# <httr2_request>
298+
# POST http://127.0.0.1:11434/api/generate
299+
# Headers:
300+
# • content_type: 'application/json'
301+
# • accept: 'application/json'
302+
# • user_agent: 'ollama-r/1.1.1 (aarch64-apple-darwin20) R/4.4.0'
303+
# Body: json encoded data
304+
305+
```
306+
307+
When you have multiple `httr2_request` objects in a list, you can make parallel requests with the `req_perform_parallel` function from the `httr2` library. See [`httr2` documentation](https://httr2.r-lib.org/reference/req_perform_parallel.html) for details.
293308

294309
```{r eval=FALSE}
295310
library(httr2)

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,27 @@ messages <- delete_message(messages, 2)
328328

329329
### Parallel requests
330330

331-
For the `generate()` and `chat()` endpoints/functions, you can make
331+
For the `generate()` and `chat()` endpoints/functions, you can specify
332+
`output = 'req'` in the function so the functions return `httr2_request`
333+
objects instead of `httr2_response` objects.
334+
335+
``` r
336+
prompt <- "Tell me a 10-word story"
337+
req <- generate("llama3.1", prompt, output = "req") # returns a httr2_request object
338+
# <httr2_request>
339+
# POST http://127.0.0.1:11434/api/generate
340+
# Headers:
341+
# • content_type: 'application/json'
342+
# • accept: 'application/json'
343+
# • user_agent: 'ollama-r/1.1.1 (aarch64-apple-darwin20) R/4.4.0'
344+
# Body: json encoded data
345+
```
346+
347+
When you have multiple `httr2_request` objects in a list, you can make
332348
parallel requests with the `req_perform_parallel` function from the
333-
`httr2` library. You need to specify `output = 'req'` in the function so
334-
the functions return `httr2_request` objects instead of `httr2_response`
335-
objects.
349+
`httr2` library. See [`httr2`
350+
documentation](https://httr2.r-lib.org/reference/req_perform_parallel.html)
351+
for details.
336352

337353
``` r
338354
library(httr2)

0 commit comments

Comments
 (0)