raise ValueError(
                    f"Error raised by inference API: {parsed_response['error']}"
                )
            # The inference API has changed a couple of times, so we add some handling
            # to be robust to multiple response formats.
            if isinstance(parsed_response, dict):
                if "data" in parsed_response:
                    output_item = parsed_response["data"]
                elif "output" in parsed_response:
                    output_item = parsed_response["output"]
                else:
                    raise ValueError(
                        f"No key data or output in response: {parsed_response}"
                    )
                if isinstance(output_item, list):
                    text = output_item[0]
                else:
                    text = output_item
            elif isinstance(parsed_response, list):
                first_item = parsed_response[0]
                if isinstance(first_item, str):
                    text = first_item
                elif isinstance(first_item, dict):
                    if "output" in parsed_response:
                        text = first_item["output"]
                    else:
                        raise ValueError(
                            f"No key data or output in response: {parsed_response}"
                        )
                else:
                    raise ValueError(f"Unexpected response format: {parsed_response}")
            else:
                raise ValueError(f"Unexpected response type: {parsed_response}")
            text = text[len(prompt) :]
        except requests.exceptions.JSONDecodeError as e:
            raise ValueError(
                f"Error raised by inference API: {e}.\nResponse: {response.text}"
            )
        # TODO: replace when MosaicML supports custom stop tokens natively
        if stop is not None:
            text = enforce_stop_tokens(text, stop)
        return text
By Harrison Chase
    
      © Copyright 2023, Harrison Chase.
rtdocs_stable/api.python.langchain.com/en/stable/_modules/langchain/llms/mosaicml.html