Skip to content

ModelProperties.cs

suncloudsmoon edited this page Dec 8, 2024 · 1 revision

Overview

The ModelProperties class in the TextForge namespace is responsible for handling various properties and constraints related to different models used in the application, focusing on context window lengths and supported models. It interacts with the OpenAI API and possibly other endpoints like Ollama.

Public Members

Variables

  • BaselineContextWindowLength: A constant integer set to 4096, representing a default context window length for models when specific information is not available.
  • EmbedModelList: A static list of strings including "all-minilm", "bge-m3", "bge-large", and "paraphrase-multilingual", which are embedding models handled differently or excluded in certain operations.

Functions

  • IsImageModel(string modelName): Determines if a given model name starts with "dall-e", identifying models used for generating images.
    • Parameters: modelName - the name of the model to check.
    • Returns: bool - whether the model is an image model.
  • ConvertChatHistoryToString(List chatHistory): Converts a list of chat messages into a single string by concatenating the text content of each message.
    • Parameters: chatHistory - the list of chat messages to convert.
    • Returns: string - the concatenated string of chat history.
  • GetContextLength(string modelName, OpenAIModelCollection availableModels): Calculates and returns the context length for a specified model name based on various conditions and dictionaries defined within the class.
    • Parameters: modelName - the name of the model to get the context length for, availableModels - the collection of available models.
    • Returns: int - the context length for the specified model.
  • GetLanguageModelList(OpenAIModelCollection availableModels): Filters and returns a list of model IDs from the available models, excluding embedding models and unsupported models.
    • Parameters: availableModels - the collection of available models.
    • Returns: IEnumerable<string> - the list of supported model IDs.

Private Members

Variables

  • _openAIModelsContextLength: A dictionary mapping specific OpenAI model names to their context lengths.
  • _unsupportedOpenAIModels: A list of strings representing model names that are not supported or handled differently.
  • IsOllamaEndpoint: A boolean indicating whether the endpoint being used is Ollama.
  • IsOllamaFetched: A boolean tracking whether the check for Ollama endpoint has been performed.
  • ollamaContextWindowCache: A dictionary caching the context window lengths for Ollama models.
  • _cultureHelper: An instance of CultureLocalizationHelper for handling localized strings.

Functions

  • IsOllama(OpenAIModelCollection availableModels): Checks if the models are from Ollama based on the OwnedBy property.
    • Parameters: availableModels - the collection of available models.
    • Returns: bool - whether the models are from Ollama.
  • GetOllamaModelContextWindow(string model): Retrieves the context window length for a specific Ollama model by making a request to the Ollama endpoint and parsing the JSON response.
    • Parameters: model - the name of the Ollama model to get the context length for.
    • Returns: int - the context length for the specified Ollama model.

Exceptions

  • OllamaMissingContextWindowException: A custom exception thrown when the context window length cannot be found for an Ollama model.
    • Parameters: message - a message describing the exception.
    • Throws: When the context window length is not found for an Ollama model.
Clone this wiki locally