AIConfig Documentation

repository·main·Indexed 22 days ago

https://github.com/lastmile-ai/aiconfig

An open-source framework for building production-grade generative AI applications by separating prompts, models, and parameters from application code into version-controllable JSON configurations. It supports integrations with Anyscale Endpoints, OpenAI, and HuggingFace, and provides patterns for prompt routing, Chain-of-Verification (CoVe), function calling, and safety classification using LLaMA Guard.

Tokens
92.1K
Snippets
305
Records
413
Agent score
71%

What's inside AIConfig

  1. Overview of AIConfig

    main

    AIConfig is a system for saving prompts, models, and model parameters as source-control-friendly configurations. It decouples generative AI settings from application code, allowing for independent iteration on prompts and model parameters.

    Key components include:

    • Prompts as configs: A standardized JSON format for storing generative AI settings, prompt inputs/outputs, and metadata.
    • Model-agnostic SDKs: Python and Node.js SDKs that allow you to use aiconfig with any generative AI model (text, image, or audio).
    • AI Workbook editor: A notebook-like playground for visually editing aiconfig files, running prompts, and chaining tasks.
  2. What is AIConfig

    main

    AIConfig is a source-control friendly framework for managing generative AI prompts, models, and model parameters as configuration files. It decouples AI behavior from application code, allowing developers to iterate on prompts and models independently of the core software logic.

    Key Benefits

    • Separation of Concerns: Decouples prompts and model settings from application code, enabling collaborative development between software engineers and AI specialists.
    • Simplified Application Code: Instead of complex model-specific logic, applications can simply call config.run() via the SDK.
    • Improved Governance: Since aiconfig is a standardized JSON artifact, it can be version-controlled to ensure reproducibility, provenance, and easier evaluation of AI behavior.
    • Rapid Iteration: Supports a notebook-like playground (AI Workbook editor) for visual editing, prompt testing, and model tweaking without redeploying code.
  3. Build a custom CLI chat bot with Cli-Mate

    main

    Cli-Mate is a tool built using AIConfig designed to create custom CLI chat bots. While it can function as a general-purpose chatbot, its primary use case is interactive code modification.

    Key features include:

    • Using the AIConfig runtime API to execute arbitrary-length sequences of prompts.
    • Leveraging streaming callbacks to allow users to gracefully interrupt LLM output and return to the query prompt.
  4. What are Gradio Notebooks?

    main

    Gradio Notebooks is a notebook component for generative AI designed to create Hugging Face Spaces quickly (in under 10 lines of code). It provides a familiar, Jupyter-inspired interface for interacting with multimodal models (text, image, audio) in a single space.

    Key capabilities include:

    • Chaining multiple models together.
    • Experimenting with a pre-built UI for multimodal interaction.
    • Sharing outputs via shareable URLs.
    • Exporting configurations as aiconfig.json files to be used in production applications via the AIConfig SDK.
  5. Explore AIConfig Cookbooks and Guides

    main

    AIConfig provides a variety of cookbooks in its repository that demonstrate specific implementation patterns and capabilities. These examples serve as templates for building complex AI-driven applications.

    Available patterns include:

    • Chatbots: Implement interactive CLI agents like Wizard GPT or code-modification assistants like CLI-mate.
    • Retrieval Augmented Generation (RAG): Learn how to pass external data into prompts using vector databases like ChromaDB or MongoDB Vector Search.
    • Function Calling: Implement structured tool use, such as the OpenAI function calling example.
    • Prompt Routing: Implement logic to route queries to different prompts or models based on input.
    • Chain of Thought (CoT): Implement advanced reasoning patterns, including Chain of Verification (CoVe) to reduce hallucinations.
    • Model-Specific Implementations: Specialized guides for using LLaMA2, Hugging Face (Mistral-7B), and Google PaLM with the AIConfig framework.
  6. Stanford LastMile Challenge Rubric

    main

    Projects are evaluated based on the following criteria:

    • Creativity and Originality: The project should be unique and demonstrate creative use of AIConfig and AI workbooks.
    • Functionality: The project must be bug-free, functional, and easily reproducible by others.
    • Use of AIConfig: Effective and innovative integration of AIConfig and AI workbooks is a key factor.
    • Documentation: A README.md must clearly explain the project's purpose, mechanics, and how AIConfig/workbooks are utilized.
  7. Overview of AIConfig core concepts

    main

    AIConfig is a system designed to decouple generative AI settings from application code. It provides:

    • Prompts as configs: A standardized JSON format to store model settings, prompt inputs/outputs, and metadata.
    • Model-agnostic SDK: Python and Node SDKs that allow you to use any generative AI model (text, image, audio) by extending the configuration.
    • AI Workbook editor: A notebook-like playground to visually edit aiconfig files, run prompts, and chain tasks without writing application code.
    • Prompt Chaining: Uses {{handlebars}} syntax to pass dynamic data between prompts and allow parameterization.
  8. Use AIConfigRuntime as the SDK entrypoint

    main
    The AIConfigRuntime object is the primary interface for interacting with AIConfig programmatically. It provides the methods necessary to perform CRUD operations on prompts, models, parameters, and metadata, and serves as the engine for running inference and managing prompt dependencies.
  9. How the AIConfig Editor works

    main

    The AIConfig Editor is a UI layer for the AIConfig JSON/YAML schema.

    Core Workflow:

    1. Installation: Upon installation, the extension installs the python-aiconfig pip package in your Python environment.
    2. Execution: When you open a *.aiconfig.yaml file, the extension launches a Python server running the AIConfig SDK.
    3. Runtime: As you edit and run prompts in the UI, the server uses the SDK to execute them. This architecture allows you to use any AIConfig Extension installed in your Python environment directly within the VS Code editor.
  10. Use ParameterizedModelParser for dynamic prompts

    main

    If your model needs to handle prompts with placeholders (using handlebar syntax like {{variable}}), inherit from ParameterizedModelParser instead of the base ModelParser. This subclass provides built-in support for resolving these placeholders during the serialization and deserialization process.

    Additional capabilities of ParameterizedModelParser:

    • Dynamic Prompt Generation: Automatically replaces placeholders with actual values.
    • run_with_dependencies: Allows executing prompts with resolved dependencies and prompt references.

    Helper methods provided by ParameterizedModelParser:

    • resolve_prompt_template() (Python/TS): Resolves a templated string with provided parameters.
    • get_prompt_template() (Python/TS): An overrideable method to specify how templates are extracted from prompts.
  11. Define prompts in AIConfig

    main

    Prompts are the primary building blocks of an aiconfig. They store inputs, optional outputs, and prompt-specific metadata.

    Prompt Structure

    PropertyRequirementDescription
    nameRequiredA unique identifier used to reference the prompt in the SDK or other prompts.
    inputRequiredThe model input. Can be a string or a complex object (e.g., for multi-modal inputs).
    metadataOptionalPrompt-specific settings. These are merged with root metadata, but prompt-level values take precedence.
    outputsOptionalAn array of previous inference results (cached outputs).

    Prompt Input Types

    The input field supports two main forms:

    1. String: A simple text prompt.
    2. Object: A complex structure for multi-modal data. A ModelParser may use keys like data or specific MIME types to interpret the object.
    type PromptInput =
      | {
          /**
           * Input to the model. The structure is up to the ModelParser.
           */
          data?: JSONValue;
          [k: string]: any;
        }
      | string;