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.Basically, those model are split into the following type:
Embedding
Chat
Completion
In this notebook, we will introduce how to use langchain with Qianfan mainly in Embedding corresponding
to the package langchain/embeddings in langchain:
To use the LLM services based on Baidu Qianfan, you have to initialize these parameters:You could either choose to init the AK,SK in environment variables or init params:
Copy
Ask AI
export QIANFAN_AK=XXXexport QIANFAN_SK=XXX
Copy
Ask AI
"""For basic init and call"""import osfrom langchain_community.embeddings import QianfanEmbeddingsEndpointos.environ["QIANFAN_AK"] = "your_ak"os.environ["QIANFAN_SK"] = "your_sk"embed = QianfanEmbeddingsEndpoint( # qianfan_ak='xxx', # qianfan_sk='xxx')res = embed.embed_documents(["hi", "world"])async def aioEmbed(): res = await embed.aembed_query("qianfan") print(res[:8])await aioEmbed()async def aioEmbedDocs(): res = await embed.aembed_documents(["hi", "world"]) for r in res: print("", r[:8])await aioEmbedDocs()