UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

37 lines (30 loc) 1.17 kB
import OpenAI from 'openai'; import { ChatStreamPayload, ModelProvider } from '../types'; import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory'; export const LobePerplexityAI = createOpenAICompatibleRuntime({ baseURL: 'https://api.perplexity.ai', chatCompletion: { handlePayload: (payload: ChatStreamPayload) => { // Set a default frequency penalty value greater than 0 const { presence_penalty, frequency_penalty, stream = true, temperature, ...res } = payload; let param; // Ensure we are only have one frequency_penalty or frequency_penalty if (presence_penalty !== 0) { param = { presence_penalty }; } else { const defaultFrequencyPenalty = 1; param = { frequency_penalty: frequency_penalty || defaultFrequencyPenalty }; } return { ...res, ...param, stream, temperature: temperature >= 2 ? undefined : temperature, } as OpenAI.ChatCompletionCreateParamsStreaming; }, }, debug: { chatCompletion: () => process.env.DEBUG_PERPLEXITY_CHAT_COMPLETION === '1', }, provider: ModelProvider.Perplexity, });