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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed system prompt extraction inside of the bedrock client #1937

Merged
merged 3 commits into from
May 24, 2024

Conversation

kevinmessiaen
Copy link
Member

Description

Currently, system prompt are extracted by taking the first message (if it is from user and second message is also from user). Furthermore, system role are being changed to user, but only after trying to extract the system prompt creating inconsistencies.

This is not clear and create bug when using giskard.rag.generate_testset (system followed by user is translated to two user messages which is forbidden by the bedrock client):

2024-05-14 09:16:03,949 pid:43435 MainThread giskard.rag  ERROR    An error occurred (ValidationException) when calling the InvokeModel operation: messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row
Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/giskard/rag/question_generators/base.py", line 57, in generate_questions
    yield self.generate_single_question(knowledge_base, *args, **kwargs)
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/giskard/rag/question_generators/simple_questions.py", line 96, in generate_single_question
    generated_qa = self._llm_complete(messages=messages)
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/giskard/rag/question_generators/base.py", line 42, in _llm_complete
    out = self._llm_client.complete(
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/giskard/llm/client/bedrock.py", line 72, in complete
    response = self._client.invoke_model(body=body, modelId=self.model, accept=accept, contentType=contentType)
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/botocore/client.py", line 565, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/botocore/client.py", line 1021, in _make_api_call
    raise error_class(parsed_response, operation_name)

Solution

Remove the previous logic and extract system_prompt by using the system role. This is cleaner and way easier to understand.

Related Issue

Type of Change

  • 馃摎 Examples / docs / tutorials / dependencies update
  • 馃敡 Bug fix (non-breaking change which fixes an issue)
  • 馃 Improvement (non-breaking change which improves an existing feature)
  • 馃殌 New feature (non-breaking change which adds functionality)
  • 馃挜 Breaking change (fix or feature that would cause existing functionality to change)
  • 馃攼 Security fix

@kevinmessiaen kevinmessiaen marked this pull request as draft May 22, 2024 02:40
@kevinmessiaen kevinmessiaen changed the title Fixed system prompt extracting of bedrock clients Fixed system prompt extracting inside of the bedrock client May 22, 2024
@kevinmessiaen kevinmessiaen changed the title Fixed system prompt extracting inside of the bedrock client Fixed system prompt extraction inside of the bedrock client May 22, 2024
@kevinmessiaen kevinmessiaen marked this pull request as ready for review May 23, 2024 10:59
Copy link

sonarcloud bot commented May 23, 2024

@mattbit mattbit merged commit fac1656 into main May 24, 2024
16 checks passed
@mattbit mattbit deleted the fix/bedrock_client branch May 24, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants