Dashscope API
Dashscope API (Qwen 모델)
Alibaba Cloud의 모든 Qwen 모델을 지원해요. completion 요청 시 dashscope/ 접두사로 설정하기만 하면 돼요.
이 플랫폼은 이제 중국 본토 외 지역에서는 QwenCloud, 중국 본토에서는 Qianwen AI Platform으로 불려요. QwenCloud 및 Qianwen AI Platform 페이지에서
qwencloud/과qwen_ai_platform/접두사를 확인하세요.dashscope/접두사는 별칭으로 완전히 지원되며 계속 동작해요.
출처: 문서
본문
API 키
# env variable
os.environ['DASHSCOPE_API_KEY']
API Base
# Set via environment variable
os.environ['DASHSCOPE_API_BASE'] = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
# Or pass directly in the completion call
response = completion(
model="dashscope/qwen-turbo",
messages=[{"role": "user", "content": "hello"}],
api_base="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
)
지역에 따라 API base URL을 선택적으로 지정할 수 있어요:
| 지역 | API Base |
|---|---|
| 국제 (International) | https://dashscope-intl.aliyuncs.com/compatible-mode/v1 |
| 중국/베이징 (China/Beijing) | https://dashscope.aliyuncs.com/compatible-mode/v1 |
샘플 사용법 (Sample Usage)
from litellm import completion
import os
os.environ['DASHSCOPE_API_KEY'] = ""
response = completion(
model="dashscope/qwen-turbo",
messages=[
{"role": "user", "content": "hello from litellm"}
],
)
print(response)
샘플 사용법 - 스트리밍 (Streaming)
from litellm import completion
import os
os.environ['DASHSCOPE_API_KEY'] = ""
response = completion(
model="dashscope/qwen-turbo",
messages=[
{"role": "user", "content": "hello from litellm"}
],
stream=True,
)
for chunk in response:
print(chunk)