コンテンツにスキップ

パープレキシティ

パープレキシティは、AI駆動の回答エンジンです。

エンドポイント

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-ai

例 fetch リクエスト
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-ai/chat/completions \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer {perplexity_token}' \
--data '{
"model": "mistral-7b-instruct",
"messages": [
{
"role": "user",
"content": "Cloudflareとは何ですか?"
}
]
}'

パープレキシティは独自のSDKを持っていませんが、OpenAI SDKとの互換性があります。以下のようにOpenAI SDKを使用してAI Gatewayを通じてパープレキシティの呼び出しを行うことができます:

JavaScript
import OpenAI from "openai";
const apiKey = env.PERPLEXITY_API_KEY;
const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/perplexity-ai`;
const perplexity = new OpenAI({
apiKey,
baseURL,
});
const model = "mistral-7b-instruct";
const messages = [{ role: "user", content: "Cloudflareとは何ですか?" }];
const maxTokens = 20;
const chatCompletion = await perplexity.chat.completions.create({
model,
messages,
max_tokens: maxTokens,
});