Skip to content

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 requested a review from mattbit May 22, 2024 02:39
@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
@sonarqubecloud
Copy link

@mattbit mattbit merged commit fac1656 into main May 24, 2024
@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.

3 participants