Overview
This topic describes how to build an official documentation assistant based on retrieval-augmented generation (RAG). The assistant can help you better understand Alibaba Cloud Model Studio and resolve questions about the Model Studio.
Procedure
Step 1: Upload data
On the Data Management page, click the "+" icon to the right of Category Management to create a category. On the Create Category page, enter a category name and click OK. You can also use the default category instead of creating one.
Click Import Data You can upload local files or import data from Object Storage Service (OSS). In this example, a local file is uploaded. You can drag the file to the upload section or click the section and select the path of the file.
Asynchronous parsing of the file takes a period of time. After the parsing is completed, the status of the file becomes Imported.
Step 2: Create a knowledge index
In the left-side navigation pane, click Data Application > Knowledge Index. On the Knowledge Base Index page, click Create Knowledge Base. On the page that appears, enter a name for the knowledge base and keep the default configurations for other parameters.
Recommended: Recommended configuration, best practices in terms of performance, cost, and retrieval latency.
Custom: Fully open offline knowledge base configuration, freely configured according to retrieval needs, providing different levels of performance and latency.
Custom configuration mode allows you to select different embedding models and rank models, and choose whether to enable the Multi-round Conversation Rewriting feature. Then, click Next Step.
Select the files that you want to import and click Next Step.
If you choose Custom Splitting, you can set the Estimated Segment Length and Segment Overlap Length parameters.
Then, click Import. After the parsing is completed, the status of the file becomes Parsed.
Click View in the Actions column to view the details of the segments.
Step 3: Create an application
Choose Application Center > My Applications and click Create Application. For more information, see Build an application.
After the application is created, you can test the application and view logs.
Step 4: Use API
You can call your application by using API in multiple programming languages. For more information, see SDK reference.
Single-round conversation
from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
def call_agent_app():
response = Application.call(app_id='***',#YOUR-APPID
prompt='What capabilities does Alibaba Cloud Model Studio offer? ',
api_key='****', #Replace **** with your API key.
)
if response.status_code != HTTPStatus.OK:
print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
else:
print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))
if __name__ == '__main__':
call_agent_app()
Sample response:
request_id=22954c05-66ac-94fd-b1f7-9a6ef161190d
output={"text": "Alibaba Cloud Model Studio offers the following core capabilities:\n\n1. ** Model Optimization and Fine-tuning **: The platform supports model optimization and fine-tuning functions, enabling users to customize existing large models or conduct tailored training based on specific needs. This includes leveraging mixed training to integrate users' proprietary data with the foundational data of general-purpose large models, thereby enhancing the model's performance in specific domains while preserving its generalization capabilities. \n\n2. **Prompt Engineering**: It provides prompt templates and optimization tools to assist users in designing and refining prompts, ensuring that large models can execute specific tasks more accurately, such as converting natural language instructions into programming variable names. \n\n3. **Intelligent Q&A**: It is suitable for applications like smart customer service and encyclopedic knowledge bases. Models from the Qwen series (e.g., Qwen-Max, Turbo, Plus) are recommended to deliver rapid and precise responses to user queries. \n\n4. **Document Retrieval**: Although specific details are not elaborated, document retrieval is mentioned as one of the application scenarios, indicating the platform's support for information search and document management functionalities. \n\n5. **Model Training**: Users can train their own large models, encompassing the entire process from preparing training data to model training and evaluation. It supports self-service uploading of data, selection of model versions, and hybrid training operations. \n\n6. **API-KEY Management**: It facilitates the creation and management of API keys, allowing developers to securely invoke large model services for text generation, QA interactions, and more. \n\n7. **Application Integration and Deployment**: Through pre-configured plug-ins and streamlined integration methods, users can swiftly incorporate large models into their business solutions, such as product descriptions and marketing copy in e-commerce scenarios. \n\n8. **Model Evaluation**: The platform is equipped with model performance evaluation features, assisting users in assessing key metrics like accuracy and efficiency, thereby guaranteeing the quality of model applications. \n \nIn summary, Alibaba Cloud Model Studio aims to provide enterprises and developers with a one-stop solution for large model commercialization, covering the full pipeline from model development, tuning, and training to application deployment. ", "finish_reason": "stop", "session_id": "ad487191306d4d7e868d4d50c0d09714", "thoughts": null, "doc_references": null}
usage={"models": [{"model_id": "qwen-max", "input_tokens": 1564, "output_tokens": 404}]}
Multi-round conversation
from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
def call_with_session():
response = Application.call(app_id='***',#YOUR-APPID
prompt='What capabilities does Alibaba Cloud Model Studio offer? ',
api_key='****', #Replace **** with your API key.
)
if response.status_code != HTTPStatus.OK:
print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
return
response = Application.call(app_id='***',#YOUR-APPID
prompt='What commercial models are included in the Qwen series? ',
session_id=response.output.session_id,
api_key='****', #Replace **** with your API key.
)
if response.status_code != HTTPStatus.OK:
print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
else:
print('request_id=%s, output=%s, usage=%s\n' % (response.request_id, response.output, response.usage))
if __name__ == '__main__':
call_with_session()
Sample response:
request_id=4bf9b34b-aa6c-99f7-86c5-1ca5dac24c1d, output={"text": "The Qwen Series encompasses the following commercial models:\n\n1. **qwen-turbo**: A super-large language model within the Qwen Series, capable of handling inputs in various languages including Chinese and English, tailored for diverse text generation and comprehension tasks. \n2. **qwen-plus**: An enhanced version of the Qwen Series' super-large language model, with augmented capabilities compared to the base model, also supporting multi-language inputs. \n3. **qwen-max**: A peta-scale super-large language model within the Qwen Series, boasting more potent language processing capabilities and accommodating multiple languages such as Chinese and English. **qwen-max-longcontext**: A peta-scale super-large language model optimized for long texts and complex contextual processing, also designed for multi-language inputs. \n\n Additionally, there are models tailored for the integration of vision and language tasks:\n\n- **qwen-vl-plus**: An enhanced large-scale visual-language model within the Qwen Series, significantly improving detail recognition and optical character recognition abilities, suitable for image-related tasks with support for high-resolution image inputs. \n- **qwen-vl-max**: A super-large visual-language model within the Qwen Series, further enhancing visual reasoning and command adherence capabilities, adept at managing more intricate and advanced visual tasks. These models span a broad spectrum of applications, from text creation, text processing, programming assistance, translation services, dialogue simulation, to image understanding and processing, fulfilling AI requirements across different industries and domains.", "finish_reason": "stop", "session_id": "37d1303c8b89488393e02c2deff0c68e", "thoughts": null, "doc_references": null}, usage={"models": [{"model_id": "qwen-max", "input_tokens": 1777, "output_tokens": 297}]}
Streaming output
from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
def call_with_stream():
responses = Application.call(app_id='***',#YOUR-APPID
prompt='What capabilities does Alibaba Cloud Model Studio offer? ',
api_key='****', #Replace **** with your API key.
stream=True
)
for response in responses:
if response.status_code != HTTPStatus.OK:
print('request_id=%s, code=%s, message=%s\n' % (
response.request_id, response.status_code, response.message))
else:
print('output=%s, usage=%s\n' % (response.output, response.usage))
if __name__ == '__main__':
call_with_stream()
Sample response:
output={"text": "Alibaba Cloud Model Studio offers a comprehensive suite of capabilities designed to enable enterprise customers and partners to efficiently leverage large model technology. Core competencies include, but are not limited to:\n\n1. **Model Optimization & Fine-Tuning**: The platform enables users to optimize and fine-tune large models for specific application scenarios. This involves hybrid training with proprietary data alongside Qwen large models or other foundational models, enhancing the model's performance in particular domains while preserving its generalization abilities. \n\n2. **Prompt Engineering**: Provides prompt templates and optimization tools to assist users in designing and refining prompts, ensuring large models execute specific tasks more accurately, such as converting natural language instructions into programming tasks or enhancing the interaction quality of Q&A systems. \n\n3. **Application Integration**: Pre-configured applications or prompts for scenarios like intelligent Q&A and document retrieval are available, facilitating the direct integration of models like Qwen into existing business solutions, accelerating the practical application of large models. \n\n4. **Model Evaluation**: Supplies tools to assess model performance, ensuring models tuned or fine-tuned meet expected outcomes, with support for automated or semi-automated evaluation processes. \n\n5. **API Access & Management**: Users can generate API keys to securely invoke large model services, with support for access control and management of APIs, ensuring service security and traceability. \n\n6. **Custom Model Training**: Allows users to upload custom data for training exclusive large models, catering to the personalized needs of specific industries. \n\n7. **Playground & Application Center**: Features a model playground for users to browse, select, and apply pre-trained models, and an application center for creating and deploying large model-based application services. \n\n8. **Resources & Tutorials**: Provides detailed tutorials and guides, covering aspects from uploading training data, training models, evaluating models, to creating custom applications, reducing technical barriers and hastening project implementation. \n \nIn summary, Alibaba Cloud Model Studio is an end-to-end solution encompassing the entire pipeline from model selection, tuning, training, evaluation to application deployment, empowering enterprises to achieve intelligent transformation and enhance operational efficiency. ", "finish_reason": "stop", "session_id": "a8947b8ea6f842e3a8015e6cb9b92f21", "thoughts": null, "doc_references": null}, usage={"models": [{"model_id": "qwen-max", "input_tokens": 1564, "output_tokens": 428}]}