Skip to content

Commit 4d520c0

Browse files
authored
Merge pull request #28 from WhatTheFuzz/feature/new-models
Feature/new models
2 parents 32c5769 + 112df17 commit 4d520c0

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
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)

src/settings.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def register_api_key_settings(self) -> bool:
4242

4343
def register_model_settings(self) -> bool:
4444
'''Register the OpenAI model settings in Binary Ninja.
45-
Defaults to text-davinci-003.
45+
Defaults to gpt-3.5-turbo.
4646
'''
4747
# Set the attributes of the settings. Refer to:
4848
# https://api.binary.ninja/binaryninja.settings-module.html
@@ -52,22 +52,30 @@ def register_model_settings(self) -> bool:
5252
'description': 'The OpenAI model used to generate the response.',
5353
# https://beta.openai.com/docs/models
5454
'enum': [
55+
'gpt-4',
56+
'gpt-4-32k',
57+
'gpt-3.5-turbo',
5558
'text-davinci-003',
59+
'text-davinci-002',
5660
'text-curie-001',
5761
'text-babbage-001',
5862
'text-babbage-002',
5963
'code-davinci-002',
6064
'code-cushman-001'
6165
],
6266
'enumDescriptions': [
63-
'Most capable GPT-3 model. Can do any task the other models can do, often with higher quality, longer output and better instruction-following. Also supports inserting completions within text.',
67+
'More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration.',
68+
'Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with our latest model iteration.',
69+
'Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our latest model iteration.',
70+
'Can do any language task with better quality, longer output, and consistent instruction-following than the curie, babbage, or ada models.',
71+
'Similar capabilities to text-davinci-003 but trained with supervised fine-tuning instead of reinforcement learning'
6472
'Very capable, but faster and lower cost than Davinci.',
6573
'Capable of straightforward tasks, very fast, and lower cost.',
6674
'Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.',
6775
'Most capable Codex model. Particularly good at translating natural language to code. In addition to completing code, also supports inserting completions within code.',
6876
'Almost as capable as Davinci Codex, but slightly faster. This speed advantage may make it preferable for real-time applications.'
6977
],
70-
'default': 'text-davinci-003'
78+
'default': 'gpt-3.5-turbo'
7179
}
7280
return self.register_setting('openai.model', json.dumps(properties))
7381

@@ -81,11 +89,11 @@ def register_max_tokens(self) -> bool:
8189
properties = {
8290
'title': 'OpenAI Max Completion Tokens',
8391
'type': 'number',
84-
'description': 'The maximum number of tokens used for completion. Tokens do not necessarily align with word or instruction count. Typically, each token is four characters. If your function is very large, you may need to decrease this value, as the number of tokens in your prompt counts against the total number of tokens supported by the model. Not all models support the same number of maximum tokens; most support 2,048 tokens. For larger functions, check out text-davinci-003 and code-davinci-002 which support 4,000 and 8,000 respectively.',
92+
'description': 'The maximum number of tokens used for completion. Tokens do not necessarily align with word or instruction count. Typically, each token is four characters. If your function is very large, you may need to decrease this value, as the number of tokens in your prompt counts against the total number of tokens supported by the model. Not all models support the same number of maximum tokens; most support 2,048 tokens. For larger functions, check out text-davinci-003 and code-davinci-002 which support 4,000 and 8,000 respectively. For the maximum amount of tokens, check out gpt-4-32k which supports up to 32,768 tokens. This may be costly, however.',
8593
'default': 1_024,
8694
'minValue': 1,
87-
'maxValue': 8_000,
88-
'message': "Min: 1, Max: 8,000"
95+
'maxValue': 32_768,
96+
'message': "Min: 1, Max: 32,768"
8997
}
9098
return self.register_setting('openai.max_tokens',
9199
json.dumps(properties))

0 commit comments

Comments
 (0)