Для взаимодействия с языковыми моделями (LLM) ParagonAPI использует конечную точку завершения чата в REST API, что идентично формату от OpenAI:
https://rest.paragonapi.ru/v1/chat/completions
Вы можете работать с API через HTTP-запросы на любом языке, через официальные библиотеки или любую другую библиотеку, поддерживаемую сообществом.
Python
Чтобы установить официальную библиотеку Python, выполните следующую команду:
Выполните запрос:
from openai import OpenAI
client = OpenAI(
base_url="https://rest.paragonapi.ru/v1",
api_key="$PARAGON_API_KEY",
)
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
)
print(completion.choices[0].message.content)
Node.js
Чтобы установить официальную библиотеку Node.js, выполните следующую команду:
Выполните запрос:
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://rest.paragonapi.ru/v1",
apiKey: $PARAGON_API_KEY
});
async function main() {
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
});
console.log(completion.choices[0].message);
}
main();
Python
Чтобы установить официальную библиотеку Python, выполните следующую команду:
Выполните запрос:
from openai import OpenAI
client = OpenAI(
base_url="https://rest.paragonapi.ru/v1",
api_key="$PARAGON_API_KEY",
)
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
)
print(completion.choices[0].message.content)
Node.js
Чтобы установить официальную библиотеку Node.js, выполните следующую команду:
Выполните запрос:
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://rest.paragonapi.ru/v1",
apiKey: $PARAGON_API_KEY
});
async function main() {
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
});
console.log(completion.choices[0].message);
}
main();
cURL
curl https://rest.paragonapi.ru/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PARAGON_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
}'
Python
Вызов через библиотеку request:
import requests
import json
response = requests.post(
url="https://rest.paragonapi.ru/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {PARAGON_API_KEY}"
},
data=json.dumps({
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
})
)
print(response.json())
Node.js
Вызов через стандартный метод fetch:
fetch("https://rest.paragonapi.ru/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${PARAGON_API_KEY}`
},
body: JSON.stringify({
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Что такое LLM?"
}
]
})
})
.then(response => response.json())
.then(data => {
const assistantMessage = data.choices[0].message.content;
console.log(assistantMessage);
});