Skip to content

Commit 032cce8

Browse files
authored
fix compatibility issue with newer models
based on https://platform.openai.com/docs/guides/gpt/chat-completions-vs-completions
1 parent cd25822 commit 032cce8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/query.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,25 @@ def run(self) -> None:
2222

2323
log_debug(f'Sending query: {self.query_string}')
2424

25-
response = openai.Completion.create(
26-
model=self.model,
27-
prompt=self.query_string,
28-
max_tokens=self.max_token_count,
29-
)
30-
# Get the response text.
31-
result: str = response.choices[0].text
25+
if self.model in ["gpt-3.5-turbo","gpt-4","gpt-4-32k"]:
26+
response = openai.ChatCompletion.create(
27+
model=self.model,
28+
messages=[{"role":"user","content":self.query_string}],
29+
max_tokens=self.max_token_count,
30+
)
31+
# Get the response text.
32+
result: str = response.choices[0].message.content
33+
else:
34+
response = openai.Completion.create(
35+
model=self.model,
36+
prompt=self.query_string,
37+
max_tokens=self.max_token_count,
38+
)
39+
# Get the response text.
40+
result: str = response.choices[0].text
3241
# If there is a callback, do something with it.
3342
if self.callback:
3443
self.callback(result)
3544
# Otherwise, assume we just want to log it.
3645
else:
37-
log_info(result)
46+
log_info(result)

0 commit comments

Comments
 (0)