From 825348185c27a52f245ea9c63cef04d66b60c69b Mon Sep 17 00:00:00 2001 From: ZhangShenao <15201440436@163.com> Date: Fri, 9 Aug 2024 10:38:01 +0800 Subject: [PATCH 1/2] [doc] Add docs for ZhipuAI Embedding --- .../integrations/text_embedding/zhipuai.ipynb | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 docs/docs/integrations/text_embedding/zhipuai.ipynb diff --git a/docs/docs/integrations/text_embedding/zhipuai.ipynb b/docs/docs/integrations/text_embedding/zhipuai.ipynb new file mode 100644 index 0000000000000..c347bad33aa0e --- /dev/null +++ b/docs/docs/integrations/text_embedding/zhipuai.ipynb @@ -0,0 +1,163 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# ZHIPU AI\n", + "\n", + "This notebook shows how to use Langchain with [ZhipuAI](https://open.bigmodel.cn/console/overview) embeddings models.\n", + "\n", + "To use, you should have the `zhipuai` python package installed." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install --upgrade --quiet zhipuai" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After installation,sign in to [ZHIPU AI](https://open.bigmodel.cn/usercenter/apikeys) for the an API Key to access our models.\n", + "\n", + "import os\n", + "\n", + "os.environ[\"ZHIPUAI_API_KEY\"] = \"zhipuai_api_key\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Then, you can use `ZhipuAIEmbeddings` API for text embedding." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_community.embeddings import ZhipuAIEmbeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "embeddings = ZhipuAIEmbeddings(model=\"embedding-3\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "query = \"This is a test document.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "query_embedding = embeddings.embed_query(query)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "doc_embedding = embeddings.embed_documents([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-0.029220581, 0.0034008026, -0.020065308, 0.001244545, -0.007461548]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query_embedding[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-0.029220581, 0.0034008026, -0.020065308, 0.001244545, -0.007461548]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "doc_embedding[0][:5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 41bf1ac30c0cd520db73ce10c7641967fd4f2137 Mon Sep 17 00:00:00 2001 From: ZhangShenao <15201440436@163.com> Date: Fri, 9 Aug 2024 11:41:40 +0800 Subject: [PATCH 2/2] modify doc --- docs/docs/integrations/text_embedding/zhipuai.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/integrations/text_embedding/zhipuai.ipynb b/docs/docs/integrations/text_embedding/zhipuai.ipynb index c347bad33aa0e..b93a8f2f19e19 100644 --- a/docs/docs/integrations/text_embedding/zhipuai.ipynb +++ b/docs/docs/integrations/text_embedding/zhipuai.ipynb @@ -1,7 +1,7 @@ { "cells": [ { - "cell_type": "markdown", + "cell_type": "raw", "metadata": {}, "source": [ "# ZHIPU AI\n",