Skip to content

qanary-component-helpers/generate-clarification-question

This page is auto-generated from TSDoc output. Edit the source file, not this Markdown.

qanary-component-helpers/generate-clarification-question

Section titled “qanary-component-helpers/generate-clarification-question”
  • Package: @leipzigtreechat/qanary-component-helpers
  • Source file: packages/qanary-component-helpers/src/generate-clarification-question.ts

Context describing the ambiguity that triggered a clarification request.

function generateClarificationQuestion(context: ClarificationContext, modelFactory: () => LanguageModel, generateFn: GenerateTextFn): Promise<string | null>

Uses an LLM to generate a human-readable clarification question based on the provided ambiguity context.

The generated text is intended to be stored as an AnnotationOfClarification in the Qanary knowledge graph so that the chatbot can present it to the user.

Parameters

  • context (ClarificationContext): Describes the original question and what is ambiguous.
  • modelFactory (() => LanguageModel): Optional override for the LLM model factory (for testing / DI).
  • generateFn (GenerateTextFn): Optional override for the text-generation function. When omitted the function dynamically imports generateText from ai. Returns
  • Promise<string | null>: The clarification question string, or null if generation fails. Defined at: line 51
interface ClarificationContext

Context describing the ambiguity that triggered a clarification request.

Properties

  • question (string): The original user question.
  • componentName (string): The component that encountered the ambiguity.
  • ambiguityDescription (string): A description of what is ambiguous and why clarification is needed. Defined at: line 7
type GenerateTextFn = (options: {
model: LanguageModel;
system: string;
prompt: string;
}) => Promise<{ text: string }>

Signature for a text-generation function compatible with the AI SDK’s generateText. Accepting this as a parameter allows callers (and tests) to inject their own implementation without having to mock the ai module.

Defined at: line 21