llm-util.ts


Overview

The llm-util.ts file provides a set of utility functions related to handling identifiers and names for Large Language Models (LLMs) in the system. These functions facilitate parsing, formatting, and extracting meaningful parts of LLM names and IDs, which are often composite strings containing multiple pieces of information separated by delimiters.

This utility is essential for consistent naming conventions and identifier management when interacting with various third-party LLM integrations, particularly when dealing with model identifiers that combine provider IDs and model names.


Functions

getLLMIconName(fid: string, llm_name: string): string

Returns an icon name or identifier based on the feature ID (fid) and the LLM name.


getLlmNameAndFIdByLlmId(llmId?: string): { fId?: string; llmName?: string }

Parses a composite LLM ID string and extracts the LLM name and feature ID.


getRealModelName(llmName: string): string

Extracts the core model name from a possibly decorated model string.


buildLlmUuid(llm: IThirdOAIModel): string

Constructs a unique identifier string for an LLM by combining its name and feature ID.


Implementation Details


Interaction with Other System Components


Mermaid Diagram

flowchart TD
    A[getLLMIconName(fid, llm_name)]
    B[getLlmNameAndFIdByLlmId(llmId)]
    C[getRealModelName(llmName)]
    D[buildLlmUuid(llm: IThirdOAIModel)]

    A -->|Uses fid and llm_name| Output1[Icon name string]
    B -->|Splits llmId by '@'| Output2[{ llmName, fId }]
    C -->|Splits llmName by '__'| Output3[Real model name]
    D -->|Concatenate llm_name and fid| Output4[LLM UUID string]

    style A fill:#f9f,stroke:#333,stroke-width:1px
    style B fill:#bbf,stroke:#333,stroke-width:1px
    style C fill:#bfb,stroke:#333,stroke-width:1px
    style D fill:#fbf,stroke:#333,stroke-width:1px

Summary

The llm-util.ts file is a concise but crucial utility module for managing LLM identifiers and names within the system. It encapsulates common string parsing and formatting logic to maintain consistent handling of LLM-related strings across UI and backend components. Its simple yet effective functions support the integration of multiple LLM providers by standardizing how model names and feature IDs are interpreted and combined.