|
1 | 1 | { |
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 | | - }, |
16 | 2 | "cells": [ |
17 | 3 | { |
18 | 4 | "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "id": "qx9ZBUUkQwvG" |
| 7 | + }, |
19 | 8 | "source": [ |
20 | 9 | "<img src=\"https://github.com/chdb-io/chdb/raw/pybind/docs/_static/snake-chdb.png\" width=320 >\n", |
21 | 10 | "\n", |
22 | 11 | "# chdb-GPT\n", |
23 | 12 | "Generate **chDB** and **ClickHouse** queries using natural language and **OpenAI APIs**" |
24 | | - ], |
25 | | - "metadata": { |
26 | | - "id": "qx9ZBUUkQwvG" |
27 | | - } |
| 13 | + ] |
28 | 14 | }, |
29 | 15 | { |
30 | 16 | "cell_type": "code", |
31 | | - "source": [ |
32 | | - "#@title Install Requirements { display-mode: \"form\" }\n", |
33 | | - "!pip install openai chdb --quiet" |
34 | | - ], |
| 17 | + "execution_count": null, |
35 | 18 | "metadata": { |
36 | 19 | "id": "Gyo2KvBkMUHI" |
37 | 20 | }, |
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 | + ] |
40 | 26 | }, |
41 | 27 | { |
42 | 28 | "cell_type": "code", |
|
58 | 44 | }, |
59 | 45 | { |
60 | 46 | "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "metadata": { |
| 49 | + "id": "-GYCp4HzQ9_X" |
| 50 | + }, |
| 51 | + "outputs": [], |
61 | 52 | "source": [ |
62 | 53 | "#@title Prepare ClickHouse GTP Agent { display-mode: \"form\" }\n", |
63 | 54 | "class Conversation:\n", |
|
136 | 127 | " \"\"\"\n", |
137 | 128 | "\n", |
138 | 129 | " return input_str\n" |
139 | | - ], |
140 | | - "metadata": { |
141 | | - "id": "-GYCp4HzQ9_X" |
142 | | - }, |
143 | | - "execution_count": null, |
144 | | - "outputs": [] |
| 130 | + ] |
145 | 131 | }, |
146 | 132 | { |
147 | 133 | "cell_type": "markdown", |
148 | | - "source": [ |
149 | | - "Let's input our query and form a prompt:\n" |
150 | | - ], |
151 | 134 | "metadata": { |
152 | 135 | "id": "SkSjhVDvUZHa" |
153 | | - } |
| 136 | + }, |
| 137 | + "source": [ |
| 138 | + "Let's input our query and form a prompt:\n" |
| 139 | + ] |
154 | 140 | }, |
155 | 141 | { |
156 | 142 | "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "metadata": { |
| 145 | + "id": "wDXDTbooM8mE" |
| 146 | + }, |
| 147 | + "outputs": [], |
157 | 148 | "source": [ |
158 | 149 | "#@title Prompt using Natural Language { display-mode: \"form\" }\n", |
159 | 150 | "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 | 155 | "\n", |
165 | 156 | "answer = conversation.answer(prompt)\n", |
166 | 157 | "print(answer)" |
167 | | - ], |
168 | | - "metadata": { |
169 | | - "id": "wDXDTbooM8mE" |
170 | | - }, |
171 | | - "execution_count": null, |
172 | | - "outputs": [] |
| 158 | + ] |
173 | 159 | }, |
174 | 160 | { |
175 | 161 | "cell_type": "markdown", |
176 | | - "source": [ |
177 | | - "Create a new instance of `Conversation` whenever you want to clear the context." |
178 | | - ], |
179 | 162 | "metadata": { |
180 | 163 | "id": "aM1NvWGOUfOa" |
181 | | - } |
| 164 | + }, |
| 165 | + "source": [ |
| 166 | + "Create a new instance of `Conversation` whenever you want to clear the context." |
| 167 | + ] |
182 | 168 | }, |
183 | 169 | { |
184 | 170 | "cell_type": "markdown", |
185 | | - "source": [ |
186 | | - "We can now extend our query and the API will remember what we did before." |
187 | | - ], |
188 | 171 | "metadata": { |
189 | 172 | "id": "9k5x7gvUUn5z" |
190 | | - } |
| 173 | + }, |
| 174 | + "source": [ |
| 175 | + "We can now extend our query and the API will remember what we did before." |
| 176 | + ] |
191 | 177 | }, |
192 | 178 | { |
193 | 179 | "cell_type": "code", |
| 180 | + "execution_count": null, |
| 181 | + "metadata": { |
| 182 | + "cellView": "form", |
| 183 | + "id": "MY06L5jvNMNQ" |
| 184 | + }, |
| 185 | + "outputs": [], |
194 | 186 | "source": [ |
195 | 187 | "#@title Refine SQL using Natural Language\n", |
196 | 188 | "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 | + ] |
206 | 193 | }, |
207 | 194 | { |
208 | 195 | "cell_type": "code", |
| 196 | + "execution_count": null, |
| 197 | + "metadata": { |
| 198 | + "id": "BKeDfL1fQ4XB" |
| 199 | + }, |
| 200 | + "outputs": [], |
209 | 201 | "source": [ |
210 | 202 | "#@title Execute Query using chDB { display-mode: \"form\" }\n", |
211 | 203 | "import chdb\n", |
212 | 204 | "res = chdb.query(query, 'Pretty'); print(res.data())" |
213 | | - ], |
214 | | - "metadata": { |
215 | | - "id": "BKeDfL1fQ4XB" |
216 | | - }, |
217 | | - "execution_count": null, |
218 | | - "outputs": [] |
| 205 | + ] |
219 | 206 | } |
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 |
221 | 222 | } |
0 commit comments