getAgentLoopCoreFinalMessageText (output/messages.ts)

fastgpt · packages/service/core/workflow/dispatch/ai/agentLoopCore/application/output/messages.ts · typescript · Apache-2.0
ai, tag:embed-classified

Extracts final assistant text and reasoning from a message transcript.

// 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 type { ChatCompletionMessageParam } from '@fastgpt/global/core/ai/llm/type';

const getAssistantText = (message: ChatCompletionMessageParam) => {
  if (message.role !== 'assistant' || !message.content) return '';
  if (message.tool_calls?.length) return '';
  if (typeof message.content === 'string') return message.content;

  return message.content.map((item) => (item.type === 'text' ? item.text : '')).join('');
};

const getAssistantReasoning = (message: ChatCompletionMessageParam) => {
  if (message.role !== 'assistant' || !message.reasoning_content) return '';
  if (message.tool_calls?.length) return '';

  return message.rea

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

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

Get a free API key