Introduction to BCE Qianfan SDK
The BCE Qianfan SDK is a toolkit designed to facilitate seamless integration and utilization of AI model capabilities on the Qianfan platform. This SDK empowers users to efficiently manage and leverage large AI models for various applications, providing a comprehensive suite of tools and functionalities.
Core Capabilities
The Qianfan SDK offers three primary capabilities, each tailored to meet different aspects of AI model operations:
-
Large Model Inference: The SDK provides interfaces for the inference of the Yiyan (ERNIE) series models, as well as other open-source large models. It supports operations such as dialogues, text completion, and embedding processes, enabling versatile applications in language processing.
-
Large Model Training: It facilitates an end-to-end training process for large models on the platform, which includes handling training data, fine-tuning or pre-training tasks, and model hosting services. This capability is crucial for users looking to customize or develop their AI models from scratch or enhance existing models.
-
General and Extended Features: Qianfan SDK encompasses general AI development tools like prompt, debugging, and client functionalities. Additionally, it offers extended capabilities tailored to integrate seamlessly with Qianfan's specific features, such as middleware frameworks.
Installation
The Qianfan SDK is available for Python and can be easily installed from PyPI. To set it up, ensure you have Python version 3.7 or higher and use the following pip command:
pip install 'qianfan[dataset_base]'
After installation, users can quickly start using the SDK by importing it into their Python code:
import qianfan
For a detailed guide on installation and configuration, please refer to the documentation.
Multi-language Support
The Qianfan SDK is not limited to Python; it also has versions for other programming languages including Go, Java, and JavaScript. Detailed instructions for each language can be found through their respective documentation links:
Quick Start
To use the Qianfan SDK, users must obtain an Access Key and Secret Key from the Baidu Cloud Console - Security Authentication page. Once these credentials are acquired, the SDK can be configured and used:
import os
import qianfan
os.environ["QIANFAN_ACCESS_KEY"] = "your_access_key"
os.environ["QIANFAN_SECRET_KEY"] = "your_secret_key"
chat = qianfan.ChatCompletion()
response = chat.do(messages=[{"role": "user", "content": "Hello, Qianfan"}])
print(response["result"])
Apart from setting environment variables, users can also configure authentication through DotEnv files or directly within code. More details on configuration can be found in the configuration section of the documentation.
Feature Overview
To assist users in quickly understanding and utilizing the SDK, several cookbooks are provided, offering insights into integrating SDK functionalities with third-party components.
Large Model Inference
The SDK supports various predictive capabilities of large models, including:
- Chat Dialogue: Engage in automated conversations.
- Completion: Generate text continuations.
- Embedding: Convert text into vector representations.
- Plugins and Extensions: Leverage and enhance the model's features.
- Text2Image and Image2Text: Transform text to images and vice versa.
- Reranker: Reorder items based on specified criteria.
Here is an example of using the SDK for chat dialogue, which also supports asynchronous, streaming, and batch inference:
import os
import qianfan
os.environ["QIANFAN_ACCESS_KEY"] = "your_access_key"
os.environ["QIANFAN_SECRET_KEY"] = "your_secret_key"
chat_completion = qianfan.ChatCompletion(model="ERNIE-3.5-8K")
response = chat_completion.do(
messages=[{"role": "user", "content": "Hello, Qianfan"}],
top_p=0.8,
temperature=0.9,
penalty_score=1.0,
)
print(response["result"])
Conclusion
The BCE Qianfan SDK is a powerful tool for AI developers, providing robust support for handling large models, tailored training, and streamlined inference processes. Its extensive support for multiple languages and comprehensive features makes it a vital resource for implementing AI applications on the Qianfan platform.