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.7.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.7.0
File Size Uploaded Provenance Actions
llama_index_llms_dashscope-0.7.0.tar.gz 8.2 kB Without provenance Details for llama_index_llms_dashscope-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 16.5 kB

Release files / llama_index_llms_dashscope-0.7.0.tar.gz

Download URL llama_index_llms_dashscope-0.7.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dbc87dd0440b360ac11eabfcc88e43b6a1b5307de0ff5147b4e3a13a5b6a1420
BLAKE2b-256 checksum
How to use checksums
a70d5e75a33c8da66cf89e809da578d758cb216bcef696e32a93c3a72a34c7d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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.7.0-py3-none-any.whl

Download URL llama_index_llms_dashscope-0.7.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e742159c4d02751cabc02707ec49810570c05c9d8d14d0622925bc17a6a8f7f
BLAKE2b-256 checksum
How to use checksums
0d97f7578ead0735301fc2b18e32e7bba6ee44423a0b33cb2c0ec8f2f4dd0331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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.7.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