delayedkarma/langchain-issues huggingface dataset:
MarkdownTextSplitter: multiple repeat at position 4 (line 3, column 2)

### System Info

langchain 0.0.188
python 3.8.10


### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [X] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from langchain.docstore.document import Document
from langchain.text_splitter import MarkdownTextSplitter

# of course this is part of a larger markdown document, but this is the minimal string to reproduce
txt = "\n\n***\n\n" 

doc = Document(page_content=txt)
markdown_splitter = MarkdownTextSplitter(chunk_size=1000, chunk_overlap=0)
splitted = markdown_splitter.split_documents([doc])
```

```
Traceback (most recent call last):
  File "t.py", line 9, in <module>
    splitted = markdown_splitter.split_documents([doc])
  File "/home/richard/.local/lib/python3.8/site-packages/langchain/text_splitter.py", line 101, in split_documents
    return self.create_documents(texts, metadatas=metadatas)
  File "/home/richard/.local/lib/python3.8/site-packages/langchain/text_splitter.py", line 88, in create_documents
    for chunk in self.split_text(text):
  File "/home/richard/.local/lib/python3.8/site-packages/langchain/text_splitter.py", line 369, in split_text
    return self._split_text(text, self._separators)
  File "/home/richard/.local/lib/python3.8/site-packages/langchain/text_splitter.py", line 346, in _split_text
    splits = _split_text(text, separator, self._keep_separator)
  File "/home/richard/.local/lib/python3.8/site-packages/langchain/text_splitter.py", line 37, in _split_text
    _splits = re.split(f"({separator})", text)
  File "/usr/lib/python3.8/re.py", line 231, in split
    return _compile(pattern, flags).split(string, maxsplit)
  File "/usr/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 671, in _parse
    raise source.error("multiple repeat",
re.error: multiple repeat at position 4 (line 3, column 2)
```

### Expected behavior

splitted contains splitted markdown and no errors occur
Scores are explained in vectorestore docs
Labels: name: lgtm

# Scores in Vectorestores' Docs Are Explained

Following vectorestores can return scores with similar documents by using `similarity_search_with_score`:
- chroma
- docarray_hnsw
- docarray_in_memory
- faiss
- myscale
- qdrant
- supabase
- vectara
- weaviate

However, in documents, these scores were either not explained at all or explained in a way that could lead to misunderstandings (e.g., FAISS). For instance in FAISS document: if we consider the score returned by the function as a similarity score, we understand that a document returning a higher score is more similar to the source document. However, since the scores returned by the function are distance scores, we should understand that smaller scores correspond to more similar documents.

For the libraries other than Vectara, I wrote the scores they use by investigating from the source libraries. Since I couldn't be certain about the score metric used by Vectara, I didn't make any changes in its documentation. The links mentioned in Vectara's documentation became broken due to updates, so I replaced them with working ones.

VectorStores / Retrievers / Memory
  - @dev2049

my twitter: [berkedilekoglu](https://twitter.com/berkedilekoglu)
PassthroughOutputParser
Labels: name: auto:enhancement

# Your PR Title (What it does)

<!--
Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution.

Replace this with a description of the change, the issue it fixes (if applicable), and relevant context. List any dependencies required for this change.

After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle!
-->

<!-- Remove if not applicable -->

Fixes # (issue)

## Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests, lint
etc:

https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @vowelparrot

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
Raise an exception in MKRL and Chat Output Parsers if parsing text which contains both an action and a final answer

Raises exception if OutputParsers receive a response with both a valid action and a final answer

Currently, if an OutputParser receives a response which includes both an action and a final answer, they return a FinalAnswer object. This allows the parser to accept responses which propose an action and hallucinate an answer without the action being parsed or taken by the agent.

This PR changes the logic to:
1. store a variable checking whether a response contains the `FINAL_ANSWER_ACTION` (this is the easier condition to check). 
2. store a variable checking whether the response contains a valid action
3. if both are present, raise a new exception stating that both are present
4. if an action is present, return an AgentAction
5. if an answer is present, return an AgentAnswer
6. if neither is present, raise the relevant exception based around the action format (these have been kept consistent with the prior exception messages)

Disclaimer:
* Existing mock data included strings which did include an action and an answer. This might indicate that prioritising returning AgentAnswer was always correct, and I am patching out desired behaviour? @hwchase17 to advice. Curious if there are allowed cases where this is not hallucinating, and we do want the LLM to output an action which isn't taken.
* I have not passed `send_to_llm` through this new exception

Fixes #5601 

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@hwchase17 - project lead
@vowelparrot
Issue: ConversationalRetrievalQAChain returns the qaTemplate condensed question as the first token

### Issue you'd like to raise.

I am using the ConversationalRetrievalQAChain to retrieve answers for questions while condensing the chat history to a standalone question. The issue I am facing is that the first token returned by the chain.call handleLLMNewToken is the standalone condensed question when there is a chat_history provided. Ideally, I do not want the condensed question to be sent via the handleLLMNewToken instead I want just the answer tokens. Is there any way to achieve that? Here is the code I am running:

`import { CallbackManager } from "langchain/callbacks";
import { ConversationalRetrievalQAChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models";
import { PineconeStore } from "langchain/vectorstores/pinecone";

const CONDENSE_PROMPT = `Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.

Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:`;

const QA_PROMPT = `You are an AI assistant. Use the following pieces of context to answer the question at the end.
If you don't know the answer, just say you don't know. DO NOT try to make up an answer.
If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.

{context}

Question: {question}
Helpful answer in markdown:`;

export const makeChain = (
    vectorstore: PineconeStore,
    onTokenReceived: (data: string) => void
) => {
    const model = new ChatOpenAI({
        temperature: 0,
        streaming: true,
        modelName: "gpt-3.5-turbo",
        openAIApiKey: process.env.OPENAI_API_KEY as string,
        callbackManager: CallbackManager.fromHandlers({
            async handleLLMNewToken(token) {
                onTokenReceived(token);
            },
            async handleLLMEnd(result) {},
        }),
    });

    return ConversationalRetrievalQAChain.fromLLM(
        model,
        vectorstore.asRetriever(),
        {
            qaTemplate: QA_PROMPT,
            questionGeneratorTemplate: CONDENSE_PROMPT,
            returnSourceDocuments: true, // The number of source documents returned is 4 by default
        }
    );
};
`

### Suggestion:

_No response_
Issue: How to let Agent act in a more consistent way, e.g., not jumping from a tool to another before a task is finished

### Issue you'd like to raise.

Hi,

I am using Langchain to implement a customer service agent. I am using AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION and ConversationBufferMemory.

Findings:

1. the Agent works very well with lookup & retrieve QA, e.g., what is the material of a t-shirt, how long does it take to ship...

2. However, the Agent failed to process a task consistently.

- For example, Image the agent has two tools: [cancel-order-tool] & [size-lookup-tool]. 
- Now the user wants to cancel an order.
- User says: "I want to cancel the order of the XYZ t-shirt."
- Agent using [cancel-order-tool]: "Sorry to hear that. May I know why you want to cancel the order?"
- User: "The size is too big"
- Agent using [size-question-tool]: Please look up the size in the website size chart. 
                    ---> this is a wrong answer. The agent switched from [cancel-order-tool] to [size-lookup-tool].

How can I implement the consistency here? So that the Agent will continue to process the cancel-order issue instead of jumping into the size QA.

I think consistency is very important to the customer service application where we have kind of strict SOPs.


### Suggestion:


Maybe I should overwrite the plan function of the agent so that it can plan & act in a more consistent way? E.g., implement a state transit machine
Issue: <Please write a comprehensive title after the 'Issue: ' prefix>

### Issue you'd like to raise.

Hi,

I am using Langchain to implement a customer service agent. I am using AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION and ConversationBufferMemory.

Findings:

1. the Agent works very well with lookup & retrieve QA, e.g., what is the material of a t-shirt, how long does it take to ship...

3. However, the Agent failed to process a task consistently. 
      -  For example, Image the agent has two tools: "cancel-order-tool" & "size-lookup-tool". Now the user wants to return a t-shirt.
      - User says: I want to return my t-shirt.
      - Agent: "using cancel-order-tool" sorry to hear that. May I know why you want to return it?
      - User: the size is too big
      - Agent: "using size-question-tool" Please look up the size in the website size chart. ---> this is a wrong answer. The agent switched from "cancel-order-tool" to "size-question-tool".

How can I implement the consistency here? So that the Agent will continue to process the cancel-order issue instead of jumping into the size QA.

I think consistency is very important to the customer service application where we have kind of strict SOPs.

### Suggestion:

Maybe I should overwrite the plan function of the agent so that it can process in a more consistent way?
Issue: How to let Agent behave in a more consistent way, e.g., under my customer service SOP?

### Issue you'd like to raise.

Hi,

I am using Langchain to implement a customer service agent. I am using AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION and ConversationBufferMemory.

Findings:

1. the Agent works very well with lookup & retrieve QA, e.g., what is the material of a t-shirt, how long does it take to ship...

3. However, the Agent failed to process a task consistently. 
      -  For example, the user wants to return a t-shirt. Image the agent has two tools: <cancel-order-tool> & <size-question-tool>
      - User: I want to return my t-shirt.
      - Agent: <using cancel-order-tool> sorry to hear that. May I know why you want to return it?
      - User: the size is too big
      - Agent: <using size-question-tool> Please look up the size in the website size chart. ---> this is a wrong answer. The agent switched from <cancel-order-tool> to <size-question-tool>.

How can I implement the consistency here? So that the Agent will continue to process the cancel-order issue instead of jumping into the size QA.

I think consistency is very important to the customer service application where we have kind of strict SOPs.

### Suggestion:

Maybe I should override the plan function in the agent so that it can plan in a more consistent way?
Fix outputparser answer and action

Raises exception if OutputParsers receive a response with both a valid action and a final answer

Currently, if an OutputParser receives a response which includes both an action and a final answer, they return a FinalAnswer object. This allows the parser to accept responses which propose an action and hallucinate an answer without the action being parsed or taken by the agent.

This PR changes the logic to:
1. store a variable checking whether a response contains the `FINAL_ANSWER_ACTION` (this is the easier condition to check). 
2. store a variable checking whether the response contains a valid action
3. if both are present, raise a new exception stating that both are present
4. if an action is present, return an AgentAction
5. if an answer is present, return an AgentAnswer
6. if neither is present, raise the relevant exception based around the action format (these have been kept consistent with the prior exception messages)

Disclaimer:
* Existing mock data included strings which did include an action and an answer. This might mean that I am patching out desired behaviour? @hwchase17 up to you whether you are comfortable with this change conceptually, or whether there cases where this is not hallucinating, and we do want the LLM to output an action which isn't taken.
* I have not passed `send_to_llm` through this exception. The reason I haven't is that I can't think of a valid observation - for example, it is not accurate from a text completion standpoint to say "Final answer should not follow action" (or something to this effect). The problem is that the model hallucinates the correct format and returns that in the response. (I can easily make this change to the exception if we wish)

Fixes #5601 

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@hwchase17 - project lead
@vowelparrot
Add `ArgillaCallbackHandler`

Hi to whoever is reading this! 👋🏻 According to the PR Template I guess it may be @agola11, so hi in advance!

# What's in this PR?

As of the recent [v1.8.0](https://github.com/argilla-io/argilla/releases/tag/v1.8.0) release of [Argilla](https://github.com/argilla-io/argilla), the `FeedbackDataset`s were introduced, which are a new type of dataset is designed to cover the specific needs of working with LLMs.

So we thought it was a nice opportunity to create an `ArgillaCallbackHandler` to be integrated within `LangChain` (because Argilla ❤️ LangChain). Besides the `ArgillaCallbackHandler` we've included a Jupyter Notebook to serve as a tutorial on how to use the callback to track the inputs and the responses that come into LangChain, to generate a dataset to be curated for LLM evaluation, monitoring, and potentially fine-tuning.

Besides the `ArgillaCallbackHandler` itself, we've also included a Jupyter Notebook to show how to use it.

# What's missing in this PR?

We didn't include any integration tests, since `argilla` relies on an Argilla Server deployed, and following the suggestions, tests that require a network connection are not preferred, that's why. But we could add those if needed during the review of this PR!

# Who to mention?

If this PR moves forward, we'd love to be tagged:

* In Twitter as https://twitter.com/argilla_io?lang=en
* In LinkedIn as https://www.linkedin.com/company/argilla-io

Thanks in advance!
OutputParsers currently allows model to hallucinate the output of an action

### System Info

The MRKL and chat output parsers currently will allow an LLM response to generate a valid action, as well as hallucinate a "final answer" based on that response.

[Logic](https://github.com/hwchase17/langchain/blob/master/langchain/agents/chat/output_parser.py#L15)

This is because the parser is returning an AgentFinish object immediately if `FINAL_ANSWER_ACTION` is in the text, rather than checking if the text also includes a valid action. I had this appear when using the Python agent, where the LLM returned a code block as the action, but simultaneously hallucinated the output and a final answer in one response. (In this case, it was quite obvious because the code block referred to a database which does not exist)

I'm not sure if there are any situations where it is desired that a response should output an action as well as an answer?

If this is not desired behaviour, it can be easily fixable by raising an exception if a response includes both a valid action, and "final answer" rather than returning immedately from either condition.

### Who can help?

@hwchase17 @agola11 

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [X] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

````py
from langchain.agents.chat.output_parser import ChatOutputParser

parser = ChatOutputParser()

valid_action = """Action:
```
{
"action": "Python REPL",
"action_input": "print(\'Hello world!\')"
}
```
final_answer = """Final Answer: Goodbye world!"""

print(parser.parse(valid_action))  # outputs an AgentFinish
print(parser.parse(final_answer))  # outputs an AgentAction
print(parser.parse(valid_action + final_answer))  # outputs an AgentFinish, should probably raise an Exception
````

### Expected behavior

An exception should likely be raised if an LLM returns a response that both includes a final answer, and a parse-able action, rather than skipping the action and returning the final answer, since it probably hallucinated an output/observation from the action.
Issue: Does langchain store the database in memory?

### Issue you'd like to raise.

Say I have a huge database stored in BigQuery, and I'd like to use the SQL Database Agent to query this database using natural language prompts. I can't store the data in memory because it's too huge. Does the [`SQLDatabase`](https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html#sql-database-agent) function store this in memory? 

If so, can I directly query the source data without loading everything? I'm comfortable with the latencies involved with read operations on disk. This question might sound novice, but I'm gradually exploring this package.

### Suggestion:

_No response_
I want to promote Langchain in China and publish a book about it. Can I have your permission?

### Issue you'd like to raise.

My name is Even Kang and I am a Chinese developer studying Langchain in China. We have translated the Langchain Chinese documentation (www.langchain.asia / www.langchain.com.cn) and launched the website on May 7th. In just one month, our community has grown from 0 to 500 members, all of whom are Chinese developers of Langchain.

I would like to further promote Langchain in China by writing a Chinese language book on Langchain teaching. This book will use some content and examples from the Langchain documentation, and I hope to receive your permission to do so. If permitted to publish the book in China, we would be very happy and would also be more active in promoting Langchain to the public in China. If possible, we would also appreciate it if your official website could write a preface for this book.

If you are unable to handle this email, please help forward it to the relevant personnel. Thank you. We look forward to your reply.

### Suggestion:

_No response_
Issue: .doc files are not supported by DirectoryLoader and ask to download LibreOffice

### Issue you'd like to raise.

Hi,
Whenever I am trying to upload a directory containing multiple files using DirectoryLoader, It is loading files properly.

from langchain.vectorstores import Chroma                                  
from langchain.embeddings import OpenAIEmbeddings                                 
from langchain.text_splitter import RecursiveCharacterTextSplitter , TokenTextSplitter             
from langchain.llms import OpenAI                                             
from langchain.chat_models import ChatOpenAI                                  
from langchain.chains import VectorDBQA, RetrievalQA                                        
from langchain.document_loaders import TextLoader, UnstructuredFileLoader, DirectoryLoader

loader = DirectoryLoader("D:/files/data", show_progress=True)  
docs = loader.load()                                                   
text_splitter = TokenTextSplitter(chunk_size=1000, chunk_overlap=200)
texts = text_splitter.split_documents(docs)
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)                                             
vectordb = Chroma.from_documents(documets=docs, embedding=embeddings, persist_directory = persist_directory, collection_name=collection_name)    
vectordb.persist()                      
vectordb = None

but if my loaded directory is containing .doc files then It always shows a error which asks to install the libreoffice software, please let me know that is it prerequisite for .doc types file or there is any other way to fix this issue.

Thank You

### Suggestion:

_No response_