Skip to content

Commit bfae812

Browse files
authored
Update Openai support to >= v1.0.0 (#211)
Hi, I upgraded the oss-fuzz-gen project’s OpenAI SDK dependency from version 0.27.8 to version >=1.0.0, in line with OpenAI's official recommendations. This move is motivated by the significant enhancements introduced in version 1.0.0, which OpenAI details [here](openai/openai-python#742). Key improvements include: - A complete rewrite of the library for robustness and error resilience. - Introduction of explicit client instantiation, replacing the global default and offering more flexible SDK interaction. After upgrading to v1.16.2 (the latest available), I tested the integration with my API key and confirmed full functionality. This upgrade aligns oss-fuzz-gen with current best practices and ensures compatibility with future developments in AI technologies. Hope it helps.
1 parent 481f921 commit bfae812

File tree

3 files changed

+73
-55
lines changed

3 files changed

+73
-55
lines changed

llm_toolkit/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,18 @@ def generate_code(self,
196196
"""Generates code with OpenAI's API."""
197197
if self.ai_binary:
198198
print(f'OpenAI does not use local AI binary: {self.ai_binary}')
199-
openai.api_key = os.getenv('OPENAI_API_KEY')
199+
client = openai.OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
200200

201201
completion = self.with_retry_on_error(
202-
lambda: openai.ChatCompletion.create(messages=prompt.get(),
203-
model=self.name,
204-
n=self.num_samples,
205-
temperature=self.temperature),
202+
lambda: client.chat.completions.create(messages=prompt.get(),
203+
model=self.name,
204+
n=self.num_samples,
205+
temperature=self.temperature),
206206
openai.OpenAIError)
207207
if log_output:
208208
print(completion)
209209
for index, choice in enumerate(completion.choices): # type: ignore
210-
content = choice.message['content']
210+
content = choice.message.content
211211
self._save_output(index, content, response_dir)
212212

213213

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
google-cloud-aiplatform==1.39.0
22
google-cloud-storage==2.9.0
33
PyYAML==6.0
4-
openai==0.27.8
4+
openai==1.16.2
55
requests==2.31.0
66
#pytype==2023.7.28
77
Flask==2.3.2

requirements.txt

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,56 @@
44
#
55
# pip-compile requirements.in
66
#
7-
aiohttp==3.9.2
8-
# via openai
9-
aiosignal==1.3.1
10-
# via aiohttp
7+
annotated-types==0.6.0
8+
# via pydantic
9+
anyio==4.3.0
10+
# via
11+
# httpx
12+
# openai
1113
astroid==2.15.8
1214
# via pylint
13-
attrs==23.2.0
14-
# via aiohttp
1515
blinker==1.7.0
1616
# via flask
17-
cachetools==5.3.2
17+
cachetools==5.3.3
1818
# via google-auth
19-
certifi==2023.11.17
20-
# via requests
21-
charset-normalizer==2.1.1
19+
certifi==2024.2.2
20+
# via
21+
# httpcore
22+
# httpx
23+
# requests
24+
charset-normalizer==3.3.2
2225
# via requests
2326
click==8.1.7
2427
# via flask
25-
dill==0.3.7
28+
dill==0.3.8
2629
# via pylint
30+
distro==1.9.0
31+
# via openai
2732
flask==2.3.2
2833
# via -r requirements.in
29-
frozenlist==1.4.1
30-
# via
31-
# aiohttp
32-
# aiosignal
33-
google-api-core[grpc]==2.15.0
34+
google-api-core[grpc]==2.18.0
3435
# via
3536
# google-cloud-aiplatform
3637
# google-cloud-bigquery
3738
# google-cloud-core
3839
# google-cloud-resource-manager
3940
# google-cloud-storage
40-
google-auth==2.26.2
41+
google-auth==2.29.0
4142
# via
4243
# google-api-core
44+
# google-cloud-bigquery
4345
# google-cloud-core
46+
# google-cloud-resource-manager
4447
# google-cloud-storage
4548
google-cloud-aiplatform==1.39.0
4649
# via -r requirements.in
47-
google-cloud-bigquery==3.16.0
50+
google-cloud-bigquery==3.20.1
4851
# via google-cloud-aiplatform
4952
google-cloud-core==2.4.1
5053
# via
5154
# google-cloud-bigquery
5255
# google-cloud-storage
53-
google-cloud-resource-manager==1.11.0
56+
google-cloud-resource-manager==1.12.3
5457
# via google-cloud-aiplatform
5558
google-cloud-storage==2.9.0
5659
# via
@@ -62,26 +65,33 @@ google-resumable-media==2.7.0
6265
# via
6366
# google-cloud-bigquery
6467
# google-cloud-storage
65-
googleapis-common-protos[grpc]==1.62.0
68+
googleapis-common-protos[grpc]==1.63.0
6669
# via
6770
# google-api-core
6871
# grpc-google-iam-v1
6972
# grpcio-status
7073
grpc-google-iam-v1==0.13.0
7174
# via google-cloud-resource-manager
72-
grpcio==1.60.0
75+
grpcio==1.62.1
7376
# via
7477
# google-api-core
7578
# googleapis-common-protos
7679
# grpc-google-iam-v1
7780
# grpcio-status
78-
grpcio-status==1.60.0
81+
grpcio-status==1.62.1
7982
# via google-api-core
83+
h11==0.14.0
84+
# via httpcore
85+
httpcore==1.0.5
86+
# via httpx
87+
httpx==0.27.0
88+
# via openai
8089
idna==3.6
8190
# via
91+
# anyio
92+
# httpx
8293
# requests
83-
# yarl
84-
importlib-metadata==7.0.1
94+
importlib-metadata==7.1.0
8595
# via yapf
8696
isort==5.13.2
8797
# via pylint
@@ -91,39 +101,36 @@ jinja2==3.1.3
91101
# via flask
92102
lazy-object-proxy==1.10.0
93103
# via astroid
94-
markupsafe==2.1.3
104+
markupsafe==2.1.5
95105
# via
96106
# jinja2
97107
# werkzeug
98108
mccabe==0.7.0
99109
# via pylint
100-
multidict==6.0.4
101-
# via
102-
# aiohttp
103-
# yarl
104110
nodeenv==1.8.0
105111
# via pyright
106-
numpy==1.26.3
112+
numpy==1.26.4
107113
# via
108114
# pandas
109115
# shapely
110-
openai==0.27.8
116+
openai==1.16.2
111117
# via -r requirements.in
112-
packaging==23.2
118+
packaging==24.0
113119
# via
114120
# google-cloud-aiplatform
115121
# google-cloud-bigquery
116122
pandas==2.1.1
117123
# via -r requirements.in
118-
platformdirs==4.1.0
124+
platformdirs==4.2.0
119125
# via
120126
# pylint
121127
# yapf
122128
proto-plus==1.23.0
123129
# via
130+
# google-api-core
124131
# google-cloud-aiplatform
125132
# google-cloud-resource-manager
126-
protobuf==4.25.2
133+
protobuf==4.25.3
127134
# via
128135
# google-api-core
129136
# google-cloud-aiplatform
@@ -132,21 +139,25 @@ protobuf==4.25.2
132139
# grpc-google-iam-v1
133140
# grpcio-status
134141
# proto-plus
135-
pyasn1==0.5.1
142+
pyasn1==0.6.0
136143
# via
137144
# pyasn1-modules
138145
# rsa
139-
pyasn1-modules==0.3.0
146+
pyasn1-modules==0.4.0
140147
# via google-auth
148+
pydantic==2.6.4
149+
# via openai
150+
pydantic-core==2.16.3
151+
# via pydantic
141152
pylint==2.17.5
142153
# via -r requirements.in
143154
pyright==1.1.345
144155
# via -r requirements.in
145-
python-dateutil==2.8.2
156+
python-dateutil==2.9.0.post0
146157
# via
147158
# google-cloud-bigquery
148159
# pandas
149-
pytz==2023.3.post1
160+
pytz==2024.1
150161
# via pandas
151162
pyyaml==6.0
152163
# via -r requirements.in
@@ -158,35 +169,42 @@ requests==2.31.0
158169
# google-api-core
159170
# google-cloud-bigquery
160171
# google-cloud-storage
161-
# openai
162172
# tiktoken
163173
rsa==4.9
164174
# via google-auth
165-
shapely==2.0.2
175+
shapely==2.0.3
166176
# via google-cloud-aiplatform
167177
six==1.16.0
168178
# via python-dateutil
179+
sniffio==1.3.1
180+
# via
181+
# anyio
182+
# httpx
183+
# openai
169184
tiktoken==0.5.1
170185
# via -r requirements.in
171186
tomli==2.0.1
172187
# via yapf
173-
tomlkit==0.12.3
188+
tomlkit==0.12.4
174189
# via pylint
175-
tqdm==4.66.1
190+
tqdm==4.66.2
176191
# via openai
177-
tzdata==2023.4
192+
typing-extensions==4.11.0
193+
# via
194+
# openai
195+
# pydantic
196+
# pydantic-core
197+
tzdata==2024.1
178198
# via pandas
179-
urllib3==1.26.18
199+
urllib3==2.2.1
180200
# via requests
181-
werkzeug==3.0.1
201+
werkzeug==3.0.2
182202
# via flask
183203
wrapt==1.16.0
184204
# via astroid
185205
yapf==0.40.1
186206
# via -r requirements.in
187-
yarl==1.9.4
188-
# via aiohttp
189-
zipp==3.17.0
207+
zipp==3.18.1
190208
# via importlib-metadata
191209

192210
# The following packages are considered to be unsafe in a requirements file:

0 commit comments

Comments
 (0)