"tests/L0/vscode:/vscode.git/clone" did not exist on "dec4fdd60039ee34dae41e4bc52f1fc6deb9ddeb"
api.md 4.47 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
The **Generate** endpoint takes a JSON object with the following fields:

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

Matt Williams's avatar
Matt Williams committed
21
Context is optional, but is used to provide additional context, such as memory of earlier prompts.
Matt Williams's avatar
Matt Williams committed
22
23
24
25
26
27
28
29
30
31
32
33

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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,
  "context":[1,31822,1,13,8458,31922 ... 382,871,550,389,266,7661,31844,382,820,541,4842,1954,661,645,590,3465,31843,2],
  "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
56
| created_at | the time the response was generated |
Matt Williams's avatar
Matt Williams committed
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
91
92
93
94
95
96
97
98
| response   | the current token                   |
| done       | whether the response is complete    |
| context    | vectorize context that can be supplied in the next request to continue the conversation |
| 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}
{"model":"orca","created_at":"2023-08-04T19:22:45.499127Z","done":true,"context":[1,31822,1,13,8458,31922,3244,31871,13,3838,397,363,7421,8825,342,5243,10389,5164,828,31843,9530,362,988,362,365,473,31843,13,13,8458,31922,9779,31871,13,23712,322,266,7661,4842,13,13,8458,31922,13166,31871,13,347,7661,4725,4842,906,287,260,12329,1676,6697,27554,27289,31843,4025,2990,322,985,550,287,260,9949,287,8286,31844,10990,427,2729,289,399,20036,31843,1408,21062,16858,266,4556,31876,31829,7965,31844,357,19322,16450,287,1900,859,362,22329,291,11944,31843,1872,16450,397,988,5497,661,266,23893,287,266,1954,31844,560,526,640,3304,266,1954,288,484,11468,31843,1813,31844,4842,1954,470,260,13830,23893,661,590,8286,31844,560,357,322,18752,541,4083,31843,672,1901,342,662,382,871,550,389,266,7661,31844,382,820,541,4842,1954,661,645,590,3465,31843,2],"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}
```

99
## Create a Model
Matt Williams's avatar
Matt Williams committed
100

Matt Williams's avatar
Matt Williams committed
101
**POST /api/create**
102
103

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

Matt Williams's avatar
Matt Williams committed
105
106
107
**GET /api/tags**

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

Matt Williams's avatar
Matt Williams committed
109
110
111
112
113
114
115
116
117
118
119
120
```
{
  "models": [
    {
      "name": "modelname:tags",
      "modified_at": "2023-08-04T08:52:19.385406455-07:00",
      "size": size
    }
  ]

}
```
121
122

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

124
125
**/api/copy**

Matt Williams's avatar
Matt Williams committed
126
## Delete a Model
Matt Williams's avatar
Matt Williams committed
127

Matt Williams's avatar
Matt Williams committed
128
129
**/api/delete**

130
## Pull a Model
Matt Williams's avatar
Matt Williams committed
131

132
133
134
**/api/pull**

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

Matt Williams's avatar
Matt Williams committed
136
137
138
139
**/api/push**

## Heartbeat

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