Skip to content

Commit

Permalink
Fix prompt stacking in bedrock converse (#17613)
Browse files Browse the repository at this point in the history
  • Loading branch information
GinkREAL authored Jan 24, 2025
1 parent 612f670 commit 19c177c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,13 @@ def _get_content_and_tool_calls(
def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
# convert Llama Index messages to AWS Bedrock Converse messages
converse_messages, system_prompt = messages_to_converse_messages(messages)
if len(system_prompt) > 0 or self.system_prompt is None:
self.system_prompt = system_prompt
all_kwargs = self._get_all_kwargs(**kwargs)

# invoke LLM in AWS Bedrock Converse with retry
response = converse_with_retry(
client=self._client,
messages=converse_messages,
system_prompt=self.system_prompt,
system_prompt=system_prompt,
max_retries=self.max_retries,
stream=False,
guardrail_identifier=self.guardrail_identifier,
Expand Down Expand Up @@ -349,15 +347,13 @@ def stream_chat(
) -> ChatResponseGen:
# convert Llama Index messages to AWS Bedrock Converse messages
converse_messages, system_prompt = messages_to_converse_messages(messages)
if len(system_prompt) > 0 or self.system_prompt is None:
self.system_prompt = system_prompt
all_kwargs = self._get_all_kwargs(**kwargs)

# invoke LLM in AWS Bedrock Converse with retry
response = converse_with_retry(
client=self._client,
messages=converse_messages,
system_prompt=self.system_prompt,
system_prompt=system_prompt,
max_retries=self.max_retries,
stream=True,
guardrail_identifier=self.guardrail_identifier,
Expand Down Expand Up @@ -431,16 +427,14 @@ async def achat(
) -> ChatResponse:
# convert Llama Index messages to AWS Bedrock Converse messages
converse_messages, system_prompt = messages_to_converse_messages(messages)
if len(system_prompt) > 0 or self.system_prompt is None:
self.system_prompt = system_prompt
all_kwargs = self._get_all_kwargs(**kwargs)

# invoke LLM in AWS Bedrock Converse with retry
response = await converse_with_retry_async(
session=self._asession,
config=self._config,
messages=converse_messages,
system_prompt=self.system_prompt,
system_prompt=system_prompt,
max_retries=self.max_retries,
stream=False,
guardrail_identifier=self.guardrail_identifier,
Expand Down Expand Up @@ -479,16 +473,14 @@ async def astream_chat(
) -> ChatResponseAsyncGen:
# convert Llama Index messages to AWS Bedrock Converse messages
converse_messages, system_prompt = messages_to_converse_messages(messages)
if len(system_prompt) > 0 or self.system_prompt is None:
self.system_prompt = system_prompt
all_kwargs = self._get_all_kwargs(**kwargs)

# invoke LLM in AWS Bedrock Converse with retry
response_gen = await converse_with_retry_async(
session=self._asession,
config=self._config,
messages=converse_messages,
system_prompt=self.system_prompt,
system_prompt=system_prompt,
max_retries=self.max_retries,
stream=True,
guardrail_identifier=self.guardrail_identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-llms-bedrock-converse"
readme = "README.md"
version = "0.4.3"
version = "0.4.4"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down

0 comments on commit 19c177c

Please sign in to comment.