api.md 3.38 KB
Newer Older
1
2
3
4
5
[Documentation Home](./README.md)

# API

## Generate a Prompt
Matt Williams's avatar
Matt Williams committed
6

Matt Williams's avatar
Matt Williams committed
7
**POST /api/generate**
8

Matt Williams's avatar
Matt Williams committed
9
10
**Generate** is the main endpoint that you will use when working with Ollama. This is used to generate a response to a prompt sent to a model.

Matt Williams's avatar
Matt Williams committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
The **Generate** endpoint takes a JSON object with the following fields:

```
{
  Model: "modelname",
  Prompt: "prompt",
}
```

The response is a stream of JSON objects with the following fields:

```
{
  "model": "modelname",
  "created_at": "2023-08-04T08:52:19.385406455-07:00"
  "response": "the current token",
  "done": false
}
```

Matt Williams's avatar
Matt Williams committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
The final response in the stream also includes the context and what is usually seen in the output from verbose mode. For example:

```
{
  "model":"orca",
  "created_at":"2023-08-04T19:22:45.499127Z",
  "done":true,
  "total_duration":5589157167,
  "load_duration":3013701500,
  "sample_count":114,
  "sample_duration":81442000,
  "prompt_eval_count":46,
  "prompt_eval_duration":1160282000,
  "eval_count":113,
  "eval_duration":1325948000
}
```

| field      | description                         |
| ---------- | ----------------------------------- |
| model      | the name of the model               |
Matt Williams's avatar
Matt Williams committed
52
| created_at | the time the response was generated |
Matt Williams's avatar
Matt Williams committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
| response   | the current token                   |
| done       | whether the response is complete    |
| total_duration | total time spent generating the response |
| load_duration | time spent loading the model |
| sample_count | number of samples generated |
| sample_duration | time spent generating samples |
| prompt_eval_count | number of times the prompt was evaluated |
| prompt_eval_duration | time spent evaluating the prompt |
| eval_count | number of times the response was evaluated |
| eval_duration | time spent evaluating the response |



### Example Request

```curl
curl --location --request POST 'http://localhost:11434/api/generate' \
--header 'Content-Type: text/plain' \
--data-raw '{
    "model": "orca",
    "prompt": "why is the sky blue"
}'
```

### Example Response

```json
{"model":"orca","created_at":"2023-08-04T19:22:44.085127Z","response":" The","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.176425Z","response":" sky","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.18883Z","response":" appears","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.200852Z","response":" blue","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.213644Z","response":" because","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.225706Z","response":" of","done":false}
{"model":"orca","created_at":"2023-08-04T19:22:44.237686Z","response":" a","done":false}
.
.
.
{"model":"orca","created_at":"2023-08-04T19:22:45.487113Z","response":".","done":false}
Matt Williams's avatar
Matt Williams committed
91
{"model":"orca","created_at":"2023-08-04T19:22:45.499127Z","done":true,"total_duration":5589157167,"load_duration":3013701500,"sample_count":114,"sample_duration":81442000,"prompt_eval_count":46,"prompt_eval_duration":1160282000,"eval_count":113,"eval_duration":1325948000}
Matt Williams's avatar
Matt Williams committed
92
93
```

94
## Create a Model
Matt Williams's avatar
Matt Williams committed
95

Matt Williams's avatar
Matt Williams committed
96
**POST /api/create**
97
98

## List Local Models
Matt Williams's avatar
Matt Williams committed
99

Matt Williams's avatar
Matt Williams committed
100
101
102
**GET /api/tags**

### Return Object
Matt Williams's avatar
Matt Williams committed
103

Matt Williams's avatar
Matt Williams committed
104
105
106
107
108
109
110
111
112
113
114
115
```
{
  "models": [
    {
      "name": "modelname:tags",
      "modified_at": "2023-08-04T08:52:19.385406455-07:00",
      "size": size
    }
  ]

}
```
116
117

## Copy a Model
Matt Williams's avatar
Matt Williams committed
118

119
120
**/api/copy**

Matt Williams's avatar
Matt Williams committed
121
## Delete a Model
Matt Williams's avatar
Matt Williams committed
122

Matt Williams's avatar
Matt Williams committed
123
124
**/api/delete**

125
## Pull a Model
Matt Williams's avatar
Matt Williams committed
126

127
128
129
**/api/pull**

## Push a Model
Matt Williams's avatar
Matt Williams committed
130

Matt Williams's avatar
Matt Williams committed
131
132
133
134
**/api/push**

## Heartbeat

Matt Williams's avatar
Matt Williams committed
135
**/**