Skip to content

AWS Sagemaker model #14

@aatish-shinde

Description

@aatish-shinde

Hi

I have a Mistral model deployed on AWS Sagemaker. Is there a way I can use the Sagemaker LLM with MCP client?

I have this class below. I would like to use it with MCP. Is it possible?

def get_streaming_response(self, prompt):
    """
    Sends a structured prompt to the SageMaker LLM endpoint and streams the response.

    :param prompt: The structured prompt formatted as a JSON list.
    :return: The streamed response as a string.
    """
    try:
        # Define inference parameters with streaming enabled
        inference_params = {
            "do_sample": True,
            "temperature": 0.1,
            "top_k": 50,
            "max_new_tokens": 512,
            "repetition_penalty": 1.03,
            "stop": ["</s>", "<|system|>", "<|user|>", "<|assistant|>"],
            "return_full_text": False
        }

        body = json.dumps({"inputs": prompt, "parameters": inference_params, "stream": True})

        # Invoke SageMaker endpoint with response streaming
        response = self.client.invoke_endpoint_with_response_stream(
            EndpointName=self.endpoint_name,
            Body=body,
            ContentType="application/json"
        )

        event_stream = response["Body"]

        return event_stream

    except Exception as e:
        self.logger.error(f"🚨 SageMaker error: {e}")
        return "Error processing request. Please try again."

Thanks
Atish

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions