Yandex AI Studio SDK

repository·master·Indexed 41 days ago

https://github.com/yandex-cloud/yandex-ai-studio-sdk

A multimodal Python SDK for Yandex Cloud AI Studio services, providing high-level abstractions for text generation (yandexgpt), chat, vision OCR, speech synthesis/recognition, and search indexing. Includes a CLI for building vector search indexes from local files, S3-compatible storage, Atlassian Confluence, and MediaWiki, as well as integration support for LangChain and Open WebUI.

Tokens
34.1K
Snippets
138
Records
189
Agent score
51%

What's inside Yandex AI Studio SDK

  1. Configure search index types and strategies

    master

    The Yandex AI Studio SDK provides several modules to define how search indexes are constructed, including file-based indexing, chunking strategies, combination strategies, and normalization strategies.

    Key components include:

    • SearchIndexFile: Used for creating indexes from local files.
    • index_type: Defines the fundamental type of the search index.
    • chunking_strategy: Determines how text is split into smaller segments (chunks) for indexing.
    • combination_strategy: Defines how chunks or results are combined.
    • normalization_strategy: Defines how data is normalized before indexing or retrieval.
  2. Configure Generative Search

    master
    Generative search functionality is configured using types from yandex_ai_studio_sdk._search_api.generative.config. This includes FilterType for specifying search filters and other configuration objects found in the generative.config module. Results for these searches are returned as objects defined in yandex_ai_studio_sdk._search_api.generative.result.
  3. Use the Chat class for conversational AI

    master
    The yandex_ai_studio_sdk._chat.Chat class is the primary interface for interacting with chat-based models within the Yandex AI Studio SDK. It manages conversational state and provides methods for generating responses based on chat history and user input. For specific implementation details regarding text generation and embeddings within the chat context, refer to the completions and text_embeddings documentation.
  4. Use the AsyncSpeechKitDomain for SpeechKit services

    master

    The AsyncSpeechKitDomain class is the entry point for interacting with Yandex SpeechKit services asynchronously within the SDK. It provides access to specialized domains for speech processing, specifically:

    • Text-to-Speech: Converting text into synthesized speech.
    • Speech-to-Text: Transcribing spoken audio into text.

    To use these features, you should access the sub-domains provided by an instance of AsyncSpeechKitDomain.

    from yandex_ai_studio_sdk._speechkit.domain import AsyncSpeechKitDomain
    
    # An instance of AsyncSpeechKitDomain provides access to:
    # - domain.text_to_speech
    # - domain.speech_to_text
  5. Use OCR features in Yandex AI Studio SDK

    master

    The SDK provides Vision capabilities, specifically Optical Character Recognition (OCR), to extract text from images. The OCR implementation is structured around three main components:

    1. OCRConfig: Used to configure the parameters of the OCR request.
    2. OCRResult: The object returned containing the extracted text and metadata.
    3. yandex_ai_studio_sdk._vision.ocr.text_annotation: Provides the underlying text annotation structures used to describe the location and content of recognized text.

    To perform OCR, you will typically instantiate an OCRConfig object and pass it to the vision service methods to receive an OCRResult.

  6. Understand the relationship between yandex-cloud-ml-sdk and yandex-ai-studio-sdk

    master

    The yandex-cloud-ml-sdk package serves as a compatibility wrapper for yandex-ai-studio-sdk starting from version 0.19.0.

    • The last standalone version of yandex-cloud-ml-sdk is 0.18.
    • Version 0.19.0 of yandex-cloud-ml-sdk is a wrapper that points to yandex-ai-studio-sdk version 0.19.0.

    If you are using yandex-cloud-ml-sdk version 0.19.0 or higher, you are effectively using the yandex-ai-studio-sdk via a compatibility layer.

  7. Configure Code Interpreter for Yandex AI Studio Agents

    master

    If you intend to use an agent with a code interpreter, you must perform these additional configuration steps in Open WebUI to ensure files are correctly passed to the agent rather than being handled by Open WebUI's internal RAG:

    1. Model Selection: Locate the model corresponding to your selected agent in the Open WebUI admin interface at /admin/settings/models.
    2. Disable File Context: In the model settings, turn off File Context. This prevents Open WebUI from attaching RAG context to user messages, allowing this pipe to attach the files directly to your request for code interpretation.
    3. Optimize File Attachment (Optional): To increase the speed of attaching files to the WebUI, navigate to /admin/settings/documents and enable Bypass Embedding and Retrieval.
  8. Install the Vector Stores CLI

    master

    The SDK includes a CLI for building vector search indexes from various sources. Depending on your data source, you may need to install specific extras:

    • Base CLI (Local files + Confluence): pip install yandex-ai-studio-sdk
    • S3 Support (S3 / Yandex Object Storage): pip install "yandex-ai-studio-sdk[cli-s3]"
    • Wiki Support (Wikipedia / MediaWiki): pip install "yandex-ai-studio-sdk[cli-wiki]"
    # Install base CLI (local files + Confluence)
    pip install yandex-ai-studio-sdk
    
    # With S3 / Yandex Object Storage support
    pip install "yandex-ai-studio-sdk[cli-s3]"
    
    # With Wikipedia / MediaWiki support
    pip install "yandex-ai-studio-sdk[cli-wiki]"
  9. Authenticate the Vector Stores CLI

    master

    The CLI resolves authentication automatically in the following order:

    1. Explicit credentials via --auth, YC_API_KEY, or YC_IAM_TOKEN.
    2. Yandex Cloud CLI (yc) if installed and configured.
    3. Compute Metadata Service (automatic on Yandex Compute Cloud VMs).

    Note: YC_API_KEY takes precedence over YC_IAM_TOKEN if both are set.

    Required Environment Variables:

    • YC_FOLDER_ID: Your Yandex Cloud folder ID.

    Optional Authentication Variables:

    • YC_API_KEY: Your API key.
    • YC_IAM_TOKEN: Your IAM token.
    export YC_FOLDER_ID=b1gxxxxxxxxxxxxx
    export YC_API_KEY=AQVNxxxxxxxxxxxxxx
    # or
    export YC_IAM_TOKEN=t1.9euelZxxxxxxxxxxxxxx
  10. Integrate Yandex AI Studio with LangChain

    master

    To use the SDK with LangChain, you must install the package with the langchain extra. Once installed, you can convert a completion model into a LangChain-compatible object using the .langchain() method. This allows you to use standard LangChain methods like .invoke() with HumanMessage and AIMessage objects.

    pip install yandex-ai-studio-sdk[langchain]
    from yandex_ai_studio_sdk import AIStudio
    from langchain_core.messages import AIMessage, HumanMessage
    
    sdk = AIStudio(folder_id="...", auth="<APIKey/IAMToken/SomethingElse>")
    
    model = sdk.models.completions('yandexgpt').langchain()
    
    langchain_result = model.invoke([
        HumanMessage(content="hello!"),
        AIMessage(content="Hi there human!"),
        HumanMessage(content="Meow!"),
    ])
  11. Integrate Yandex AI Studio Agents with Open WebUI

    master

    This integration allows you to use agents created in the Yandex AI Studio service as manifold pipes within Open WebUI.

    Setup Steps

    1. Create an Agent: Visit https://aistudio.yandex.ru/ and create your desired agent.
    2. Obtain API Key: Retrieve your API Key from https://aistudio.yandex.ru/platform/folders/<your_folder_id>/access.
    3. Import Pipe: Import this manifold pipe into your Open WebUI instance.
    4. Configure Valves: In Open WebUI, configure the following valve settings:
      • Yandex Cloud Api Key: The key obtained in step 2.
      • Yandex Cloud Folder Id: Your Yandex Cloud folder ID.
      • Agent Ids: The IDs of the agents created in step 1 (supports one or more IDs separated by commas).
      • Agent Names (Optional): Custom names for the agents to appear more cleanly in the WebUI.