sevdeawesome commited on
Commit
6e26bd0
·
1 Parent(s): 9bb3d46

update to new openai

Browse files
Files changed (3) hide show
  1. Untitled.ipynb +0 -187
  2. app.py +9 -9
  3. app_2.py +7 -8
Untitled.ipynb DELETED
@@ -1,187 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "id": "ac22dd5d-c6b5-4c7a-a7de-67c4c3c5f04b",
7
- "metadata": {},
8
- "outputs": [
9
- {
10
- "name": "stdout",
11
- "output_type": "stream",
12
- "text": [
13
- "Running on local URL: http://127.0.0.1:7861\n",
14
- "\n",
15
- "To create a public link, set `share=True` in `launch()`.\n"
16
- ]
17
- },
18
- {
19
- "data": {
20
- "text/html": [
21
- "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
- ],
23
- "text/plain": [
24
- "<IPython.core.display.HTML object>"
25
- ]
26
- },
27
- "metadata": {},
28
- "output_type": "display_data"
29
- },
30
- {
31
- "data": {
32
- "text/plain": []
33
- },
34
- "execution_count": 1,
35
- "metadata": {},
36
- "output_type": "execute_result"
37
- }
38
- ],
39
- "source": [
40
- "import gradio as gr\n",
41
- "\n",
42
- "gr.themes.builder(server_port=7861)"
43
- ]
44
- },
45
- {
46
- "cell_type": "code",
47
- "execution_count": null,
48
- "id": "b4c3c6c4-f9f9-477c-af90-9e078e6b3de1",
49
- "metadata": {},
50
- "outputs": [],
51
- "source": []
52
- },
53
- {
54
- "cell_type": "code",
55
- "execution_count": null,
56
- "id": "d7ea55b9-91d8-486a-9f51-2c927ca98331",
57
- "metadata": {},
58
- "outputs": [],
59
- "source": []
60
- },
61
- {
62
- "cell_type": "code",
63
- "execution_count": null,
64
- "id": "d4283b3a-07db-4b9e-a45a-383e4523a1de",
65
- "metadata": {},
66
- "outputs": [],
67
- "source": []
68
- },
69
- {
70
- "cell_type": "code",
71
- "execution_count": 4,
72
- "id": "c9abfe47-b72e-4205-9dc6-ba63a775adf5",
73
- "metadata": {},
74
- "outputs": [
75
- {
76
- "data": {
77
- "text/plain": [
78
- "\u001b[0;31mInit signature:\u001b[0m\n",
79
- "\u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthemes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mColor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
80
- "\u001b[0;34m\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
81
- "\u001b[0;34m\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
82
- "\u001b[0;34m\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
83
- "\u001b[0;34m\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
84
- "\u001b[0;34m\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
85
- "\u001b[0;34m\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
86
- "\u001b[0;34m\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
87
- "\u001b[0;34m\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
88
- "\u001b[0;34m\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
89
- "\u001b[0;34m\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
90
- "\u001b[0;34m\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
91
- "\u001b[0;34m\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str | None'\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
92
- "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
93
- "\u001b[0;31mDocstring:\u001b[0m <no docstring>\n",
94
- "\u001b[0;31mSource:\u001b[0m \n",
95
- "\u001b[0;32mclass\u001b[0m \u001b[0mColor\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
96
- "\u001b[0;34m\u001b[0m \u001b[0mall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n",
97
- "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
98
- "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
99
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
100
- "\u001b[0;34m\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
101
- "\u001b[0;34m\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
102
- "\u001b[0;34m\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
103
- "\u001b[0;34m\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
104
- "\u001b[0;34m\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
105
- "\u001b[0;34m\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
106
- "\u001b[0;34m\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
107
- "\u001b[0;34m\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
108
- "\u001b[0;34m\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
109
- "\u001b[0;34m\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
110
- "\u001b[0;34m\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
111
- "\u001b[0;34m\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
112
- "\u001b[0;34m\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
113
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc50\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m\u001b[0m\n",
114
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc100\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m\u001b[0m\n",
115
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc200\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m\u001b[0m\n",
116
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc300\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m\u001b[0m\n",
117
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc400\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m\u001b[0m\n",
118
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc500\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m\u001b[0m\n",
119
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc600\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m\u001b[0m\n",
120
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc700\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m\u001b[0m\n",
121
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc800\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m\u001b[0m\n",
122
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc900\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m\u001b[0m\n",
123
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc950\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m\u001b[0m\n",
124
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\n",
125
- "\u001b[0;34m\u001b[0m \u001b[0mColor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
126
- "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
127
- "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mexpand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
128
- "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\u001b[0m\n",
129
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc50\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
130
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
131
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc200\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
132
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc300\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
133
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc400\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
134
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc500\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
135
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc600\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
136
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc700\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
137
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc800\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
138
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc900\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
139
- "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc950\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
140
- "\u001b[0;34m\u001b[0m \u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
141
- "\u001b[0;31mFile:\u001b[0m ~/anaconda3/lib/python3.10/site-packages/gradio/themes/utils/colors.py\n",
142
- "\u001b[0;31mType:\u001b[0m type\n",
143
- "\u001b[0;31mSubclasses:\u001b[0m "
144
- ]
145
- },
146
- "metadata": {},
147
- "output_type": "display_data"
148
- }
149
- ],
150
- "source": [
151
- "??gr.themes.monochrome\n",
152
- "??gr.themes.Color"
153
- ]
154
- },
155
- {
156
- "cell_type": "code",
157
- "execution_count": null,
158
- "id": "c6411099-03cd-4bfa-88a7-e0fda5cd6366",
159
- "metadata": {},
160
- "outputs": [],
161
- "source": [
162
- "z"
163
- ]
164
- }
165
- ],
166
- "metadata": {
167
- "kernelspec": {
168
- "display_name": "Python 3 (ipykernel)",
169
- "language": "python",
170
- "name": "python3"
171
- },
172
- "language_info": {
173
- "codemirror_mode": {
174
- "name": "ipython",
175
- "version": 3
176
- },
177
- "file_extension": ".py",
178
- "mimetype": "text/x-python",
179
- "name": "python",
180
- "nbconvert_exporter": "python",
181
- "pygments_lexer": "ipython3",
182
- "version": "3.10.11"
183
- }
184
- },
185
- "nbformat": 4,
186
- "nbformat_minor": 5
187
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -12,11 +12,14 @@ from pathlib import Path
12
  import tiktoken
13
  from getpass import getpass
14
 
15
- import openai
 
 
16
  from langchain.text_splitter import MarkdownHeaderTextSplitter
17
  import numpy as np
18
 
19
- from langchain.embeddings import OpenAIEmbeddings
 
20
  # from langchain.vectorstores import Chroma
21
  from typing import Iterable
22
  from gradio.themes.base import Base
@@ -30,7 +33,6 @@ if os.getenv("OPENAI_API_KEY") is None:
30
  if any(['VSCODE' in x for x in os.environ.keys()]):
31
  print('Please enter password in the VS Code prompt at the top of your VS Code window!')
32
  os.environ["OPENAI_API_KEY"] = getpass("Paste your OpenAI key from: https://platform.openai.com/account/api-keys\n")
33
- openai.api_key = os.getenv("OPENAI_API_KEY", "")
34
 
35
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
36
  print("OpenAI API key configured")
@@ -95,12 +97,10 @@ def get_gpt_response(user_prompt, system_prompt=default_config.system_prompt, mo
95
  {"role": "system", "content": system_prompt},
96
  {"role": "user", "content": user_prompt},
97
  ]
98
- response = openai.ChatCompletion.create(
99
- model=model,
100
- messages=messages,
101
- n=n,
102
- max_tokens=max_tokens
103
- )
104
 
105
 
106
  for choice in response.choices:
 
12
  import tiktoken
13
  from getpass import getpass
14
 
15
+ from openai import OpenAI
16
+
17
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY", ""))
18
  from langchain.text_splitter import MarkdownHeaderTextSplitter
19
  import numpy as np
20
 
21
+ # from langchain.embeddings import OpenAIEmbeddings
22
+ from langchain_openai import OpenAIEmbeddings
23
  # from langchain.vectorstores import Chroma
24
  from typing import Iterable
25
  from gradio.themes.base import Base
 
33
  if any(['VSCODE' in x for x in os.environ.keys()]):
34
  print('Please enter password in the VS Code prompt at the top of your VS Code window!')
35
  os.environ["OPENAI_API_KEY"] = getpass("Paste your OpenAI key from: https://platform.openai.com/account/api-keys\n")
 
36
 
37
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
38
  print("OpenAI API key configured")
 
97
  {"role": "system", "content": system_prompt},
98
  {"role": "user", "content": user_prompt},
99
  ]
100
+ response = client.chat.completions.create(model=model,
101
+ messages=messages,
102
+ n=n,
103
+ max_tokens=max_tokens)
 
 
104
 
105
 
106
  for choice in response.choices:
app_2.py CHANGED
@@ -12,7 +12,9 @@ from pathlib import Path
12
  import tiktoken
13
  from getpass import getpass
14
 
15
- import openai
 
 
16
  from langchain.text_splitter import MarkdownHeaderTextSplitter
17
  import numpy as np
18
 
@@ -30,7 +32,6 @@ if os.getenv("OPENAI_API_KEY") is None:
30
  if any(['VSCODE' in x for x in os.environ.keys()]):
31
  print('Please enter password in the VS Code prompt at the top of your VS Code window!')
32
  os.environ["OPENAI_API_KEY"] = getpass("Paste your OpenAI key from: https://platform.openai.com/account/api-keys\n")
33
- openai.api_key = os.getenv("OPENAI_API_KEY", "")
34
 
35
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
36
  print("OpenAI API key configured")
@@ -95,12 +96,10 @@ def get_gpt_response(user_prompt, system_prompt=default_config.system_prompt, mo
95
  {"role": "system", "content": system_prompt},
96
  {"role": "user", "content": user_prompt},
97
  ]
98
- response = openai.ChatCompletion.create(
99
- model=model,
100
- messages=messages,
101
- n=n,
102
- max_tokens=max_tokens
103
- )
104
 
105
 
106
  for choice in response.choices:
 
12
  import tiktoken
13
  from getpass import getpass
14
 
15
+ from openai import OpenAI
16
+
17
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY", ""))
18
  from langchain.text_splitter import MarkdownHeaderTextSplitter
19
  import numpy as np
20
 
 
32
  if any(['VSCODE' in x for x in os.environ.keys()]):
33
  print('Please enter password in the VS Code prompt at the top of your VS Code window!')
34
  os.environ["OPENAI_API_KEY"] = getpass("Paste your OpenAI key from: https://platform.openai.com/account/api-keys\n")
 
35
 
36
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
37
  print("OpenAI API key configured")
 
96
  {"role": "system", "content": system_prompt},
97
  {"role": "user", "content": user_prompt},
98
  ]
99
+ response = client.chat.completions.create(model=model,
100
+ messages=messages,
101
+ n=n,
102
+ max_tokens=max_tokens)
 
 
103
 
104
 
105
  for choice in response.choices: