Skip to content

Commit

Permalink
Better documented the 400 error code thrown by OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Nov 12, 2024
1 parent d1b5a92 commit af7d31b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ldp/llms/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ async def call( # noqa: C901, PLR0915
) -> list[LLMResult]:
start_clock = asyncio.get_running_loop().time()

# Deal with tools. OpenAI throws an error if tool list is empty,
# so skip this block if tools in (None, [])
# Deal with tools. Note OpenAI throws a 400 response if tools is empty:
# > Invalid 'tools': empty array. Expected an array with minimum length 1,
# > but got an empty array instead.
# So, circumvent this behavior if tools in (None, [])
if tools:
chat_kwargs["tools"] = ToolsAdapter.dump_python(
tools, exclude_none=True, by_alias=True
Expand Down

0 comments on commit af7d31b

Please sign in to comment.