langchain[minor]: add volcengine endpoint as LLM (#13942)

- **Description:** Volc Engine MaaS serves as an enterprise-grade,
large-model service platform designed for developers. You can visit its
homepage at https://www.volcengine.com/docs/82379/1099455 for details.
This change will facilitate developers to integrate quickly with the
platform.
  - **Issue:** None
  - **Dependencies:** volcengine
  - **Tag maintainer:** @baskaryan 
  - **Twitter handle:** @he1v3tica

---------

Co-authored-by: lvzhong <lvzhong@bytedance.com>
This commit is contained in:
h3l
2023-11-30 05:16:42 +08:00
committed by GitHub
parent 1600ebe6c7
commit dbaeb163aa
10 changed files with 729 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "404758628c7b20f6",
"metadata": {
"collapsed": false
},
"source": [
"# Volc Engine Maas\n",
"\n",
"This notebook provides you with a guide on how to get started with volc engine maas chat models."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2cd2ebd9d023c4d3",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Install the package\n",
"!pip install volcengine"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "51e7f967cb78f5b7",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:43:37.131292Z",
"start_time": "2023-11-27T10:43:37.127250Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"from langchain.chat_models import VolcEngineMaasChat\n",
"from langchain.schema import HumanMessage"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "139667d44689f9e0",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:43:49.911867Z",
"start_time": "2023-11-27T10:43:49.908329Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"chat = VolcEngineMaasChat(volc_engine_maas_ak=\"your ak\", volc_engine_maas_sk=\"your sk\")"
]
},
{
"cell_type": "markdown",
"id": "e84ebc4feedcc739",
"metadata": {
"collapsed": false
},
"source": [
"or you can set access_key and secret_key in your environment variables\n",
"```bash\n",
"export VOLC_ACCESSKEY=YOUR_AK\n",
"export VOLC_SECRETKEY=YOUR_SK\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "35da18414ad17aa0",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:43:53.101852Z",
"start_time": "2023-11-27T10:43:51.741041Z"
},
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": "AIMessage(content='好的,这是一个笑话:\\n\\n为什么鸟儿不会玩电脑游戏\\n\\n因为它们没有翅膀')"
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chat([HumanMessage(content=\"给我讲个笑话\")])"
]
},
{
"cell_type": "markdown",
"id": "a55e5a9ed80ec49e",
"metadata": {
"collapsed": false
},
"source": [
"# volc engine maas chat with stream"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "b4e4049980ac68ef",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:43:55.120405Z",
"start_time": "2023-11-27T10:43:55.114707Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"chat = VolcEngineMaasChat(\n",
" volc_engine_maas_ak=\"your ak\",\n",
" volc_engine_maas_sk=\"your sk\",\n",
" streaming=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "fe709a4ffb5c811d",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:43:58.775294Z",
"start_time": "2023-11-27T10:43:56.799401Z"
},
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": "AIMessage(content='好的,这是一个笑话:\\n\\n三岁的女儿说她会造句了妈妈让她用“年轻”造句女儿说“妈妈减肥一年轻了好几斤”。')"
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chat([HumanMessage(content=\"给我讲个笑话\")])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "404758628c7b20f6",
"metadata": {
"collapsed": false
},
"source": [
"# Volc Engine Maas\n",
"\n",
"This notebook provides you with a guide on how to get started with Volc Engine's MaaS llm models."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "946db204b33c2ef7",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Install the package\n",
"!pip install volcengine"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "51e7f967cb78f5b7",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:40:26.897649Z",
"start_time": "2023-11-27T10:40:26.552589Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"from langchain.llms import VolcEngineMaasLLM\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain.schema.output_parser import StrOutputParser"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "139667d44689f9e0",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:40:27.938517Z",
"start_time": "2023-11-27T10:40:27.861324Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"llm = VolcEngineMaasLLM(volc_engine_maas_ak=\"your ak\", volc_engine_maas_sk=\"your sk\")"
]
},
{
"cell_type": "markdown",
"id": "e84ebc4feedcc739",
"metadata": {
"collapsed": false
},
"source": [
"or you can set access_key and secret_key in your environment variables\n",
"```bash\n",
"export VOLC_ACCESSKEY=YOUR_AK\n",
"export VOLC_SECRETKEY=YOUR_SK\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "35da18414ad17aa0",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-27T10:41:35.528526Z",
"start_time": "2023-11-27T10:41:32.562238Z"
},
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": "'好的,下面是一个笑话:\\n\\n大学暑假我配了隐形眼镜回家给爷爷说我现在配了隐形眼镜。\\n爷爷让我给他看看于是我用小镊子夹了一片给爷爷看。\\n爷爷看完便准备出门边走还边说“真高级啊还真是隐形眼镜”\\n等爷爷出去后我才发现我刚没夹起来'"
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain = PromptTemplate.from_template(\"给我讲个笑话\") | llm | StrOutputParser()\n",
"chain.invoke({})"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}