Skip to main content

LlamaIndex Llms Integration: Dashscope

Installation

  1. Install the required Python package:

    pip install llama-index-llms-dashscope
    
  2. Set the DashScope API key as an environment variable:

    export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
    

    Alternatively, you can set it in your Python script:

    import os
    
    os.environ["DASHSCOPE_API_KEY"] = "YOUR_DASHSCOPE_API_KEY"
    

Usage

Basic Recipe Generation

To generate a basic vanilla cake recipe:

from llama_index.llms.dashscope import DashScope, DashScopeGenerationModels

# Initialize DashScope object
dashscope_llm = DashScope(model_name=DashScopeGenerationModels.QWEN_MAX)

# Generate a vanilla cake recipe
resp = dashscope_llm.complete("How to make cake?")
print(resp)

Streaming Recipe Responses

For real-time streamed responses:

responses = dashscope_llm.stream_complete("How to make cake?")
for response in responses:
    print(response.delta, end="")

Multi-Round Conversation

To have a conversation with the assistant and ask for a sugar-free cake recipe:

from llama_index.core.base.llms.types import MessageRole, ChatMessage

messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(role=MessageRole.USER, content="How to make cake?"),
]

# Get first round response
resp = dashscope_llm.chat(messages)
print(resp)

# Continue conversation
messages.append(
    ChatMessage(role=MessageRole.ASSISTANT, content=resp.message.content)
)
messages.append(
    ChatMessage(role=MessageRole.USER, content="How to make it without sugar?")
)

# Get second round response
resp = dashscope_llm.chat(messages)
print(resp)

Handling Sugar-Free Recipes

For sugar-free cake recipes using honey as a sweetener:

resp = dashscope_llm.complete("How to make cake without sugar?")
print(resp)

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/dashscope/

Metadata

Release files for llama-index-llms-dashscope 0.8.0

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-llms-dashscope 0.8.0
File Size Uploaded Provenance Actions
llama_index_llms_dashscope-0.8.0.tar.gz 8.1 kB Without provenance Details for llama_index_llms_dashscope-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-dashscope 0.8.0
File Interpreter ABI Platform Actions
llama_index_llms_dashscope-0.8.0-py3-none-any.whl Python 3 none any Details for llama_index_llms_dashscope-0.8.0-py3-none-any.whl

Total release size: 16.4 kB

Release files / llama_index_llms_dashscope-0.8.0.tar.gz

Download URL llama_index_llms_dashscope-0.8.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
395c7c83f730e569bd1911a5a8a1a1b8d738aae0fb6c17f05a91fc1dc4efe5b3
BLAKE2b-256 checksum
How to use checksums
7b0a69fe228ec930dd83699bd24cfa53e74cddce4601e195e694529a9e66753a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_llms_dashscope-0.8.0-py3-none-any.whl

Download URL llama_index_llms_dashscope-0.8.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae8fd04fb968426c81e67e087e9d28bd6d20341b24757ca0144c2f2d738509b3
BLAKE2b-256 checksum
How to use checksums
15178dd7b8f87601a99a451d1a91cc4702890d2392177c41f4901bd3c63181ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-llms-dashscope 0.8.0

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