Skip to content

add llm__achat to all (but one) supported providers in llm__chat #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions edenai_apis/apis/amazon/amazon_llm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,84 @@ def llm__chat(
**kwargs,
)
return response

async def llm__achat(
self,
messages: List = [],
model: Optional[str] = None,
# Optional OpenAI params: see https://platform.openai.com/docs/api-reference/chat/create
timeout: Optional[Union[float, str, httpx.Timeout]] = None,
temperature: Optional[float] = None,
top_p: Optional[float] = None,
n: Optional[int] = None,
stream: Optional[bool] = None,
stream_options: Optional[dict] = None,
stop: Optional[str] = None,
stop_sequences: Optional[any] = None,
max_tokens: Optional[int] = None,
presence_penalty: Optional[float] = None,
frequency_penalty: Optional[float] = None,
logit_bias: Optional[dict] = None,
modalities: Optional[List[Literal["text", "audio", "image"]]] = None,
audio: Optional[Dict] = None,
# openai v1.0+ new params
response_format: Optional[
Union[dict, Type[BaseModel]]
] = None, # Structured outputs
seed: Optional[int] = None,
tools: Optional[List] = None,
tool_choice: Optional[Union[str, dict]] = None,
logprobs: Optional[bool] = None,
top_logprobs: Optional[int] = None,
parallel_tool_calls: Optional[bool] = None,
deployment_id=None,
extra_headers: Optional[dict] = None,
# soon to be deprecated params by OpenAI -> This should be replaced by tools
functions: Optional[List] = None,
function_call: Optional[str] = None,
base_url: Optional[str] = None,
api_version: Optional[str] = None,
api_key: Optional[str] = None,
model_list: Optional[list] = None, # pass in a list of api_base,keys, etc.
drop_invalid_params: bool = True, # If true, all the invalid parameters will be ignored (dropped) before sending to the model
user: str | None = None,
# Optional parameters
**kwargs,
) -> ChatDataClass:
response = await self.llm_client.acompletion(
messages=messages,
model=model,
timeout=timeout,
temperature=temperature,
top_p=top_p,
n=n,
stream=stream,
stream_options=stream_options,
stop=stop,
stop_sequences=stop_sequences,
max_tokens=max_tokens,
presence_penalty=presence_penalty,
frequency_penalty=frequency_penalty,
logit_bias=logit_bias,
response_format=response_format,
seed=seed,
tools=tools,
tool_choice=tool_choice,
logprobs=logprobs,
top_logprobs=top_logprobs,
parallel_tool_calls=parallel_tool_calls,
deployment_id=deployment_id,
extra_headers=extra_headers,
functions=functions,
function_call=function_call,
base_url=base_url,
api_version=api_version,
api_key=api_key,
model_list=model_list,
drop_invalid_params=drop_invalid_params,
user=user,
modalities=modalities,
audio=audio,
**kwargs,
)
return response
Comment on lines +92 to +171
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix mutable default argument and union operator syntax issues.

The async method has the same issues as other implementations:

  1. Mutable default argument: messages: List = [] should be messages: Optional[List] = None
  2. Union operator syntax: user: str | None = None should be user: Optional[str] = None

Apply this diff to fix the issues:

     async def llm__achat(
         self,
-        messages: List = [],
+        messages: Optional[List] = None,
         model: Optional[str] = None,
         # Optional OpenAI params: see https://platform.openai.com/docs/api-reference/chat/create
         timeout: Optional[Union[float, str, httpx.Timeout]] = None,
         temperature: Optional[float] = None,
         top_p: Optional[float] = None,
         n: Optional[int] = None,
         stream: Optional[bool] = None,
         stream_options: Optional[dict] = None,
         stop: Optional[str] = None,
         stop_sequences: Optional[any] = None,
         max_tokens: Optional[int] = None,
         presence_penalty: Optional[float] = None,
         frequency_penalty: Optional[float] = None,
         logit_bias: Optional[dict] = None,
         modalities: Optional[List[Literal["text", "audio", "image"]]] = None,
         audio: Optional[Dict] = None,
         # openai v1.0+ new params
         response_format: Optional[
             Union[dict, Type[BaseModel]]
         ] = None,  # Structured outputs
         seed: Optional[int] = None,
         tools: Optional[List] = None,
         tool_choice: Optional[Union[str, dict]] = None,
         logprobs: Optional[bool] = None,
         top_logprobs: Optional[int] = None,
         parallel_tool_calls: Optional[bool] = None,
         deployment_id=None,
         extra_headers: Optional[dict] = None,
         # soon to be deprecated params by OpenAI -> This should be replaced by tools
         functions: Optional[List] = None,
         function_call: Optional[str] = None,
         base_url: Optional[str] = None,
         api_version: Optional[str] = None,
         api_key: Optional[str] = None,
         model_list: Optional[list] = None,  # pass in a list of api_base,keys, etc.
         drop_invalid_params: bool = True,  # If true, all the invalid parameters will be ignored (dropped) before sending to the model
-        user: str | None = None,
+        user: Optional[str] = None,
         # Optional parameters
         **kwargs,
     ) -> ChatDataClass:
