LLM Chat Completion Request (request/createChatCompletion.ts)

fastgpt · packages/service/core/ai/llm/request/createChatCompletion.ts · typescript · Apache-2.0
ai, chat, lang:typescript

Handles the execution of chat completion requests to LLM providers with built-in error normalization and logging. Use this to abstract AI model interactions and manage request lifecycles.

// Source: https://github.com/labring/fastgpt | License: Apache-2.0 | Copyright 2023 Sealos
// Provided via justclaw.it.com; keep this notice with the code.
import { getErrText } from '@fastgpt/global/common/error/utils';
import type { UnStreamResponseType } from '@fastgpt/global/core/ai/llm/type';
import OpenAI from '@fastgpt/global/core/ai';
import { getAIApi, getModelOpenAIOptions } from '../../config';
import { normalizeRelayNoChannelError } from '../../../../thirdProvider/aiproxy/error';
import { getLogger, LogCategories } from '../../../../common/logger';
import { isStreamCompletionResponse } from './response/normalize';
import type { CreateChatCompletionProps, CreateChatCompletionResult } from './types';
import { sanitizeLLMRequestRecordPayload } from '../../record/controller';

con

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key