Skip to main content

llama-index llms dashscope integration

Project description

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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_llms_dashscope-0.6.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_llms_dashscope-0.6.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_dashscope-0.6.1.tar.gz.

File metadata

  • Download URL: llama_index_llms_dashscope-0.6.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","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}

File hashes

Hashes for llama_index_llms_dashscope-0.6.1.tar.gz
Algorithm Hash digest
SHA256 c55a270f2e2053b3c148a4254e6acf12114521f11b78e3a695d1af2b17300849
MD5 72935548d867f9bdac9baee96e096849
BLAKE2b-256 6dcbf5b6ed5007803ea880c4c7ab4aede3b8a22fe6c5a103a3baa22bf71840b1

See more details on using hashes here.

File details

Details for the file llama_index_llms_dashscope-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_dashscope-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","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}

File hashes

Hashes for llama_index_llms_dashscope-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a60d2f333e5eaca9c0463dbe3de9a5d0036b602662a2839a98a7f0ca4942b09
MD5 503aa903ce4d15a6948ea4812cc46bb2
BLAKE2b-256 8f544116c207f74eab6dc0d27d3825be95efce7588080d41f6e4be22932a1d82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page