Format Python code with psf/black push

github-actions 2 years ago
parent c9b9d9ce2b
commit 68e4313d71

@ -310,7 +310,10 @@ class Commands(discord.Cog, name="Commands"):
name="prompt", description="The prompt to send to GPT3", required=True
)
@discord.option(
name="model", description="The model to use for the request", required=False, autocomplete=Settings_autocompleter.get_models
name="model",
description="The model to use for the request",
required=False,
autocomplete=Settings_autocompleter.get_models,
)
@discord.option(
name="private", description="Will only be visible to you", required=False

@ -102,7 +102,11 @@ class ImgPromptOptimizer(discord.Cog, name="ImgPromptOptimizer"):
# twice because of the best_of_override=2 parameter. This is to ensure that the model does a lot of analysis, but is
# also relatively cost-effective
response_text = str(response["choices"][0]["text"]) if not self.model.model in Models.CHATGPT_MODELS else response["choices"][0]["message"]["content"]
response_text = (
str(response["choices"][0]["text"])
if not self.model.model in Models.CHATGPT_MODELS
else response["choices"][0]["message"]["content"]
)
# escape any mentions
response_text = discord.utils.escape_mentions(response_text)

@ -65,7 +65,16 @@ class Models:
TURBO_DEV = "gpt-3.5-turbo-0301"
# Model collections
TEXT_MODELS = [DAVINCI, CURIE, BABBAGE, ADA, CODE_DAVINCI, CODE_CUSHMAN, TURBO, TURBO_DEV]
TEXT_MODELS = [
DAVINCI,
CURIE,
BABBAGE,
ADA,
CODE_DAVINCI,
CODE_CUSHMAN,
TURBO,
TURBO_DEV,
]
CHATGPT_MODELS = [TURBO, TURBO_DEV]
EDIT_MODELS = [EDIT, CODE_EDIT]
@ -841,7 +850,6 @@ class Model:
): # The response, and a boolean indicating whether or not the context limit was reached.
# Validate that all the parameters are in a good state before we send the request
# Clean up the user display name
user_displayname_clean = self.cleanse_username(user_displayname)
@ -950,7 +958,9 @@ class Model:
"model": self.model if model is None else model,
"prompt": prompt,
"stop": "" if stop is None else stop,
"temperature": self.temp if temp_override is None else temp_override,
"temperature": self.temp
if temp_override is None
else temp_override,
"top_p": self.top_p if top_p_override is None else top_p_override,
"max_tokens": self.max_tokens - tokens
if max_tokens_override is None
@ -961,13 +971,17 @@ class Model:
"frequency_penalty": self.frequency_penalty
if frequency_penalty_override is None
else frequency_penalty_override,
"best_of": self.best_of if not best_of_override else best_of_override,
"best_of": self.best_of
if not best_of_override
else best_of_override,
}
headers = {
"Authorization": f"Bearer {self.openai_key if not custom_api_key else custom_api_key}"
}
async with session.post(
"https://api.openai.com/v1/completions", json=payload, headers=headers
"https://api.openai.com/v1/completions",
json=payload,
headers=headers,
) as resp:
response = await resp.json()
# print(f"Payload -> {payload}")
@ -976,13 +990,15 @@ class Model:
print(f"Response -> {response}")
return response
else: # ChatGPT Simple completion
else: # ChatGPT Simple completion
async with aiohttp.ClientSession(raise_for_status=False) as session:
payload = {
"model": self.model if not model else model,
"messages": [{"role": "user", "content": prompt}],
"stop": "" if stop is None else stop,
"temperature": self.temp if temp_override is None else temp_override,
"temperature": self.temp
if temp_override is None
else temp_override,
"top_p": self.top_p if top_p_override is None else top_p_override,
"presence_penalty": self.presence_penalty
if presence_penalty_override is None
@ -995,7 +1011,9 @@ class Model:
"Authorization": f"Bearer {self.openai_key if not custom_api_key else custom_api_key}"
}
async with session.post(
"https://api.openai.com/v1/chat/completions", json=payload, headers=headers
"https://api.openai.com/v1/chat/completions",
json=payload,
headers=headers,
) as resp:
response = await resp.json()
# print(f"Payload -> {payload}")

@ -277,12 +277,28 @@ class TextService:
return
# Send the request to the model
is_chatgpt_conversation = ctx.channel.id in converser_cog.conversation_threads and not from_ask_command and not from_edit_command and ((model is not None and (model in Models.CHATGPT_MODELS or model == "chatgpt")) or (model is None and converser_cog.model.model in Models.CHATGPT_MODELS))
is_chatgpt_conversation = (
ctx.channel.id in converser_cog.conversation_threads
and not from_ask_command
and not from_edit_command
and (
(
model is not None
and (model in Models.CHATGPT_MODELS or model == "chatgpt")
)
or (
model is None
and converser_cog.model.model in Models.CHATGPT_MODELS
)
)
)
delegator = model or converser_cog.model.model
is_chatgpt_request = delegator in Models.CHATGPT_MODELS
if is_chatgpt_conversation:
_prompt_with_history = converser_cog.conversation_threads[ctx.channel.id].history
_prompt_with_history = converser_cog.conversation_threads[
ctx.channel.id
].history
response = await converser_cog.model.send_chatgpt_chat_request(
_prompt_with_history,
bot_name=BOT_NAME,
@ -320,10 +336,13 @@ class TextService:
# Clean the request response
response_text = converser_cog.cleanse_response(
str(response["choices"][0]["text"])
) if not is_chatgpt_request and not is_chatgpt_conversation else converser_cog.cleanse_response(str(response["choices"][0]["message"]["content"]))
response_text = (
converser_cog.cleanse_response(str(response["choices"][0]["text"]))
if not is_chatgpt_request and not is_chatgpt_conversation
else converser_cog.cleanse_response(
str(response["choices"][0]["message"]["content"])
)
)
if from_message_context:
response_text = f"{response_text}"

Loading…
Cancel
Save