Class OpenAi


  • public class OpenAi
    extends Object
    • Constructor Detail

      • OpenAi

        public OpenAi()
    • Method Detail

      • reinsertCodes

        public static List<List<InlineCodeRef>> reinsertCodes​(String modelName,
                                                              List<LayeredSegment> layeredSegments)
        Reinserts inline codes into target segments using an LLM to align them with source codes.

        This method analyzes source and target text segments and uses an OpenAI model to determine the correct positions for inline codes in the target text based on word/phrase alignment with the source text.

        The method guarantees to return a list of the same size as the input layeredSegments, with empty lists for segments that have no codes or when processing fails.

        Parameters:
        modelName - the OpenAI model name to use (e.g., "gpt-5-mini")
        layeredSegments - the list of segments containing source and target text with code references
        Returns:
        a list of code reference lists, one per input segment. Never null, always the same size as layeredSegments. Individual lists are never null (empty lists for no codes).
      • alignParagraphsAndSentences

        public static AlignmentData.CombinedAlignmentOutput alignParagraphsAndSentences​(String modelName,
                                                                                        AlignmentData.CombinedAlignmentInput input)
                                                                                 throws Exception
        Performs combined paragraph and sentence alignment using an LLM.

        This method sends a request to align both paragraphs and sentences in a single API call. The input contains source and target paragraphs with their segmented sentences. The LLM first aligns paragraphs (which may be split, merged, or reordered between documents), then aligns sentences within each aligned paragraph pair.

        Parameters:
        modelName - the OpenAI model name to use (e.g., "gpt-4o-mini")
        input - the alignment input containing source and target paragraphs with segments
        Returns:
        the alignment output with paragraph and sentence alignments
        Throws:
        Exception - if the API call fails or returns invalid data
      • getClient

        public static com.openai.client.OpenAIClient getClient()