docs[patch]: RAG Cookbook example fix (#13914)

### Description:
Hey 👋🏽  this is a small docs example fix. Hoping it helps future developers  who are working with Langchain.

### Problem:
Take a look at the original example code. You were not able to get the `dialogue_turn[0]` while it was a tuple.

Original code:
```python
def _format_chat_history(chat_history: List[Tuple]) -> str:
    buffer = ""
    for dialogue_turn in chat_history:
        human = "Human: " + dialogue_turn[0]
        ai = "Assistant: " + dialogue_turn[1]
        buffer += "\n" + "\n".join([human, ai])
    return buffer
```
In the original code you were getting this error:
```bash
    human = "Human: " + dialogue_turn[0].content
                        ~~~~~~~~~~~~~^^^
TypeError: 'HumanMessage' object is not subscriptable
```
### Solution:
The fix is to just for loop over the chat history and look to see if its a human or ai message and add it to the buffer.
pull/14001/head
WaseemH 7 months ago committed by GitHub
parent 5eca1bd93f
commit a47f1da884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -234,7 +234,13 @@
"from typing import List, Tuple\n",
"\n",
"\n",
"def _format_chat_history(chat_history: List[Tuple]) -> str:\n",
"def _format_chat_history(chat_history: List[Tuple[str, str]]) -> str:\n",
" # chat history is of format:\n",
" # [\n",
" # (human_message_str, ai_message_str),\n",
" # ...\n",
" # ]\n",
" # see below for an example of how it's invoked\n",
" buffer = \"\"\n",
" for dialogue_turn in chat_history:\n",
" human = \"Human: \" + dialogue_turn[0]\n",

Loading…
Cancel
Save