远兮 commited on
Commit
5c19486
·
1 Parent(s): 8ca23f8

add llms serialization

Browse files
Files changed (3) hide show
  1. llms_openai.py +3 -0
  2. llms_serialization.ipynb +99 -0
  3. txt/llm.json +13 -0
llms_openai.py CHANGED
@@ -2,6 +2,9 @@ from langchain.llms import OpenAI
2
 
3
  llm = OpenAI(model_name="text-davinci-003", n=2, best_of=2)
4
 
 
 
 
5
  # 生成文本, get_num_tokens用于计算输入文本的token。
6
  result = llm("随机一份双色球号码")
7
  print()
 
2
 
3
  llm = OpenAI(model_name="text-davinci-003", n=2, best_of=2)
4
 
5
+ # 保存llm配置
6
+ # llm.save("./txt/llm.json")
7
+
8
  # 生成文本, get_num_tokens用于计算输入文本的token。
9
  result = llm("随机一份双色球号码")
10
  print()
llms_serialization.ipynb ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 31,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from langchain.llms import OpenAI\n",
10
+ "from langchain.llms.loading import load_llm\n",
11
+ "from langchain.agents import load_tools\n",
12
+ "from langchain.agents import initialize_agent\n",
13
+ "from langchain.agents import AgentType"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 32,
19
+ "metadata": {},
20
+ "outputs": [
21
+ {
22
+ "data": {
23
+ "text/plain": [
24
+ "'\\n\\n今天是2020年7月5日(星期日)。'"
25
+ ]
26
+ },
27
+ "execution_count": 32,
28
+ "metadata": {},
29
+ "output_type": "execute_result"
30
+ }
31
+ ],
32
+ "source": [
33
+ "llm = load_llm(\"./txt/llm.json\")\n",
34
+ "llm(\"今天的日期?\")"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 33,
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "name": "stdout",
44
+ "output_type": "stream",
45
+ "text": [
46
+ "\n",
47
+ "\n",
48
+ "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
49
+ "\u001b[32;1m\u001b[1;3m I need to figure out the date today\n",
50
+ "Action: Search\n",
51
+ "Action Input: 今天的日期\u001b[0m\n",
52
+ "Observation: \u001b[36;1m\u001b[1;3m随着Today'sDate365,迅速得到当前日期。 无论你有一台电脑,平板电脑或智能手机,当前日期会立即出现。 今天的日期是:. 周一; 2023 四月17; 2023/04/17 ...\u001b[0m\n",
53
+ "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n",
54
+ "Final Answer: 2023年4月17日\u001b[0m\n",
55
+ "\n",
56
+ "\u001b[1m> Finished chain.\u001b[0m\n"
57
+ ]
58
+ },
59
+ {
60
+ "data": {
61
+ "text/plain": [
62
+ "'2023年4月17日'"
63
+ ]
64
+ },
65
+ "execution_count": 33,
66
+ "metadata": {},
67
+ "output_type": "execute_result"
68
+ }
69
+ ],
70
+ "source": [
71
+ "tools = load_tools([\"serpapi\", \"llm-math\"], llm=llm)\n",
72
+ "agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)\n",
73
+ "agent.run(\"今天的日期?\")"
74
+ ]
75
+ }
76
+ ],
77
+ "metadata": {
78
+ "kernelspec": {
79
+ "display_name": "base",
80
+ "language": "python",
81
+ "name": "python3"
82
+ },
83
+ "language_info": {
84
+ "codemirror_mode": {
85
+ "name": "ipython",
86
+ "version": 3
87
+ },
88
+ "file_extension": ".py",
89
+ "mimetype": "text/x-python",
90
+ "name": "python",
91
+ "nbconvert_exporter": "python",
92
+ "pygments_lexer": "ipython3",
93
+ "version": "3.10.10"
94
+ },
95
+ "orig_nbformat": 4
96
+ },
97
+ "nbformat": 4,
98
+ "nbformat_minor": 2
99
+ }
txt/llm.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "text-davinci-003",
3
+ "temperature": 0.7,
4
+ "max_tokens": 256,
5
+ "top_p": 1,
6
+ "frequency_penalty": 0,
7
+ "presence_penalty": 0,
8
+ "n": 2,
9
+ "best_of": 2,
10
+ "request_timeout": null,
11
+ "logit_bias": {},
12
+ "_type": "openai"
13
+ }