Skip to content
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

Fix prompt stacking in bedrock converse #17613

Merged
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
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
Loading