"Baidu AI Cloud Qianfan Platform is a one-stop large model development and service operation platform for enterprise developers. Qianfan not only provides including the model of Wenxin Yiyan (ERNIE-Bot) and the third-party open source models, but also provides various AI development tools and the whole set of development environment, which facilitates customers to use and develop large model applications easily.\n",
"\n",
"Basically, those model are split into the following type:\n",
"\n",
"- Embedding\n",
"- Chat\n",
"- Completion\n",
"\n",
"In this notebook, we will introduce how to use langchain with [Qianfan](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html) mainly in `Embedding` corresponding\n",
" to the package `langchain/embeddings` in langchain:\n",
"\n",
"\n",
"\n",
"## API Initialization\n",
"\n",
"To use the LLM services based on Baidu Qianfan, you have to initialize these parameters:\n",
"\n",
"You could either choose to init the AK,SK in enviroment variables or init params:\n",
" res = await embed.aembed_documents([\"hi\", \"world\"])\n",
" for r in res:\n",
" print(\"\", r[:8])\n",
"await aioEmbedDocs()\n",
"\n",
"\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use different models in Qianfan\n",
"\n",
"In the case you want to deploy your own model based on Ernie Bot or third-party open sources model, you could follow these steps:\n",
"\n",
"- 1. (Optional, if the model are included in the default models, skip it)Deploy your model in Qianfan Console, get your own customized deploy endpoint.\n",
"- 2. Set up the field called `endpoint` in the initlization:"