Skip to main content

LlamaIndex Multi-Modal-Llms Integration: ZhipuAI

Installation

%pip install llama-index-multi-modal-llms-zhipuai
!pip install llama-index

Basic usage

# Import ZhipuAI
import os
from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.multi_modal_llms.zhipuai import ZhipuAIMultiModal

# Set your environment variables
os.environ["ZHIPUAI_API_KEY"] = "Your API KEY"
os.environ["ZHIPUAI_TEST_VIDEO"] = "xxx.mp4"

# Call chat/complete with glm-4v-plus (types support: text, image_url, video_url)
llm = ZhipuAIMultiModal(
    model="glm-4v-plus", api_key=os.getenv("ZHIPUAI_API_KEY")
)
with open(os.getenv("ZHIPUAI_TEST_VIDEO"), "rb") as video_file:
    video_base = base64.b64encode(video_file.read()).decode("utf-8")
messages_1 = [
    ChatMessage(
        role=MessageRole.USER,
        content=[
            {"type": "video_url", "video_url": {"url": video_base}},
            {"type": "text", "text": "descript the video"},
        ],
    ),
]

print(llm.chat(messages_1))
print(llm.stream_chat(messages_1))
# Output:
# <class 'llama_index.core.base.llms.types.ChatResponse'>
# assistant: The camera shoots the sky, with white clouds moving from the right side of the screen to the left. Then, the clouds move upwards, and the camera pans to the right.
# <generator object llm_chat_callback.<locals>.wrap.<locals>.wrapped_llm_chat.<locals>.wrapped_gen at 0x127853350>

messages_2 = [
    ChatMessage(
        role=MessageRole.USER,
        content="descript the video",
    ),
]

print(llm.chat(messages_2, video_url=video_base))
print(llm.stream_chat(messages_2, video_url=video_base))
# Output:
# <class 'llama_index.core.base.llms.types.ChatResponse'>
# assistant: The camera shoots the sky, with white clouds moving from the right side of the screen to the left. Then, the clouds move upwards, and the camera pans to the right.
# <generator object llm_chat_callback.<locals>.wrap.<locals>.wrapped_llm_chat.<locals>.wrapped_gen at 0x135853350>

print(llm.complete("descript the video", video_url=video_base))
print(llm.stream_complete("descript the video", video_url=video_base))
# Output:
# <class 'llama_index.core.base.llms.types.ChatResponse'>
# The camera captures a downward shot of the sky, with white clouds drifting across the frame. The clouds are moving from the right side of the screen to the left, and the camera follows their movement, panning to the left.
# <generator object llm_completion_callback.<locals>.wrap.<locals>.wrapped_llm_predict.<locals>.wrapped_gen at 0x1175535b0>

# Call chat/complete with cogview or cogvideo
llm = ZhipuAIMultiModal(
    model="cogvideox", api_key=os.getenv("ZHIPUAI_API_KEY")
)
messages = [
    ChatMessage(
        role=MessageRole.USER,
        content=[{"type": "text", "text": "a bird flying in the sky"}],
    ),
]

print(llm.chat(messages))
print(llm.complete("a bird flying in the sky"))
# Output:
# <class 'llama_index.core.base.llms.types.ChatResponse'>
# assistant: https://aigc-files.bigmodel.cn/api/cogvideo/bcdaa436-xxxx-11ef-a354-628f45da38f5_0.mp4
# <class 'llama_index.core.base.llms.types.ChatResponse'>
# https://aigc-files.bigmodel.cn/api/cogvideo/ce55d168-xxxx-11ef-b2eb-72fab4c14186_0.mp4

ZhipuAI Documentation

usage: https://bigmodel.cn/dev/howuse/introduction

api: https://bigmodel.cn/dev/api/normal-model/glm-4v

Metadata

Release files for llama-index-multi-modal-llms-zhipuai 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-multi-modal-llms-zhipuai 0.3.1
File Size Uploaded Provenance Actions
llama_index_multi_modal_llms_zhipuai-0.3.1.tar.gz 6.8 kB Without provenance Details for llama_index_multi_modal_llms_zhipuai-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-multi-modal-llms-zhipuai 0.3.1
File Interpreter ABI Platform Actions
llama_index_multi_modal_llms_zhipuai-0.3.1-py3-none-any.whl Python 3 none any Details for llama_index_multi_modal_llms_zhipuai-0.3.1-py3-none-any.whl

Total release size: 13.5 kB

Release files / llama_index_multi_modal_llms_zhipuai-0.3.1.tar.gz

Download URL llama_index_multi_modal_llms_zhipuai-0.3.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7d221cf75a8a5c9612cdb10324a0df5a14c24d0e5c290b5a1dab7659015dd03c
BLAKE2b-256 checksum
How to use checksums
00fd47284f945fb431fad114dd19bfd4679efb5ffc4d6da83402fc8a72ce2fda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / llama_index_multi_modal_llms_zhipuai-0.3.1-py3-none-any.whl

Download URL llama_index_multi_modal_llms_zhipuai-0.3.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecce8e1a7b27bfa810509c7a90c6cae2b3fe7cb8d8640a97cf88e3a82707dda7
BLAKE2b-256 checksum
How to use checksums
5454af05257dd1c3cb0359e0448950cd4ec05f2963eecd4b18f0cf81ce545849
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Security for llama-index-multi-modal-llms-zhipuai 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page