mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
refactor: standardize string quotes and improve model name handling
This commit is contained in:
parent
33f981d8f1
commit
d8c14c04e3
1 changed files with 9 additions and 5 deletions
|
@ -60,20 +60,21 @@ def ensure_alternating_roles(messages):
|
||||||
prev_role = None
|
prev_role = None
|
||||||
|
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
current_role = msg.get('role') # Get 'role', None if missing
|
current_role = msg.get("role") # Get 'role', None if missing
|
||||||
|
|
||||||
# If the current role is the same as the previous, insert an empty message of the opposite role
|
# If the current role is the same as the previous, insert an empty message of the opposite role
|
||||||
if current_role == prev_role:
|
if current_role == prev_role:
|
||||||
if current_role == 'user':
|
if current_role == "user":
|
||||||
fixed_messages.append({'role': 'assistant', 'content': ''})
|
fixed_messages.append({"role": "assistant", "content": ""})
|
||||||
else:
|
else:
|
||||||
fixed_messages.append({'role': 'user', 'content': ''})
|
fixed_messages.append({"role": "user", "content": ""})
|
||||||
|
|
||||||
fixed_messages.append(msg)
|
fixed_messages.append(msg)
|
||||||
prev_role = current_role
|
prev_role = current_role
|
||||||
|
|
||||||
return fixed_messages
|
return fixed_messages
|
||||||
|
|
||||||
|
|
||||||
def send_completion(
|
def send_completion(
|
||||||
model_name,
|
model_name,
|
||||||
messages,
|
messages,
|
||||||
|
@ -89,7 +90,7 @@ def send_completion(
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
if model_name == 'deepseek/deepseek-reasoner':
|
if "deepseek-reasoner" in model_name:
|
||||||
messages = ensure_alternating_roles(messages)
|
messages = ensure_alternating_roles(messages)
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
@ -127,6 +128,9 @@ def send_completion(
|
||||||
def simple_send_with_retries(model, messages):
|
def simple_send_with_retries(model, messages):
|
||||||
litellm_ex = LiteLLMExceptions()
|
litellm_ex = LiteLLMExceptions()
|
||||||
|
|
||||||
|
if "deepseek-reasoner" in model.name:
|
||||||
|
messages = ensure_alternating_roles(messages)
|
||||||
|
|
||||||
retry_delay = 0.125
|
retry_delay = 0.125
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue