From c553b59af4079e116459acb5bdcfc78317cc0aaa Mon Sep 17 00:00:00 2001 From: Roy Han Date: Tue, 4 Jun 2024 15:44:03 -0700 Subject: [PATCH 1/4] JavaScript API PS --- README.md | 8 ++++++++ examples/list/list.ts | 16 ++++++++++++++++ src/browser.ts | 10 ++++++++++ src/interfaces.ts | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 examples/list/list.ts diff --git a/README.md b/README.md index 76b688a..90aba55 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,14 @@ ollama.embeddings(request) - `options` ``: (Optional) Options to configure the runtime. - Returns: `` +### process + +```javascript +ollama.process() +``` + +- Returns: `` + ## Custom client A custom client can be created with the following fields: diff --git a/examples/list/list.ts b/examples/list/list.ts new file mode 100644 index 0000000..89c99f6 --- /dev/null +++ b/examples/list/list.ts @@ -0,0 +1,16 @@ +import ollama from '../../src/browser' + +await ollama.pull({ + model: 'llama2', + }) + +await ollama.chat({ + model: 'llama2', + messages: [{ role: 'user', content: 'True or false' }], +}) + +var response = await ollama.list() +console.log(response) + +response = await ollama.process() +console.log(response) \ No newline at end of file diff --git a/src/browser.ts b/src/browser.ts index 81ce484..8a1ec5c 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -278,6 +278,16 @@ export class Ollama { }) return (await response.json()) as EmbeddingsResponse } + + /** + * Lists the running models on the server + * @returns {Promise} - The response object. + * @throws {Error} - If the response body is missing. + */ + async process(): Promise { + const response = await utils.get(this.fetch, `${this.config.host}/api/ps`) + return (await response.json()) as ListResponse + } } export default new Ollama() diff --git a/src/interfaces.ts b/src/interfaces.ts index 786bcc5..71f5eea 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -166,6 +166,8 @@ export interface ModelResponse { size: number digest: string details: ModelDetails + expires_at: Date + size_vram: number } export interface ModelDetails { From 8b52afb2ada61b1fd056db36740a19e1de526566 Mon Sep 17 00:00:00 2001 From: Roy Han Date: Tue, 4 Jun 2024 15:49:19 -0700 Subject: [PATCH 2/4] PS Rename --- README.md | 2 +- examples/list/list.ts | 2 +- src/browser.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 90aba55..bf7815e 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ ollama.embeddings(request) ### process ```javascript -ollama.process() +ollama.ps() ``` - Returns: `` diff --git a/examples/list/list.ts b/examples/list/list.ts index 89c99f6..fda676b 100644 --- a/examples/list/list.ts +++ b/examples/list/list.ts @@ -12,5 +12,5 @@ await ollama.chat({ var response = await ollama.list() console.log(response) -response = await ollama.process() +response = await ollama.ps() console.log(response) \ No newline at end of file diff --git a/src/browser.ts b/src/browser.ts index 8a1ec5c..759d5ce 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -284,7 +284,7 @@ export class Ollama { * @returns {Promise} - The response object. * @throws {Error} - If the response body is missing. */ - async process(): Promise { + async ps(): Promise { const response = await utils.get(this.fetch, `${this.config.host}/api/ps`) return (await response.json()) as ListResponse } From 36de0aa2fe9f2bd1a52699884aa8698e372166e9 Mon Sep 17 00:00:00 2001 From: Roy Han Date: Tue, 4 Jun 2024 15:52:07 -0700 Subject: [PATCH 3/4] Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf7815e..e037295 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ ollama.embeddings(request) - `options` ``: (Optional) Options to configure the runtime. - Returns: `` -### process +### ps ```javascript ollama.ps() From fcfd6417a73db35cd77b9615810bf4efaa3ac633 Mon Sep 17 00:00:00 2001 From: Roy Han Date: Wed, 5 Jun 2024 11:09:48 -0700 Subject: [PATCH 4/4] Delete List Example --- examples/list/list.ts | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 examples/list/list.ts diff --git a/examples/list/list.ts b/examples/list/list.ts deleted file mode 100644 index fda676b..0000000 --- a/examples/list/list.ts +++ /dev/null @@ -1,16 +0,0 @@ -import ollama from '../../src/browser' - -await ollama.pull({ - model: 'llama2', - }) - -await ollama.chat({ - model: 'llama2', - messages: [{ role: 'user', content: 'True or false' }], -}) - -var response = await ollama.list() -console.log(response) - -response = await ollama.ps() -console.log(response) \ No newline at end of file