delayedkarma/langchain-issues huggingface dataset:
Update reX Exp  & Added method to return the type of the parser
Labels: name: needs test

<!--
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?

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

 -->
use tenacity to retry in cohere llm as it is done for openai llms
Labels: name: lgtm

A minor update to retry Cohore API call in case of errors using tenacity as it is done for OpenAI LLMs.

#### Who can review?

@hwchase17, @agola11 

<!-- 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

 -->
fixing gpt4all.py to use get_model_from_type instead of model_type

This  is to fix the error :   File "\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\llms\gpt4all.py", line 156, in validate_environment
    values["backend"] = values["client"].model_type
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'GPT4All' object has no attribute 'model_type'

<!--
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?

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

 -->
Regular Expression Fails to Match Newline-Starting Action Inputs

### System Info

LangChain version: `0.0.189`
OS: Ubuntu `22.04.2`
Python version: `3.10.7`


### Who can help?

@vowelparrot

### Information

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

### Related Components

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

### Reproduction

Reproducing this issue can be challenging as it hinges on the action input generated by the LLM. Nevertheless, the issue occurs when using an agent of type `CONVERSATIONAL_REACT_DESCRIPTION`. The agent's output parser attempts to [extract](https://github.com/hwchase17/langchain/blob/d0d89d39efb5f292f72e70973f3b70c4ca095047/langchain/agents/conversational/output_parser.py#L21) both the tool's name that the agent needs to utilize for its task and the input to that tool based on the LLM prediction.

In order to accomplish this, the agent's output parser employs the following regular expression on the LLM prediction: `Action: (.*?)[\n]*Action Input: (.*)`. This expression divides the LLM prediction into two components: i) the tool that needs to be utilized (Action) and ii) the tool's input (Action Input).

However, the action input generated by an LLM is an arbitrary string. Hence, if the action input initiates with a newline character, the regular expression's search operation fails to find a match, resulting in the action input defaulting to an empty string. This issue stems from the fact that the `.` character in the regular expression doesn't match newline characters by default. Consequently, `(.*)` stops at the end of the line it started on.