+        if messages is None:
+            messages = []
         response = await self.llm_client.acompletion(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async def llm__achat(
self,
messages: List = [],
model: Optional[str] = None,
# Optional OpenAI params: see https://platform.openai.com/docs/api-reference/chat/create
timeout: Optional[Union[float, str, httpx.Timeout]] = None,
temperature: Optional[float] = None,
top_p: Optional[float] = None,
n: Optional[int] = None,
stream: Optional[bool] = None,
stream_options: Optional[dict] = None,
stop: Optional[str] = None,
stop_sequences: Optional[any] = None,
max_tokens: Optional[int] = None,
presence_penalty: Optional[float] = None,
frequency_penalty: Optional[float] = None,
logit_bias: Optional[dict] = None,
modalities: Optional[List[Literal["text", "audio", "image"]]] = None,
audio: Optional[Dict] = None,
# openai v1.0+ new params
response_format: Optional[
Union[dict, Type[BaseModel]]
] = None, # Structured outputs
seed: Optional[int] = None,
tools: Optional[List] = None,
tool_choice: Optional[Union[str, dict]] = None,
logprobs: Optional[bool] = None,
top_logprobs: Optional[int] = None,
parallel_tool_calls: Optional[bool] = None,
deployment_id=None,
extra_headers: Optional[dict] = None,
# soon to be deprecated params by OpenAI -> This should be replaced by tools
functions: Optional[List] = None,
function_call: Optional[str] = None,
base_url: Optional[str] = None,
api_version: Optional[str] = None,
api_key: Optional[str] = None,
model_list: Optional[list] = None, # pass in a list of api_base,keys, etc.
drop_invalid_params: bool = True, # If true, all the invalid parameters will be ignored (dropped) before sending to the model
user: str | None = None,
# Optional parameters
**kwargs,
) -> ChatDataClass:
response = await self.llm_client.acompletion(
messages=messages,
model=model,
timeout=timeout,
temperature=temperature,
top_p=top_p,
n=n,
stream=stream,
stream_options=stream_options,
stop=stop,
stop_sequences=stop_sequences,
max_tokens=max_tokens,
presence_penalty=presence_penalty,
frequency_penalty=frequency_penalty,
logit_bias=logit_bias,
response_format=response_format,
seed=seed,
tools=tools,
tool_choice=tool_choice,
logprobs=logprobs,
top_logprobs=top_logprobs,
parallel_tool_calls=parallel_tool_calls,
deployment_id=deployment_id,
extra_headers=extra_headers,
functions=functions,
function_call=function_call,
base_url=base_url,
api_version=api_version,
api_key=api_key,
model_list=model_list,
drop_invalid_params=drop_invalid_params,
user=user,
modalities=modalities,
audio=audio,
**kwargs,
)
return response
async def llm__achat(
self,
- messages: List = [],
+ messages: Optional[List] = None,
model: Optional[str] = None,
# Optional OpenAI params: see https://platform.openai.com/docs/api-reference/chat/create
timeout: Optional[Union[float, str, httpx.Timeout]] = None,
temperature: Optional[float] = None,
# … other parameters …
- user: str | None = None,
+ user: Optional[str] = None,
# Optional parameters
**kwargs,
) -> ChatDataClass:
+ if messages is None:
+ messages = []
response = await self.llm_client.acompletion(
messages=messages,
model=model,
timeout=timeout,
temperature=temperature,
# … rest of the call …
)
return response
🧰 Tools
🪛 Ruff (0.12.2)

94-94: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

🪛 Pylint (3.3.7)

[refactor] 92-92: Too many arguments (34/7)

(R0913)


[refactor] 92-92: Too many positional arguments (34/5)

(R0917)


[error] 131-131: unsupported operand type(s) for |

(E1131)

🤖 Prompt for AI Agents
In edenai_apis/apis/amazon/amazon_llm_api.py around lines 92 to 171, fix the
mutable default argument by changing the parameter messages from List = [] to
Optional[List] = None to avoid shared mutable defaults. Also, replace the union
operator syntax in the user parameter from str | None = None to Optional[str] =
None for compatibility and clarity. Update the method signature accordingly and
handle the None default for messages inside the method if necessary.

Loading
Loading