Skip to content

Commit

Permalink
model pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
monofuel committed Jan 13, 2024
1 parent 4184dee commit 90d6e48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/llama_leap.nim
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,25 @@ proc generate*(api: OllamaAPI, req: JsonNode): JsonNode =
result = fromJson(resp.body)

proc listModels*(api: OllamaAPI): ListResp =
## List all the models available
let url = api.baseUrl / "tags"
let resp = api.curlPool.get(url, timeout = api.curlTimeout)
if resp.code != 200:
raise newException(CatchableError, &"ollama list tags failed: {resp.code} {resp.body}")
result = fromJson(resp.body, ListResp)

proc pullModel*(api: OllamaAPI, name: string) =
## Ask the ollama server to pull a model
let url = api.baseUrl / "pull"
let req = %*{"name": name, "stream": false}

var headers: curly.HttpHeaders
headers["Content-Type"] = "application/json"

let resp = api.curlPool.post(url, headers, toJson(req), api.curlTimeout)
if resp.code != 200:
raise newException(CatchableError, &"ollama pull failed: {resp.code} {resp.body}")
let respJson = fromJson(resp.body)
let status = respJson["status"].getStr
if status != "success":
raise newException(CatchableError, &"ollama pull bad status: {resp.body}")
4 changes: 4 additions & 0 deletions tests/test_llama_leap.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ suite "llama_leap":
teardown:
ollama.close()

suite "pull":
test "pull model":
ollama.pullModel(TestModel)

suite "list":
test "list model tags":
let resp = ollama.listModels()
Expand Down

0 comments on commit 90d6e48

Please sign in to comment.