This behavior aligns with the default functionality of the Python `re` library. To rectify this corner case, we must include the [`re.S`](https://docs.python.org/3/library/re.html#:~:text=in%20version%203.11.-,re.S,-%C2%B6) flag in the `re.search()` method. This will allow the `.` special character to match any character, including a newline.

> re.S
> re.DOTALL
> Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline. Corresponds to the inline flag (?s).

### Expected behavior

The `re.search()` method correctly matches the action input section of the LLM prediction and sets it to the relevant string, even if it starts with the new line character.

I am prepared to open a new Pull Request (PR) to address this issue. The change involves modifying the following [line](https://github.com/hwchase17/langchain/blob/d0d89d39efb5f292f72e70973f3b70c4ca095047/langchain/agents/conversational/output_parser.py#L21):

From:

```python

match = re.search(regex, text)
```

To:

```python

match = re.search(regex, text, re.S)
```
feat: issue-5712 add sleep tool
Labels: name: lgtm

Fixes # 5712 added sleep tool



<!-- 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?


@vowelparrot 

<!-- 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

 -->
NotEnoughElementsException

im getting this error 

AttributeError: module 'chromadb.errors' has no attribute 'NotEnoughElementsException'


here my code 

```
persist_directory = 'vectorstore'
embeddings = OpenAIEmbeddings()
vectorstore = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
chat_history = []
vectorstore.add_texts(["text text text"])
llm = ChatOpenAI(temperature=0.2)

qa = ConversationalRetrievalChain.from_llm(
    llm,
    vectorstore.as_retriever(),
)  
```


does it mean my vectorstore is damaged ?
Inference parameters for Bedrock titan models not working

### System Info

LangChain version 0.0.190
Python 3.9

### Who can help?

@seanpmorgan @3coins 

### Information

- [ ] The official example notebooks/scripts
- [X] 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

Tried the following to provide the `temperature` and `maxTokenCount` parameters when using the `Bedrock` class for the `amazon.titan-tg1-large` model.

```
import boto3
import botocore
from langchain.chains import LLMChain
from langchain.llms.bedrock import Bedrock
from langchain.prompts import PromptTemplate
from langchain.embeddings import BedrockEmbeddings

prompt = PromptTemplate(
    input_variables=["text"],
    template="{text}",
)

llm = Bedrock(model_id="amazon.titan-tg1-large")
llmchain = LLMChain(llm=llm, prompt=prompt)

llm.model_kwargs = {'temperature': 0.3, "maxTokenCount": 512}

text = "Write a blog explaining Generative AI in ELI5 style."
response = llmchain.run(text=text)
print(f"prompt={text}\n\nresponse={response}")
```

This results in the following exception
```
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: The provided inference configurations are invalid
```

This happens because https://github.com/hwchase17/langchain/blob/d0d89d39efb5f292f72e70973f3b70c4ca095047/langchain/llms/bedrock.py#L20 passes these params as key value pairs rather than putting them in the `textgenerationConfig` structure as the Titan model expects them to be,

The proposed fix is as follows:
```
 def prepare_input(
        cls, provider: str, prompt: str, model_kwargs: Dict[str, Any]
    ) -> Dict[str, Any]:
     input_body = {**model_kwargs}
     if provider == "anthropic" or provider == "ai21":
         input_body["prompt"] = prompt
     elif provider == "amazon":
          input_body = dict()
          input_body["inputText"] = prompt
          input_body["textGenerationConfig] = {**model_kwargs}           
      else:
          input_body["inputText"] = prompt

    if provider == "anthropic" and "max_tokens_to_sample" not in input_body:
        input_body["max_tokens_to_sample"] = 50

    return input_body
``` 


```

### Expected behavior

Support the inference config parameters.
Update test_base.py
Labels: name: area: agent, name: auto:improvement

<!--
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?

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

 -->
DOC: tracing documentation "404 Not Found"

### Issue with current documentation:

I am trying to view the documentation about tracing via Use Cases --> Evaluation --> Question Answering Benchmarking: State of the Union Address --> "See [here](https://langchain.readthedocs.io/en/latest/tracing.html) for an explanation of what tracing is and how to set it up", but the link shows "404 Not Found"
<img width="1247" alt="Screen Shot 2023-06-05 at 13 26 52" src="https://github.com/hwchase17/langchain/assets/72342196/35ea922e-e9ca-4e97-ba8f-304a79474771">


### Idea or request for content:

_No response_
feat: :sparkles: Added a LLM callback to store LLM IO in-memory

This can be useful if we want an interface to store LLM's output to some DB. I have created a very basic callback class, please guide me on how we can make it better and more extensible. Also if something like this already exists, please guide me I am very interested in how we can log these LLM inputs-outputs to a DB so that we can use the back as example prompts

#### Who can review?

Tag maintainers/contributors who might be interested:

  Tracing / Callbacks
  - @agola11
ValueError: Not a valid json with Directory Loader function

Hi, I load a folder with txt file and using Directory Loader. It keeps show this error

> File "/Users/mycompany/test-venv/lib/python3.8/site-packages/unstructured/partition/json.py", line 45, in partition_json
>     raise ValueError("Not a valid json")
> ValueError: Not a valid json

When I tried with just 10 txt file before, it was fine. Now I loaded around hundred files it shows that error. After searched, probably caused by one of the documents is not valid when parsing it to json. But I struggle to track which document caused the error. Maybe any ways to do it? Here is my code

> def construct_document(directory_path, persists_directory):
>   loader = DirectoryLoader(directory_path, glob="**/*.txt")
>   documents = loader.load()
>   text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
>   texts = text_splitter.split_documents(documents)
>   embeddings = OpenAIEmbeddings(openai_api_key=os.environ["OPENAI_API_KEY"])
>   vectordb = Chroma.from_documents(texts, embeddings, 
>                                   persist_directory=persists_directory)
>   vectordb.persist()
>   return embeddings

Thank you
JSON Agent fails when top level of input json is List object.

### Issue you'd like to raise.

JsonSpec() failes to init when top level of json is List.
It seems the JsonSpec only supports a top level dict object. 

We can avoid the error by adding a dummy key to the list, but is this an intended limitation?

test.json
```json
[
  {"name": "Mark", "age":16},
  {"name": "Gates", "age":63}
]
```

Code:
```python
import pathlib
from langchain.agents.agent_toolkits import JsonToolkit
from langchain.tools.json.tool import JsonSpec
from langchain.agents import create_json_agent
from langchain.llms import OpenAI

json_spec = JsonSpec.from_file(pathlib.Path("test.json"))
json_toolkit = JsonToolkit(spec=json_spec)
agent = create_json_agent(OpenAI(), json_toolkit, verbose=True)
```

Error:
```
Traceback (most recent call last):
    json_spec = JsonSpec.from_file(pathlib.Path("test.json"))
  File "/usr/local/lib/python3.10/dist-packages/langchain/tools/json/tool.py", line 40, in from_file
    return cls(dict_=dict_)
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for JsonSpec
dict_
  value is not a valid dict (type=type_error.dict)
  ```
  
Versions
 * Python 3.10.6
 * langchain  0.0.186

### Suggestion:

_No response_
[Draft] Add initial draft of document manager
Labels: name: area: vector store, name: auto:enhancement

Adding very initial rough draft of the document manger.

On a high level it supports the following operations:
- Add
- Update
- UpdateTruncate

`Update` and `UpdateTruncate` differ in that `UpdateTruncate` deletes the set of documents that are not present in the new set of documents passed in. `Update` only updates the existing documents. 

The document manager currently returns the a list of operations that need to be performed by the user on the vector store. This can be integrated into the existing vector store interface by adding a new method in `VectorStore` that applies add, update and delete operations.

An example script is included in the changes which is an example of the interface. It is also runnable, and proves the correctness of the document manager.

@hwchase17
feat: Support for `Tigris` Vector Database for vector search
Labels: name: lgtm

### Changes
- New vector store integration - [Tigris](https://tigrisdata.com)
- Adds [tigrisdb](https://pypi.org/project/tigrisdb/) optional dependency
- Example notebook demonstrating usage

Fixes #5535 
Closes tigrisdata/tigris-client-python#40

#### Twitter handles
We'd love a shoutout on our [@TigrisData](https://twitter.com/TigrisData) and [@adilansari](https://twitter.com/adilansari) twitter handles

#### Who can review?
@dev2049
DOC: Type hint mismatch indicating that chain.apply should return Dict[str, str] instead of Dict[str, Any]

### Issue with current documentation:

Not sure if this is actually a documentation error, but at least the error is in the code's typehints in `langchain.chain.base.py`, where:

```
    def __call__(
        self,
        inputs: Union[Dict[str, Any], Any],
        return_only_outputs: bool = False,
        callbacks: Callbacks = None,
    ) -> Dict[str, Any]:
```
indicates that it returns a dict with Any values while the .apply is specified as follows:

```
    def apply(
        self, input_list: List[Dict[str, Any]], callbacks: Callbacks = None
    ) -> List[Dict[str, str]]:
        """Call the chain on all inputs in the list."""
        return [self(inputs, callbacks=callbacks) for inputs in input_list]
```

This seems to be a consistent error also applying to e.g. `.run`.

Langchain version:
0.0.187

### Idea or request for content:

Change the type hints to consistently be dict[str, Any]. This however, will open up the output space considerably.

If desired I can open PR.
Sitemap filters not working due to lack of stripping whitespace and newlines

https://github.com/hwchase17/langchain/blob/8d9e9e013ccfe72d839dcfa37a3f17c340a47a88/langchain/document_loaders/sitemap.py#L83

if
```
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <url>
        <loc>
            https://tatum.com/
        </loc>
        <xhtml:link rel="alternate" hreflang="x-default" href="https://tatum.com/"/>
    </url>
```
then
` re.match(r, loc.text) for r in self.filter_urls` 

Comparison to filter here will be comparing against a value that includes those whitespaces and newlines.

What worked for me:

``` def parse_sitemap(self, soup: Any) -> List[dict]:
        """Parse sitemap xml and load into a list of dicts."""
        els = []
        for url in soup.find_all("url"):
            loc = url.find("loc")
            if not loc:
                continue
            loc_text = loc.text.strip()
            if self.filter_urls and not any(
                re.match(r, loc_text) for r in self.filter_urls
            ):
                continue```
DOC: Update Helicone docs to include requirement for API key

### Issue with current documentation:

Currently the [Helicone integration docs](https://python.langchain.com/en/latest/integrations/helicone.html) don't include the fact that an [API key now must be used by passing this header](https://docs.helicone.ai/quickstart/integrate-in-one-minute):
```
Helicone-Auth: Bearer $HELICONE_API_KEY
```

### Idea or request for content:

Add this to the docs.
Add metadata filter capability to similarity search functions for Supabase
Labels: name: area: vector store, name: auto:improvement


Title:
Add metadata filtering capabilities to similarity search functions

Description:

This PR enhances the functionality of the similarity search methods in our codebase. Specifically, we now support optional metadata-based filtering in our search functions.

Details:

The affected functions include:

similarity_search
similarity_search_by_vector
similarity_search_with_relevance_scores
similarity_search_by_vector_with_relevance_scores
similarity_search_by_vector_returning_embeddings
For each of these functions, a new filter argument has been added. This argument accepts a dictionary that specifies metadata fields and their desired values.

When the filter dictionary is provided, the search functions will return documents that not only match the query based on similarity but also satisfy the metadata criteria defined by the filter.

Impact:

This change provides greater flexibility for users when conducting similarity searches. They can now refine their search results based on specific metadata properties, leading to more accurate and targeted results.

Tests:

Testing will involve invoking the modified functions with various filter criteria and verifying the returned documents meet both the similarity and metadata filter criteria.

  VectorStores / Retrievers / Memory
  - @dev2049 may be interested
Use client from LCP-SDK

- Remove the client implementation (this breaks backwards compatibility for existing testers. I could keep the stub in that file if we want, but not many people are using it yet
- Add SDK as dependency
- Update the 'run_on_dataset' method to be a function that optionally accepts a client as an argument
- Remove the langchain plus server implementation (you get it for free with the SDK now)

We could make the SDK optional  for now, but the plan is to use w/in the tracer so it would likely become a hard dependency at some point.