The following code is generic and requirements updating with specific details about the LLM model and its configuration parameters. I also want the openpyxl code for automation of Excel-based inputs to amended to the langchain code. The final product needs to be in langchain format, as shown here:

from transformers import AutoTokenizer
from langchain.schema.messages import AIMessage, ChatGeneration
from langchain.chat_models.base import BaseChatModel, ChatResult
from langchain.llms.ctransformers import CTransformers

class CTransformerChatModel(BaseChatModel):
    def __init__(self, model_name_or_path: str, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
        self.model = CTransformers(model=model_name_or_path)

    def _generate(
        self,
        messages: List[BaseMessage],
        stop: Optional[List[str]] = None,
        run_manager: Optional[CallbackManagerForLLMRun] = None,
        **kwargs: Any,
    ) -> ChatResult:
        # Concatenate all messages
        text = " ".join([message.content for message in messages])
        # Generate a response
        output_str = self.model._call(prompt=text, stop=stop)
        # Create the AI message
        message = AIMessage(content=output_str)
        # Create the chat generation
        generation = ChatGeneration(message=message)
        # Return the chat result
        return ChatResult(generations=[generation])

Please insert those details using the code below and show me the final result:

!pip install ctransformers[cuda]
!pip install --upgrade git+https://github.com/huggingface/transformers

from ctransformers import AutoModelForCausalLM

# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
model = AutoModelForCausalLM.from_pretrained(
    "TheBloke/zephyr-7B-beta-GGUF",
    model_file="zephyr-7b-beta.Q4_K_M.gguf",
    model_type="mistral",
    gpu_layers=50,
    max_new_tokens = 2000,
    context_length = 8000,
    hf=True
)

from transformers import AutoTokenizer, pipeline

# Tokenizer
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-7b-beta")

# Pipeline
generator = pipeline(
    model=model, tokenizer=tokenizer,
    task='text-generation',
    max_new_tokens=2000,
    repetition_penalty=1.1
)

import openpyxl
import time
from google.colab import drive

# Start the timer
start_time = time.time()

# Open the input Excel workbook and get the sheet object
input_wb = openpyxl.load_workbook('Flo-4.xlsx')
input_sheet = input_wb['Sheet1']

# Get the range of cells containing the prompts
prompts = input_sheet['A301':'A674']

# Create a new Excel workbook and worksheet objects
output_wb = openpyxl.Workbook()
output_sheet = output_wb.active

# Define the range of cells where you want to write the responses
output_range = output_sheet['A301':'A674']

# Loop over the range of cells and write the prompt code
for i, prompt in enumerate(prompts):

  # Extract the value from the cell object
  prompt_value = prompt[0].value
  # Generate the response
  response = generator(prompt_value)
  print(response[0]["generated_text"])
  # Write the response to the current cell
  output_range[i][0].value = response[0]["generated_text"]

# Save the output workbook outside the loop
output_wb.save('output.xlsx')

# Mount your Google Drive in the Colab runtime
drive.mount('/content/gdrive')

# Save the output workbook to Google Drive (replace 'My Drive/Colab Notebooks/Flo-4-Output.xlsx' with your desired path and filename)
output_wb.save('/content/gdrive/My Drive/Colab Notebooks/Flo-4-Output.xlsx')

# Stop the timer
end_time = time.time()
elapsed_time = end_time - start_time
print("The code took {:.2f} seconds to complete.".format(elapsed_time))