Search…
Completions
Generates one or more completions of text based on the provided prompt.

Create completion

post
https://example.forefront.link
Create completion

Example request

Python
cURL
1
import requests
2
import json
3
4
headers = {"Authorization": "Bearer <INSERT_YOUR_TOKEN>"}
5
6
body = {
7
"text": "Once upon a time",
8
"top_p": 1,
9
"top_k": 40,
10
"temperature": 0.8,
11
"repetition_penalty": 1.2,
12
"length": 256,
13
"stop_sequences": ["bird", "cat", "dog"]
14
}
15
16
res = requests.post(
17
"https://vanilla-gpt-j-forefront.forefront.link",
18
json=body,
19
headers=headers
20
)
21
22
data = res.json()
23
24
completion = data['result'][0]['completion'])
Copied!
1
curl https://DEPLOYMENT_NAME-TEAM_SLUG.forefront.link \
2
-H 'Content-Type: application/json' \
3
-H 'Authorization: Bearer YOUR_API_KEY' \
4
-d '{
5
"text": "Once upon a time",
6
"top_p": 1,
7
"top_k": 40,
8
"temperature": 0.8,
9
"repetition_penalty": 1.2,
10
"length": 256,
11
"stop_sequences": ["bird", "cat", "dog"]
12
}'
Copied!

Stream completion

get
https://example.forefront.link
Stream completion

How to use

Our streaming API uses the built in Javascript EventSource object, streaming tokens via Server Sent Events (SSE). If you're using another language, you'll need to find an equivalent API to listen for these events. Because the EventSource API doesn't support POST requests, you'll have to put all of your params into a query string, and URI Encode it appropriately. Here's some sample front end JS code showing how you can do this, which you can use as a starting point for other languages.
1
url = '' // for example <https://example.forefront.link>
2
api_key = '' // navigate to Settings => API Key
3
4
encodeURIComponent(JSON.stringify(stop.map(s => s.replaceAll('\\n', '\n'))))
5
)
6
7
// helper function to construct URL
8
const makeUrlForEventSource = (input) => (
9
`${url}/?text=${encodeURIComponent(input)
10
}&length=${length
11
}&repetition_penalty=${rep
12
}&temperature=${temperature
13
}&top_p=${topP
14
}&top_k=${topK
15
}&stop_sequences=${processStopSequences(stop)
16
}&authorization=Bearer ${api_key}`
17
);
18
19
// helper function to submit request and listen for events
20
const handleEventSourceSubmit = (input) => {
21
22
const url = makeUrlForEventSource(input)
23
const source = new EventSource(url, { withCredentials: false });
24
25
source.addEventListener('update', (e) => {
26
handleStream(e.data)
27
})
28
29
source.addEventListener('end', () => {
30
source.close()
31
})
32
33
}
Copied!
Last modified 24d ago