Skip to content

Commit 4a5d241

Browse files
xinhuitiantianxinhui
authored andcommitted
fix gpt example
1 parent d990ff8 commit 4a5d241

File tree

1 file changed

+65
-64
lines changed

1 file changed

+65
-64
lines changed

examples/chDB_GPT.ipynb

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,28 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 0,
4-
"metadata": {
5-
"colab": {
6-
"provenance": []
7-
},
8-
"kernelspec": {
9-
"name": "python3",
10-
"display_name": "Python 3"
11-
},
12-
"language_info": {
13-
"name": "python"
14-
}
15-
},
162
"cells": [
173
{
184
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "qx9ZBUUkQwvG"
7+
},
198
"source": [
209
"<img src=\"https://github.com/chdb-io/chdb/raw/pybind/docs/_static/snake-chdb.png\" width=320 >\n",
2110
"\n",
2211
"# chdb-GPT\n",
2312
"Generate **chDB** and **ClickHouse** queries using natural language and **OpenAI APIs**"
24-
],
25-
"metadata": {
26-
"id": "qx9ZBUUkQwvG"
27-
}
13+
]
2814
},
2915
{
3016
"cell_type": "code",
31-
"source": [
32-
"#@title Install Requirements { display-mode: \"form\" }\n",
33-
"!pip install openai chdb --quiet"
34-
],
17+
"execution_count": null,
3518
"metadata": {
3619
"id": "Gyo2KvBkMUHI"
3720
},
38-
"execution_count": null,
39-
"outputs": []
21+
"outputs": [],
22+
"source": [
23+
"#@title Install Requirements { display-mode: \"form\" }\n",
24+
"!pip install openai chdb --quiet"
25+
]
4026
},
4127
{
4228
"cell_type": "code",
@@ -58,6 +44,11 @@
5844
},
5945
{
6046
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {
49+
"id": "-GYCp4HzQ9_X"
50+
},
51+
"outputs": [],
6152
"source": [
6253
"#@title Prepare ClickHouse GTP Agent { display-mode: \"form\" }\n",
6354
"class Conversation:\n",
@@ -136,24 +127,24 @@
136127
" \"\"\"\n",
137128
"\n",
138129
" return input_str\n"
139-
],
140-
"metadata": {
141-
"id": "-GYCp4HzQ9_X"
142-
},
143-
"execution_count": null,
144-
"outputs": []
130+
]
145131
},
146132
{
147133
"cell_type": "markdown",
148-
"source": [
149-
"Let's input our query and form a prompt:\n"
150-
],
151134
"metadata": {
152135
"id": "SkSjhVDvUZHa"
153-
}
136+
},
137+
"source": [
138+
"Let's input our query and form a prompt:\n"
139+
]
154140
},
155141
{
156142
"cell_type": "code",
143+
"execution_count": null,
144+
"metadata": {
145+
"id": "wDXDTbooM8mE"
146+
},
147+
"outputs": [],
157148
"source": [
158149
"#@title Prompt using Natural Language { display-mode: \"form\" }\n",
159150
"query = \"show the top 10 towns from url https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet\" #@param {type:\"string\"}\n",
@@ -164,58 +155,68 @@
164155
"\n",
165156
"answer = conversation.answer(prompt)\n",
166157
"print(answer)"
167-
],
168-
"metadata": {
169-
"id": "wDXDTbooM8mE"
170-
},
171-
"execution_count": null,
172-
"outputs": []
158+
]
173159
},
174160
{
175161
"cell_type": "markdown",
176-
"source": [
177-
"Create a new instance of `Conversation` whenever you want to clear the context."
178-
],
179162
"metadata": {
180163
"id": "aM1NvWGOUfOa"
181-
}
164+
},
165+
"source": [
166+
"Create a new instance of `Conversation` whenever you want to clear the context."
167+
]
182168
},
183169
{
184170
"cell_type": "markdown",
185-
"source": [
186-
"We can now extend our query and the API will remember what we did before."
187-
],
188171
"metadata": {
189172
"id": "9k5x7gvUUn5z"
190-
}
173+
},
174+
"source": [
175+
"We can now extend our query and the API will remember what we did before."
176+
]
191177
},
192178
{
193179
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {
182+
"cellView": "form",
183+
"id": "MY06L5jvNMNQ"
184+
},
185+
"outputs": [],
194186
"source": [
195187
"#@title Refine SQL using Natural Language\n",
196188
"refine_query = \"add round(avg(price)) AS price to the query\" #@param {type:\"string\"}\n",
197-
"query = conversation.answer(refine_query)\n",
198-
"print(answer)"
199-
],
200-
"metadata": {
201-
"id": "MY06L5jvNMNQ",
202-
"cellView": "form"
203-
},
204-
"execution_count": null,
205-
"outputs": []
189+
"answer = conversation.answer(refine_query)\n",
190+
"query = answer.replace(\"```sql\",\"\").replace(\"```\",\"\")\n",
191+
"print(query)"
192+
]
206193
},
207194
{
208195
"cell_type": "code",
196+
"execution_count": null,
197+
"metadata": {
198+
"id": "BKeDfL1fQ4XB"
199+
},
200+
"outputs": [],
209201
"source": [
210202
"#@title Execute Query using chDB { display-mode: \"form\" }\n",
211203
"import chdb\n",
212204
"res = chdb.query(query, 'Pretty'); print(res.data())"
213-
],
214-
"metadata": {
215-
"id": "BKeDfL1fQ4XB"
216-
},
217-
"execution_count": null,
218-
"outputs": []
205+
]
219206
}
220-
]
207+
],
208+
"metadata": {
209+
"colab": {
210+
"provenance": []
211+
},
212+
"kernelspec": {
213+
"display_name": "Python 3",
214+
"name": "python3"
215+
},
216+
"language_info": {
217+
"name": "python"
218+
}
219+
},
220+
"nbformat": 4,
221+
"nbformat_minor": 0
221222
}

0 commit comments

Comments
 (0)