- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
fix: Bedrock provider returning None due to inheritance order #3633
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
          
     Open
      
      
            skamenan7
  wants to merge
  1
  commit into
  llamastack:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
skamenan7:bug/bedrock-provider-inference-failures-issue-3621
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +15
        
        
          −12
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -87,9 +87,9 @@ def _to_inference_profile_id(model_id: str, region: str = None) -> str: | |
|  | ||
| class BedrockInferenceAdapter( | ||
| ModelRegistryHelper, | ||
| Inference, | ||
| OpenAIChatCompletionToLlamaStackMixin, | ||
| OpenAICompletionToLlamaStackMixin, | ||
| Inference, | ||
| ): | ||
| def __init__(self, config: BedrockConfig) -> None: | ||
| ModelRegistryHelper.__init__(self, model_entries=MODEL_ENTRIES) | ||
|  | @@ -155,7 +155,7 @@ async def chat_completion( | |
| async def _nonstream_chat_completion(self, request: ChatCompletionRequest) -> ChatCompletionResponse: | ||
| params = await self._get_params_for_chat_completion(request) | ||
| res = self.client.invoke_model(**params) | ||
| chunk = next(res["body"]) | ||
| chunk = res["body"].read() | ||
| result = json.loads(chunk.decode("utf-8")) | ||
|  | ||
| choice = OpenAICompatCompletionChoice( | ||
|  | @@ -172,14 +172,16 @@ async def _stream_chat_completion(self, request: ChatCompletionRequest) -> Async | |
| event_stream = res["body"] | ||
|  | ||
| async def _generate_and_convert_to_openai_compat(): | ||
| for chunk in event_stream: | ||
| chunk = chunk["chunk"]["bytes"] | ||
| result = json.loads(chunk.decode("utf-8")) | ||
| choice = OpenAICompatCompletionChoice( | ||
| finish_reason=result["stop_reason"], | ||
| text=result["generation"], | ||
| ) | ||
| yield OpenAICompatCompletionResponse(choices=[choice]) | ||
| for event in event_stream: | ||
| if "chunk" in event: | ||
| chunk_data = event["chunk"]["bytes"] | ||
| result = json.loads(chunk_data.decode("utf-8")) | ||
| if "generation" in result: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that  | ||
| choice = OpenAICompatCompletionChoice( | ||
| finish_reason=result.get("stop_reason"), | ||
| text=result["generation"], | ||
| ) | ||
| yield OpenAICompatCompletionResponse(choices=[choice]) | ||
|  | ||
| stream = _generate_and_convert_to_openai_compat() | ||
| async for chunk in process_chat_completion_stream_response(stream, request): | ||
|  | @@ -193,8 +195,9 @@ async def _get_params_for_chat_completion(self, request: ChatCompletionRequest) | |
|  | ||
| if sampling_params.max_tokens: | ||
| options["max_gen_len"] = sampling_params.max_tokens | ||
| if sampling_params.repetition_penalty > 0: | ||
| options["repetition_penalty"] = sampling_params.repetition_penalty | ||
| # Note: repetition_penalty is not supported by AWS Bedrock Llama models | ||
| # if sampling_params.repetition_penalty > 0: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why comment out? just leave a note and remove the commented code? | ||
| # options["repetition_penalty"] = sampling_params.repetition_penalty | ||
|  | ||
| prompt = await chat_completion_request_to_prompt(request, self.get_llama_model(request.model)) | ||
|  | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.