JBGruber / rollama

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

Wrap Ollama API endpoints #1

Open JBGruber opened 10 months ago

JBGruber commented 10 months ago
JBGruber commented 10 months ago

Pushing a model needs authentication. It isn't hard to accomplish that, but I wonder if it's neccessary.

JiaZhang42 commented 7 months ago

Thank you for the great package, Johannes! It works perfectly. Before I found this package, I tried to request the Ollama API using httr2, but it keeps giving this error saying the response type is "application/x-ndjson", not "application/json". Would you happen to know how to deal with it? I looked into your code but didn't figure it out.

library(tidyverse)
library(httr2)
request('http://localhost:11434/api/chat') %>% 
  req_body_json(list(
    model = 'mistral', 
    messages = list(
      list(role = 'user', 
      content = 'why is the sky blue?')
    )
  )) %>% 
  req_headers("Content-Type" = "application/json",
    "Accept" = "application/json") %>%
  req_error(is_error = function(resp) FALSE) %>% 
  req_perform() %>% 
  resp_body_json()
#> Error in `resp_body_json()`:
#> ! Unexpected content type "application/x-ndjson".
#> • Expecting type "application/json" or suffix "json".

Created on 2024-04-27 with reprex v2.1.0

JiaZhang42 commented 7 months ago

Thank you for the great package, Johannes! It works perfectly. Before I found this package, I tried to request the Ollama API using httr2, but it keeps giving this error saying the response type is "application/x-ndjson", not "application/json". Would you happen to know how to deal with it? I looked into your code but didn't figure it out.

library(tidyverse)
library(httr2)
request('http://localhost:11434/api/chat') %>% 
  req_body_json(list(
    model = 'mistral', 
    messages = list(
      list(role = 'user', 
      content = 'why is the sky blue?')
    )
  )) %>% 
  req_headers("Content-Type" = "application/json",
    "Accept" = "application/json") %>%
  req_error(is_error = function(resp) FALSE) %>% 
  req_perform() %>% 
  resp_body_json()
#> Error in `resp_body_json()`:
#> ! Unexpected content type "application/x-ndjson".
#> • Expecting type "application/json" or suffix "json".

Created on 2024-04-27 with reprex v2.1.0

Turned out I didn't set stream = FALSE. Thanks.