When saving an LLM to JSON, and retrieving it back the content_formatter is null
Labels: name: auto:bug, name: area: models

### System Info

langchain =  0.0.329


I have the following code, and it works fine as long as the JSON file does not exist.

```
    try:
        content_formatter = LlamaContentFormatter()
        formatter_template = "Write a {word_count} word essay about {topic}."

        prompt = PromptTemplate(
            input_variables=["word_count", "topic"], template=formatter_template
        )
        try:            
            loaded_llm = load_llm("azureml.json")
            chain = LLMChain(llm=loaded_llm, prompt=prompt)
        except FileNotFoundError:
            load_dotenv()
            llm = AzureMLOnlineEndpoint(
                endpoint_api_key=os.getenv("AZUREML_ENDPOINT_API_KEY"),
                endpoint_url=os.getenv("AZUREML_ENDPOINT_URL"),
                deployment_name=os.getenv("AZUREML_DEPLOYMENT_NAME"),
                model_kwargs={"temperature": 0.8, "max_tokens": 300},
                content_formatter=content_formatter
            )
            llm.save("azureml.json")
            chain = LLMChain(llm=llm, prompt=prompt)

        response = chain.run({"word_count": 100, "topic": "how to make friends"})
        return response
    except requests.exceptions.RequestException as e:
        # Handle any requests-related errors (e.g., network issues, invalid URL)
        raise ValueError(f"Error with the API request: {e}")

    except json.JSONDecodeError as e:
        # Handle any JSON decoding errors (e.g., invalid JSON format)
        raise ValueError(f"Error decoding API response as JSON: {e}")
    except Exception as e:
        # Handle any other errors
        raise ValueError(f"Error: {e}")
```


However when the llm is saved as azureml.json, the second time it loads the LLM from the file, however the second time I get this error:

ValueError: Error: 'NoneType' object has no attribute 'format_request_payload'

If I check the json file it looks like this:

```
{
    "deployment_name": "llama-2-7b-12-luis",
    "model_kwargs": {
        "temperature": 0.8,
        "max_tokens": 300
    },
    "_type": "azureml_endpoint"
}
```


I an guessing that the .save is not serializing the content formatter.



### Who can help?

@hwchase17
@agola11

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. Deploy Llama2 7B text generation as an azure managed endpoint.
2. Create a new project
3.  Add .env file with these settings:
AZUREML_ENDPOINT_API_KEY=""
AZUREML_ENDPOINT_URL="https://<xxxx>.westeurope.inference.ml.azure.com/score"
AZUREML_DEPLOYMENT_NAME= "<xxxx>"

4. Add following code```


class LlamaContentFormatter(ContentFormatterBase):
    """Content formatter for LLaMa"""

    def format_request_payload(self, prompt: str, model_kwargs: Dict) -> bytes:
        """Formats the request according the the chosen api"""
        prompt = ContentFormatterBase.escape_special_characters(prompt)
        request_payload = json.dumps(
            {
                "input_data": {
                    "input_string": [f'"{prompt}"'],
                    "parameters": model_kwargs,
                }
            }
        )
        return str.encode(request_payload)

    def format_response_payload(self, output: bytes) -> str:
        """Formats response"""
        return json.loads(output)[0]["0"]


def askdocuments(
        question):

    try:
        content_formatter = LlamaContentFormatter()
        formatter_template = "Write a {word_count} word essay about {topic}."

        prompt = PromptTemplate(
            input_variables=["word_count", "topic"], template=formatter_template
        )
        try:            
            loaded_llm = load_llm("azureml.json")
            chain = LLMChain(llm=loaded_llm, prompt=prompt)
        except FileNotFoundError:
            load_dotenv()
            llm = AzureMLOnlineEndpoint(
                endpoint_api_key=os.getenv("AZUREML_ENDPOINT_API_KEY"),
                endpoint_url=os.getenv("AZUREML_ENDPOINT_URL"),
                deployment_name=os.getenv("AZUREML_DEPLOYMENT_NAME"),
                model_kwargs={"temperature": 0.8, "max_tokens": 300},
                content_formatter=content_formatter
            )
            llm.save("azureml.json")
            chain = LLMChain(llm=llm, prompt=prompt)

        response = chain.run({"word_count": 100, "topic": "how to make friends"})
        return response
    except requests.exceptions.RequestException as e:
        # Handle any requests-related errors (e.g., network issues, invalid URL)
        raise ValueError(f"Error with the API request: {e}")

    except json.JSONDecodeError as e:
        # Handle any JSON decoding errors (e.g., invalid JSON format)
        raise ValueError(f"Error decoding API response as JSON: {e}")
    except Exception as e:
        # Handle any other errors
        raise ValueError(f"Error: {e}")


def main():
    add_company_logo_and_welcome_text()

    st.markdown('#')

    # Define a custom CSS class for the tooltip-like container
    st.markdown(
        """
        <style>
        .tooltip-container {
            position: relative;
            display: inline-block;
            cursor: pointer;
        }

        .tooltip-content {
            visibility: hidden;
            position: absolute;
            background-color: #f9f9f9;
            color: black;
            padding: 5px;
            border-radius: 3px;
            z-index: 1;
            top: -40px;
            left: 100%;
            width: 200px;
            text-align: left;
            white-space: normal;
        }

        .tooltip-container:hover .tooltip-content {
            visibility: visible;
        }
        </style>
        """,
        unsafe_allow_html=True
    )

    # Create a radio button for user selection
    selected_option = st.radio("Select an option:", ("langchain", "standard httprequest"))


    # Store LLM generated responses
    if "messages" not in st.session_state.keys():
        st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]

        # Display chat messages
    for message in st.session_state.messages:
        with st.chat_message(message["role"]):
            st.write(message["content"])

    # User-provided prompt
    if prompt := st.chat_input():
        st.session_state.messages.append({"role": "user", "content": prompt})
        with st.chat_message("user"):
            st.write(prompt)

    # Generate a new response if last message is not from assistant
    if st.session_state.messages[-1]["role"] != "assistant":
        with st.chat_message("assistant"):
            with st.spinner("Thinking..."):
                if selected_option == "langchain":
                    response = askdocuments(question=prompt)
                    st.write(response)
                elif selected_option == "standard httprequest":
                    response = askdocuments2(question=prompt)

                    st.write(response)

        message = {"role": "assistant", "content": response}
        st.session_state.messages.append(message)


if __name__ == "__main__":
    main()

```


### Expected behavior

no exceptions.