Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #16

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ npm i ollama

## Usage

A global default client is provided for convenience and can be used for both single and streaming responses.

```javascript
import ollama from 'ollama'

Expand All @@ -22,6 +20,9 @@ const response = await ollama.chat({
console.log(response.message.content)
```

## Streaming responses
Response streaming can be enabled by setting `stream: true`, modifying function calls to return an `AsyncGenerator` where each part is an object in the stream.

```javascript
import ollama from 'ollama'

Expand All @@ -32,19 +33,19 @@ for await (const part of response) {
}
```

## API

The API aims to mirror the [HTTP API for Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md).

### Ollama

## Create
```javascript
new Ollama(config)
import ollama from 'ollama'

const modelfile = `
FROM llama2
SYSTEM "You are mario from super mario bros."
`
await ollama.create({ model: 'example', modelfile: modelfile })
```

- `config` `<Object>` (Optional) Configuration object for Ollama.
- `host` `<string>` (Optional) The Ollama host address. Default: `"http://127.0.0.1:11434"`.
- `fetch` `<fetch>` (Optional) The fetch library used to make requests to the Ollama host.
## API
The Ollama JavaScript library's API is designed around the [Ollama REST API](https://github.com/jmorganca/ollama/blob/main/docs/api.md)

### chat

Expand Down Expand Up @@ -178,6 +179,23 @@ ollama.embeddings(request)
- `options` `<Options>`: (Optional) Options to configure the runtime.
- Returns: `<EmbeddingsResponse>`

## Custom client

A custom client can be created with the following fields:

- `host` `<string>`: (Optional) The Ollama host address. Default: `"http://127.0.0.1:11434"`.
- `fetch` `<Object>`: (Optional) The fetch library used to make requests to the Ollama host.

```javascript
import { Ollama } from 'ollama'

const ollama = new Ollama({ host: 'http://localhost:11434' })
const response = await ollama.chat({
model: 'llama2',
messages: [{ role: 'user', content: 'Why is the sky blue?' }],
})
```

## Building

To build the project files run:
Expand Down