Search…
⌃K

Completions

Generate completions based on the provided prompt and parameters.

Create completion

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

Example request

Python
Javascript
cURL
import requests
import json
headers = {"Authorization": "Bearer <INSERT_YOUR_TOKEN>"}
body = {
"prompt": "Once upon a time",
"max_tokens": 64,
"top_p": 1,
"top_k": 40,
"temperature": 0.8,
"repetition_penalty": 1,
"stop_sequences": ["bird", "cat", "dog"]
}
res = requests.post(
"https://vanilla-gpt-j-forefront.forefront.link",
json=body,
headers=headers
)
data = res.json()
completion = data['result'][0]['completion'])
const fetch = require('node-fetch');
const url = 'https://shared-api.forefront.link/organization/G1Yk5qgNGeTb/gpt-j-6b-vanilla/completions/2JrDQ5BhJAm6';
const headers = {
"Authorization": "Bearer 3ba7a48d87544fd4b54b13af",
"Content-Type": "application/json"
};
const body = {
prompt: "Once upon a time",
max_tokens: 64,
top_p: 1,
top_k: 40,
temperature: 0.8,
repetition_penalty: 1,
stop_sequences: ["bird", "cat", "dog"]
};
fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(body)
}).then(async (res) => {
const data = await res.json()
console.log(data)
})java
curl https://DEPLOYMENT_NAME-TEAM_SLUG.forefront.link \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"prompt": "Once upon a time",
"max_tokens": 64,
"top_p": 1,
"top_k": 40,
"temperature": 0.8,
"repetition_penalty": 1,
"stop_sequences": ["bird", "cat", "dog"]
}'

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.
url = '' // for example <https://example.forefront.link>
api_key = '' // navigate to Settings => API Key
encodeURIComponent(JSON.stringify(stop.map(s => s.replaceAll('\\n', '\n'))))
)
// helper function to construct URL
const makeUrlForEventSource = (input) => (
`${url}/?text=${encodeURIComponent(input)
}&length=${length
}&repetition_penalty=${rep
}&temperature=${temperature
}&top_p=${topP
}&top_k=${topK
}&stop_sequences=${processStopSequences(stop)
}&authorization=Bearer ${api_key}`
);
// helper function to submit request and listen for events
const handleEventSourceSubmit = (input) => {
const url = makeUrlForEventSource(input)
const source = new EventSource(url, { withCredentials: false });
source.addEventListener('update', (e) => {
handleStream(e.data)
})
source.addEventListener('end', () => {
source.close()
})
}