Skip to content

Commit

Permalink
JavaScript API PS
Browse files Browse the repository at this point in the history
  • Loading branch information
royjhan committed Jun 4, 2024
1 parent 305eb0b commit c553b59
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ ollama.embeddings(request)
- `options` `<Options>`: (Optional) Options to configure the runtime.
- Returns: `<EmbeddingsResponse>`

### process

```javascript
ollama.process()
```

- Returns: `<ListResponse>`

## Custom client

A custom client can be created with the following fields:
Expand Down
16 changes: 16 additions & 0 deletions examples/list/list.ts
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ export class Ollama {
})
return (await response.json()) as EmbeddingsResponse
}

/**
* Lists the running models on the server
* @returns {Promise<ListResponse>} - The response object.
* @throws {Error} - If the response body is missing.
*/
async process(): Promise<ListResponse> {
const response = await utils.get(this.fetch, `${this.config.host}/api/ps`)
return (await response.json()) as ListResponse
}
}

export default new Ollama()
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export interface ModelResponse {
size: number
digest: string
details: ModelDetails
expires_at: Date
size_vram: number
}

export interface ModelDetails {
Expand Down

0 comments on commit c553b59

Please sign in to comment.