Skip to content

Commit

Permalink
moved arguments within kwargs, simplified function prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartial committed Dec 6, 2024
1 parent fdc6420 commit 208a0a1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions OpenAI_GPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@


#####
def simpler_gpt_call(apikey, messages, model_engine, max_tokens, temperature, beta_model=False, **kwargs):
# 20241206: Removed temperature and max_tokens from the function call, those are now passed within kwargs
def simpler_gpt_call(apikey, messages, model_engine, **kwargs):
client = OpenAI(api_key=apikey)

# beta models limitation: https://platform.openai.com/docs/guides/reasoning
# o1 will may not provide an answer if the max_completion_tokens is lower than 2000

# with open("msg.json", 'w') as f:
# json.dump(messages, f, indent=4)

if beta_model is True:
kwargs['max_completion_tokens'] = max_tokens
else:
kwargs['max_tokens'] = max_tokens
kwargs['temperature'] = temperature

# Generate a response (20231108: Fixed for new API version)
try:
Expand Down Expand Up @@ -332,8 +327,13 @@ def chatgpt_it(self, model_engine, prompt, max_tokens, temperature, clear_chat,
with open(msg_file, 'w') as f:
json.dump(clean_messages, f, indent=4)

beta_model = self.beta_models[model_engine]
err, response = simpler_gpt_call(self.apikey, clean_messages, model_engine, max_tokens, temperature, beta_model=beta_model, **kwargs)
# Use kwargs to max_tokens and temperature
if self.beta_models[model_engine] is True:
kwargs['max_completion_tokens'] = max_tokens
else:
kwargs['max_tokens'] = max_tokens
kwargs['temperature'] = temperature
err, response = simpler_gpt_call(self.apikey, clean_messages, model_engine, **kwargs)

if cf.isNotBlank(err):
return err, ""
Expand Down

0 comments on commit 208a0a1

Please sign in to comment.