lizhen commited on
Commit
1c6d1f6
·
1 Parent(s): 5879dd0

add load prompts

Browse files
prompt_load.ipynb CHANGED
@@ -2,12 +2,120 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": null,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
  "from langchain.prompts import load_prompt"
10
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
  ],
13
  "metadata": {
@@ -26,7 +134,7 @@
26
  "name": "python",
27
  "nbconvert_exporter": "python",
28
  "pygments_lexer": "ipython3",
29
- "version": "3.10.10"
30
  },
31
  "orig_nbformat": 4
32
  },
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 3,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
  "from langchain.prompts import load_prompt"
10
  ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 4,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stdout",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "Tell me a funny joke about chickens.\n"
22
+ ]
23
+ }
24
+ ],
25
+ "source": [
26
+ "prompt = load_prompt(\"prompts/simple_prompt.yaml\")\n",
27
+ "print(prompt.format(adjective=\"funny\", content=\"chickens\"))"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 5,
33
+ "metadata": {},
34
+ "outputs": [
35
+ {
36
+ "name": "stdout",
37
+ "output_type": "stream",
38
+ "text": [
39
+ "Tell me a funny joke about chickens.\n"
40
+ ]
41
+ }
42
+ ],
43
+ "source": [
44
+ "prompt = load_prompt(\"prompts/simple_prompt.json\")\n",
45
+ "print(prompt.format(adjective=\"funny\", content=\"chickens\"))"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 13,
51
+ "metadata": {},
52
+ "outputs": [
53
+ {
54
+ "name": "stdout",
55
+ "output_type": "stream",
56
+ "text": [
57
+ "Tell me a funny joke about chickens.\n"
58
+ ]
59
+ }
60
+ ],
61
+ "source": [
62
+ "prompt = load_prompt(\"prompts/simple_prompt_with_template_file.json\")\n",
63
+ "print(prompt.format(adjective=\"funny\", content=\"chickens\"))"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 14,
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "name": "stdout",
73
+ "output_type": "stream",
74
+ "text": [
75
+ "Write antonyms for the following words.\n",
76
+ "\n",
77
+ "Input: happy\n",
78
+ "Output: sad\n",
79
+ "\n",
80
+ "Input: tall\n",
81
+ "Output: short\n",
82
+ "\n",
83
+ "Input: funny\n",
84
+ "Output:\n"
85
+ ]
86
+ }
87
+ ],
88
+ "source": [
89
+ "prompt = load_prompt(\"prompts/few_shot_prompt.json\")\n",
90
+ "print(prompt.format(adjective=\"funny\"))"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 20,
96
+ "metadata": {},
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "Write antonyms for the following words.\n",
103
+ "\n",
104
+ "Input: happy\n",
105
+ "Output: sad\n",
106
+ "\n",
107
+ "Input: tall\n",
108
+ "Output: short\n",
109
+ "\n",
110
+ "Input: funny\n",
111
+ "Output:\n"
112
+ ]
113
+ }
114
+ ],
115
+ "source": [
116
+ "prompt = load_prompt(\"prompts/few_shot_prompt_example_prompt.json\")\n",
117
+ "print(prompt.format(adjective=\"funny\"))"
118
+ ]
119
  }
120
  ],
121
  "metadata": {
 
134
  "name": "python",
135
  "nbconvert_exporter": "python",
136
  "pygments_lexer": "ipython3",
137
+ "version": "3.11.3"
138
  },
139
  "orig_nbformat": 4
140
  },
prompts/example_prompt.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_type": "prompt",
3
+ "input_variables": ["input", "output"],
4
+ "template": "Input: {input}\nOutput: {output}"
5
+ }
prompts/examples.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [
2
+ {"input": "happy", "output": "sad"},
3
+ {"input": "tall", "output": "short"}
4
+ ]
prompts/few_shot_prompt.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_type": "few_shot",
3
+ "input_variables": ["adjective"],
4
+ "prefix": "Write antonyms for the following words.",
5
+ "example_prompt": {
6
+ "_type": "prompt",
7
+ "input_variables": ["input", "output"],
8
+ "template": "Input: {input}\nOutput: {output}"
9
+ },
10
+ "examples": "prompts/examples.json",
11
+ "suffix": "Input: {adjective}\nOutput:"
12
+ }
prompts/few_shot_prompt_example_prompt.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_type": "few_shot",
3
+ "input_variables": ["adjective"],
4
+ "prefix": "Write antonyms for the following words.",
5
+ "example_prompt_path": "prompts/example_prompt.json",
6
+ "examples": "prompts/examples.json",
7
+ "suffix": "Input: {adjective}\nOutput:"
8
+ }
prompts/simple_prompt.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_type": "prompt",
3
+ "input_variables": ["adjective", "content"],
4
+ "template": "Tell me a {adjective} joke about {content}."
5
+ }
prompts/simple_prompt.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ _type: prompt
2
+ input_variables:
3
+ ["adjective", "content"]
4
+ template:
5
+ Tell me a {adjective} joke about {content}.
prompts/simple_prompt_with_template_file.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_type": "prompt",
3
+ "input_variables": ["adjective", "content"],
4
+ "template_path": "prompts/simple_template.txt"
5
+ }
prompts/simple_template.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Tell me a {adjective} joke about {content}.