adds code snippets for chat completeions
This commit is contained in:
parent
d7bf98b68a
commit
90a11ea4c4
@ -93,6 +93,110 @@ paths:
|
||||
"temperature": 0.7,
|
||||
"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:
|
||||
get:
|
||||
operationId: listModels
|
||||
@ -113,38 +217,10 @@ paths:
|
||||
$ref: specs/models.yaml#/components/schemas/ListModelsResponse
|
||||
x-codeSamples:
|
||||
- lang: cURL
|
||||
source: |-
|
||||
source: |
|
||||
curl -X 'GET' \
|
||||
'http://localhost:1337/v1/models' \
|
||||
-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}:
|
||||
get:
|
||||
operationId: downloadModel
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user