File size: 8,604 Bytes
e60c070 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from wenxin_llm import Wenxin_LLM"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import find_dotenv, load_dotenv\n",
"import os\n",
"\n",
"# 读取本地/项目的环境变量。\n",
"\n",
"# find_dotenv()寻找并定位.env文件的路径\n",
"# load_dotenv()读取该.env文件,并将其中的环境变量加载到当前的运行环境中\n",
"# 如果你设置的是全局的环境变量,这行代码则没有任何作用。\n",
"_ = load_dotenv(find_dotenv())\n",
"\n",
"# 获取环境变量 OPENAI_API_KEY\n",
"wenxin_api_key = os.environ[\"wenxin_api_key\"]\n",
"wenxin_secret_key = os.environ[\"wenxin_secret_key\"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"llm = Wenxin_LLM(model = \"ERNIE-Bot-turbo\", api_key=wenxin_api_key, secret_key=wenxin_secret_key)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'您好,我是百度研发的知识增强大语言模型,中文名是文心一言,英文名是ERNIE Bot。我能够与人对话互动,回答问题,协助创作,高效便捷地帮助人们获取信息、知识和灵感。\\n\\n如果您有任何问题,请随时告诉我。'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm(\"你是谁\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from spark_llm import Spark_LLM"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import find_dotenv, load_dotenv\n",
"import os\n",
"\n",
"# 读取本地/项目的环境变量。\n",
"\n",
"# find_dotenv()寻找并定位.env文件的路径\n",
"# load_dotenv()读取该.env文件,并将其中的环境变量加载到当前的运行环境中\n",
"# 如果你设置的是全局的环境变量,这行代码则没有任何作用。\n",
"_ = load_dotenv(find_dotenv())\n",
"#填写控制台中获取的 APPID 信息\n",
"appid = os.environ[\"spark_appid\"]\n",
"#填写控制台中获取的 APISecret 信息\n",
"api_secret = os.environ[\"spark_api_secret\"]\n",
"#填写控制台中获取的 APIKey 信息\n",
"api_key = os.environ[\"spark_api_key\"]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"llm = Spark_LLM(model = \"spark\", appid=appid, api_secret=api_secret, api_key=api_key)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\n\\n我是一个AI语言模型,可以回答你的问题和提供帮助。'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm(\"你是谁\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"from zhipuai_llm import ZhipuAILLM\n",
"\n",
"from dotenv import find_dotenv, load_dotenv\n",
"import os\n",
"\n",
"# 读取本地/项目的环境变量。\n",
"\n",
"# find_dotenv()寻找并定位.env文件的路径\n",
"# load_dotenv()读取该.env文件,并将其中的环境变量加载到当前的运行环境中\n",
"# 如果你设置的是全局的环境变量,这行代码则没有任何作用。\n",
"_ = load_dotenv(find_dotenv())\n",
"\n",
"api_key = os.environ[\"ZHIPUAI_API_KEY\"] #填写控制台中获取的 APIKey 信息"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'我是一个名为 ChatGLM 的人工智能助手,由智谱 AI 公司于2023年训练的语言模型开发而成。我的任务是针对用户的问题和要求提供适当的答复和支持。'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm = ZhipuAILLM(model=\"chatglm_pro\", zhipuai_api_key=api_key, temperature=0.1)\n",
"llm(\"你是谁\") "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"测试原生接口"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from call_llm import get_completion"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import find_dotenv, load_dotenv\n",
"import os\n",
"\n",
"# 读取本地/项目的环境变量。\n",
"\n",
"# find_dotenv()寻找并定位.env文件的路径\n",
"# load_dotenv()读取该.env文件,并将其中的环境变量加载到当前的运行环境中\n",
"# 如果你设置的是全局的环境变量,这行代码则没有任何作用。\n",
"_ = load_dotenv(find_dotenv())\n",
"\n",
"# 获取环境变量 OPENAI_API_KEY\n",
"openai_api_key = os.environ[\"OPENAI_API_KEY\"]\n",
"wenxin_api_key = os.environ[\"wenxin_api_key\"]\n",
"wenxin_secret_key = os.environ[\"wenxin_secret_key\"]\n",
"spark_appid = os.environ[\"spark_appid\"]\n",
"spark_api_secret = os.environ[\"spark_api_secret\"]\n",
"spark_api_key = os.environ[\"spark_api_key\"]\n",
"zhipu_api_key = os.environ[\"ZHIPUAI_API_KEY\"]\n",
"\n",
"# os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:7890'\n",
"# os.environ[\"HTTP_PROXY\"] = 'http://127.0.0.1:7890'"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'我是一个人工智能助手,可以回答你的问题并提供帮助。有什么可以帮到你的吗?'"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_completion(\"你是谁\",model=\"gpt-3.5-turbo\", api_key=openai_api_key)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'您好,我是百度研发的知识增强大语言模型,中文名是文心一言,英文名是ERNIE Bot。我能够与人对话互动,回答问题,协助创作,高效便捷地帮助人们获取信息、知识和灵感。'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_completion(\"你是谁\",model=\"ERNIE-Bot-turbo\", api_key=wenxin_api_key, secret_key=wenxin_secret_key)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\n\\n我是一个AI语言模型,可以回答你的问题和提供帮助。'"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_completion(\"你是谁\",model=\"Spark-1.5\", appid=spark_appid, api_key=spark_api_key, api_secret=spark_api_secret)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'我是一个名为 ChatGLM 的人工智能助手,由智谱 AI 公司于2023年训练的语言模型开发而成。我的任务是针对用户的问题和要求提供适当的答复和支持。'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_completion(\"你是谁\",model=\"chatglm_std\", api_key=zhipu_api_key)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "langchain",
"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.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|