adds code snippets for chat completeions

This commit is contained in:
avb-is-me 2024-02-27 08:02:23 +00:00
parent d7bf98b68a
commit 90a11ea4c4

View File

@ -93,6 +93,110 @@ paths:
"temperature": 0.7, "temperature": 0.7,
"top_p": 0.95 "top_p": 0.95
}' }'
- lang: JavaScript
source: |-
const data = {
messages: [
{
content: 'You are a helpful assistant.',
role: 'system'
},
{
content: 'Hello!',
role: 'user'
}
],
model: 'tinyllama-1.1b',
stream: true,
max_tokens: 2048,
stop: ['hello'],
frequency_penalty: 0,
presence_penalty: 0,
temperature: 0.7,
top_p: 0.95
};
fetch('http://localhost:1337/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data));
- lang: Node.js
source: |-
const fetch = require('node-fetch');
const data = {
messages: [
{
content: 'You are a helpful assistant.',
role: 'system'
},
{
content: 'Hello!',
role: 'user'
}
],
model: 'tinyllama-1.1b',
stream: true,
max_tokens: 2048,
stop: ['hello'],
frequency_penalty: 0,
presence_penalty: 0,
temperature: 0.7,
top_p: 0.95
};
fetch('http://localhost:1337/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data));
- lang: Python
source: >-
import requests
import json
data = {
"messages": [
{
"content": "You are a helpful assistant.",
"role": "system"
},
{
"content": "Hello!",
"role": "user"
}
],
"model": "tinyllama-1.1b",
"stream": true,
"max_tokens": 2048,
"stop": [
"hello"
],
"frequency_penalty": 0,
"presence_penalty": 0,
"temperature": 0.7,
"top_p": 0.95
}
response =
requests.post('http://localhost:1337/v1/chat/completions',
json=data)
print(response.json())
/models: /models:
get: get:
operationId: listModels operationId: listModels
@ -113,38 +217,10 @@ paths:
$ref: specs/models.yaml#/components/schemas/ListModelsResponse $ref: specs/models.yaml#/components/schemas/ListModelsResponse
x-codeSamples: x-codeSamples:
- lang: cURL - lang: cURL
source: |- source: |
curl -X 'GET' \ curl -X 'GET' \
'http://localhost:1337/v1/models' \ 'http://localhost:1337/v1/models' \
-H 'accept: application/json' -H 'accept: application/json'
- lang: JavaScript
source: |-
const response = await fetch('http://localhost:1337/v1/models', {
method: 'GET',
headers: {Accept: 'application/json'}
});
const data = await response.json();
- lang: Python
source: |-
import requests
url = 'http://localhost:1337/v1/models'
headers = {'Accept': 'application/json'}
response = requests.get(url, headers=headers)
data = response.json()
- lang: Node.js
source: |-
const fetch = require('node-fetch');
const url = 'http://localhost:1337/v1/models';
const options = {
method: 'GET',
headers: { Accept: 'application/json' }
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json));
/models/download/{model_id}: /models/download/{model_id}:
get: get:
operationId: downloadModel operationId: downloadModel