SmartLLMChain errors with Bedrock Anthropic models and n_ideas>1
Labels: name: auto:bug, name: area: models

### System Info

langchain version v0.0.305

Python 3.11

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

### Reproduction

```python
claudev2 = BedrockChat(
    client=bedrock_inference,
    model_id="anthropic.claude-v2",
)

from langchain.prompts import PromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain_experimental.smart_llm import SmartLLMChain

prompt = PromptTemplate.from_template(hard_question)

chain = SmartLLMChain(
    llm=claudev2,
    prompt=prompt,
    n_ideas=2,
)

response = chain.run({} )

print(response)
```

Results in error:
```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb) Cell 10 line 1
      [5](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=4) prompt = PromptTemplate.from_template(hard_question)
      [7](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=6) chain = SmartLLMChain(
      [8](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=7)     ideation_llm=claudev2,
      [9](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=8)     critique_llm=claudeinstant,
   (...)
     [15](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=14)     #verbose=True,
     [16](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=15) )
---> [18](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=17) response = chain.run({} )
     [20](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=19) print(response)

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:507](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:507), in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    505     if len(args) != 1:
    506         raise ValueError("`run` supports only one positional argument.")
--> 507     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    508         _output_key
    509     ]
    511 if kwargs and not args:
    512     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    513         _output_key
    514     ]

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:312](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:312), in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)
--> 312     raise e
    313 run_manager.on_chain_end(outputs)
    314 final_outputs: Dict[str, Any] = self.prep_outputs(
    315     inputs, outputs, return_only_outputs
    316 )

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:306](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chains/base.py:306), in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    299 run_manager = callback_manager.on_chain_start(
    300     dumpd(self),
    301     inputs,
    302     name=run_name,
    303 )
    304 try:
    305     outputs = (
--> 306         self._call(inputs, run_manager=run_manager)
    307         if new_arg_supported
    308         else self._call(inputs)
    309     )
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain_experimental/smart_llm/base.py:166](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain_experimental/smart_llm/base.py:166), in SmartLLMChain._call(self, input_list, run_manager)
    164 ideas = self._ideate(stop, run_manager)
    165 self.history.ideas = ideas
--> 166 critique = self._critique(stop, run_manager)
    167 self.history.critique = critique
    168 resolution = self._resolve(stop, run_manager)

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain_experimental/smart_llm/base.py:293](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain_experimental/smart_llm/base.py:293), in SmartLLMChain._critique(self, stop, run_manager)
    290 callbacks = run_manager.handlers if run_manager else None
    291 if llm:
    292     critique = self._get_text_from_llm_result(
--> 293         llm.generate_prompt([prompt], stop, callbacks), step="critique"
    294     )
    295     _colored_text = get_colored_text(critique, "yellow")
    296     _text = "Critique:\n" + _colored_text

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:475](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:475), in BaseChatModel.generate_prompt(self, prompts, stop, callbacks, **kwargs)
    467 def generate_prompt(
    468     self,
    469     prompts: List[PromptValue],
   (...)
    472     **kwargs: Any,
    473 ) -> LLMResult:
    474     prompt_messages = [p.to_messages() for p in prompts]
--> 475     return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:365](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:365), in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)
    363         if run_managers:
    364             run_managers[i].on_llm_error(e)
--> 365         raise e
    366 flattened_outputs = [
    367     LLMResult(generations=[res.generations], llm_output=res.llm_output)
    368     for res in results
    369 ]
    370 llm_output = self._combine_llm_outputs([res.llm_output for res in results])

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:355](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:355), in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)
    352 for i, m in enumerate(messages):
    353     try:
    354         results.append(
--> 355             self._generate_with_cache(
    356                 m,
    357                 stop=stop,
    358                 run_manager=run_managers[i] if run_managers else None,
    359                 **kwargs,
    360             )
    361         )
    362     except BaseException as e:
    363         if run_managers:

File [~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:507](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/~/mambaforge/envs/bedrock/lib/python3.11/site-packages/langchain/chat_models/base.py:507), in BaseChatModel._generate_with_cache(self, messages, stop, run_manager, **kwargs)
    503     raise ValueError(
    504         "Asked to cache, but no cache found at `langchain.cache`."
    505     )
    506 if new_arg_supported:
--> 507     return self._generate(
    508         messages, stop=stop, run_manager=run_manager, **kwargs
    509     )
    510 else:
    511     return self._generate(messages, stop=stop, **kwargs)

[/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb) Cell 10 line 3
    [366](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=365)     if stop:
    [367](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=366)         params["stop_sequences"] = stop
--> [369](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=368)     completion = self._prepare_input_and_invoke(
    [370](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=369)         prompt=prompt, stop=stop, run_manager=run_manager, **params
    [371](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=370)     )
    [373](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=372) message = AIMessage(content=completion)
    [374](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=373) return ChatResult(generations=[ChatGeneration(message=message)])

[/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb) Cell 10 line 2
    [223](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=222) provider = self._get_provider()
    [224](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=223) params = {**_model_kwargs, **kwargs}
--> [225](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=224) input_body = LLMInputOutputAdapterv2.prepare_input(provider, prompt, params)
    [226](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=225) body = json.dumps(input_body)
    [227](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=226) accept = "application/json"

[/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb) Cell 10 line 7
     [73](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=72) input_body = {**model_kwargs}
     [74](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=73) if provider == "anthropic":
---> [75](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=74)     input_body["prompt"] = _human_assistant_format_v2(prompt)
     [76](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=75) elif provider == "ai21":
     [77](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=76)     input_body["prompt"] = prompt

[/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb) Cell 10 line 4
     [47](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=46)             count += 1
     [48](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=47)         else:
---> [49](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=48)             raise ValueError(ALTERNATION_ERROR)
     [51](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=50) if count % 2 == 1:  # Only saw Human, no Assistant
     [52](vscode-notebook-cell:/Users/austinmw/Desktop/bedrocktesting/bedrock_test.ipynb#X14sZmlsZQ%3D%3D?line=51)     input_text = input_text + ASSISTANT_PROMPT  # SILENT CORRECTION

ValueError: Error: Prompt must alternate between '

Human:' and '

Assistant:'.
```

### Expected behavior

No error