delayedkarma/langchain-issues huggingface dataset:
Instance anonymization
Labels: name: area: memory, name: lgtm, name: auto:improvement

### Description

Add instance anonymization - if `John Doe` will appear twice in the text, it will be treated as the same entity.
The difference between `PresidioAnonymizer` and `PresidioReversibleAnonymizer` is that only the second one has a built-in memory, so it will remember anonymization mapping for multiple texts:

```
>>> anonymizer = PresidioAnonymizer()
>>> anonymizer.anonymize("My name is John Doe. Hi John Doe!")
'My name is Noah Rhodes. Hi Noah Rhodes!'
>>> anonymizer.anonymize("My name is John Doe. Hi John Doe!")
'My name is Brett Russell. Hi Brett Russell!'
```
```
>>> anonymizer = PresidioReversibleAnonymizer()
>>> anonymizer.anonymize("My name is John Doe. Hi John Doe!")
'My name is Noah Rhodes. Hi Noah Rhodes!'
>>> anonymizer.anonymize("My name is John Doe. Hi John Doe!")
'My name is Noah Rhodes. Hi Noah Rhodes!'
```

### Twitter handle
@deepsense_ai / @MaksOpp

### Tag maintainer
@baskaryan @hwchase17 @hinthornw
Agent Variant 4
Labels: name: area: agent, name: auto:enhancement

- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x
- x

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Issue: <Please write a comprehensive title after the 'Issue: ' prefix>
Labels: name: auto:question

### Issue you'd like to raise.


When I run the code I don't get any errors but I also don't get any output in the terminal or output area either? Can you help?
![Screenshot 2023-09-12 101445](https://github.com/langchain-ai/langchain/assets/72319290/8e7ac61a-8343-409f-bb98-a2cbf7401ad7)


### Suggestion:

_No response_
Add Baidu Qianfan endpoint for LLM
Labels: name: lgtm, name: auto:enhancement, name: area: models

- Description：
    * Baidu AI Cloud's [Qianfan Platform](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html) is an all-in-one platform for large model development and service deployment, catering to enterprise developers in China. Qianfan Platform offers a wide range of resources, including the Wenxin Yiyan model (ERNIE-Bot) and various third-party open-source models.
- Issue: none
- Dependencies: 
    * qianfan
- Tag maintainer: @baskaryan
- Twitter handle:
FlareChain's response_chain not picking up specified LLM model
Labels: name: area: embeddings, name: auto:bug, name: area: models

### System Info

Using LangChain 0.0.276
Python 3.11.4 

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

Construct a FlareChain instance like this and run it:

```
    myllm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")

    flare = FlareChain.from_llm(
        llm=myllm,
        retriever=vectorstore.as_retriever(),
        max_generation_len=164,
        min_prob=0.3,
    )
    result = flare.run(querytext)
```

When I inspect during debugging, the specified LLM model was set on `flare.question_generator_chain.llm.model_name` but NOT `flare.response_chain.llm.model_name`,
which is still the default value. 


### Expected behavior

I'm expecting `flare.response_chain.llm.model_name` to return `gpt-3.5-turbo-16k`, not `text-davinci-003`
Update milvus.py: avoid key error of insert_dict
Labels: name: area: vector store, name: auto:bug

the Milvus.fields is union of all metadata.keys from different file types. but insert_dict is limited to specific file, `insert_dict[x]` will raise key error after Milvus.fields growed.

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
add vearch repository link
Labels: name: auto:documentation

  - Description: add vearch repository link

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Improve code example indent
Labels: name: lgtm, name: auto:nit

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Issue: pinecone.core.client.exceptions.ApiTypeError: Invalid type for variable 'namespace'. Required value type is str and passed type was NoneType at ['namespace']
Labels: name: area: vector store, name: auto:bug, name: integration: pinecone

### Issue you'd like to raise.

I am getting this error when using langchain vectorstores similarity  search on local machine. `pinecone.core.client.exceptions.ApiTypeError: Invalid type for variable 'namespace'. Required value type is str and passed type was NoneType at ['namespace']`. But it is working fine on Google Colab. 

### Suggestion:

_No response_
Redis vector  init error
Labels: name: area: vector store, name: auto:bug

### System Info

Langchain:0.0.286
python:3.10.10
redis:5.0.0b4

### Who can help?

@hwc

### Information

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

### Related Components

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

### Reproduction

rds = Redis.from_texts(
    texts,
    embeddings,
    metadatas=metadata,
    redis_url="XXXXX",
    index_name="XXXX"
)
The following exception occurred：
AttributeError: 'RedisCluster' object has no attribute 'module_list'

The version of my redis package is 5.0.0b4.

An error occurred in the following code：

langchain\Lib\site-packages\langchain\utilities\redis.py

def check_redis_module_exist(client: RedisType, required_modules: List[dict]) -> None:
    """Check if the correct Redis modules are installed."""
-> installed_modules = client.module_list()

### Expected behavior

redis init success
Add device to GPT4All
Labels: name: auto:improvement, name: area: models

### Feature request

Hey guys!
Thanks for the great tool you've developed.

LLama now supports device and so is GPT4All:
https://docs.gpt4all.io/gpt4all_python.html#gpt4all.gpt4all.GPT4All.__init__

Can you guys please add the device property to the file: "langchain/llms/gpt4all.py"

LN 96:
`
    device: Optional[str] = Field("cpu", alias="device")
    """Device name: cpu, gpu, nvidia, intel, amd or DeviceName."""
`

Model Init:
`
        values["client"] = GPT4AllModel(
            model_name,
            model_path=model_path or None,
            model_type=values["backend"],
            allow_download=values["allow_download"],
            device=values["device"]
        )
`


### Motivation

Necessity to use the device on GPU powered machines.

### Your contribution

None.. :(
Mark Vertex AI classes as serialisable
Labels: name: lgtm, name: auto:improvement, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Issue: Use huggingface_hub InferenceClient instead of InferenceAPI
Labels: name: auto:improvement, name: area: models

### Issue you'd like to raise.

Langchain is still using the deprecated huggingface_hub `InferenceApi` in the latest version. the `InferenceApi` will be removed from version '0.19.0'.

```
/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_deprecation.py:127: FutureWarning: '__init__' (from 'huggingface_hub.inference_api') is deprecated and will be removed from version '0.19.0'. `InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out this guide to learn how to convert your script to use it: https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client.
  warnings.warn(warning_message, FutureWarning)
```

### Suggestion:

It it recommended to use the new `InferenceClient` in huggingface_hub.
Issue: Which version of langchain supports the elasticsearch 7.6
Labels: name: area: vector store, name: auto:question

### Issue you'd like to raise.

Hi Team,

I have a fixed elasticsearch version 7.6 which i cannot upgrade. could you please share me some details about which version of langchain supports mentioned version.

Problem with the latest langchain i have faced, similarity search or normal search says that KNN is not available. "Unexpected keyword argument called 'knn'".

if possible please share a sample code to connect with the existing elastic search and create an index to update the Elasticsearch data to Lang chain supported data format or document format.

### Suggestion:

_No response_
Fix tool arguments formatting in StructuredChatAgent
Labels: name: area: agent, name: lgtm, name: auto:bug

In the `FORMAT_INSTRUCTIONS` template, 4 curly braces (escaping) are used to get single curly brace after formatting:

```
"{{{ ... }}}}" -> format_instructions.format() ->  "{{ ... }}" -> template.format() -> "{ ... }".
```

Tool's `args_schema` string contains single braces `{ ... }`, and is also transformed to `{{{{ ... }}}}` form. But this is not really correct since there is only one `format()` call:

```
"{{{{ ... }}}}" -> template.format() -> "{{ ... }}".
```

As a result we get double curly braces in the prompt:
````
Respond to the human as helpfully and accurately as possible. You have access to the following tools:

foo: Test tool FOO, args: {{'tool_input': {{'type': 'string'}}}}    # <--- !!!
...
Provide only ONE action per $JSON_BLOB, as shown:

```
{
  "action": $TOOL_NAME,
  "action_input": $INPUT
}
```
````

This PR fixes curly braces escaping in the `args_schema` to have single braces in the final prompt:
````
Respond to the human as helpfully and accurately as possible. You have access to the following tools:

foo: Test tool FOO, args: {'tool_input': {'type': 'string'}}    # <--- !!!
...
Provide only ONE action per $JSON_BLOB, as shown:

```
{
  "action": $TOOL_NAME,
  "action_input": $INPUT
}
```
````
max_execution_time does not work for some queries in create_pandas_dataframe_agent
Labels: name: area: agent, name: auto:bug

### System Info

python == 3.11
langchain == 0.0.286
windows 10




### Who can help?

@hwchase17

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [X] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from langchain.chat_models import AzureChatOpenAI
from langchain.agents.agent_types import AgentType
from langchain.agents import create_pandas_dataframe_agent

llm = AzureChatOpenAI(
                deployment_name = "gpt-4", 
                model_name = "gpt-4",
                openai_api_key = '...',
                openai_api_version = "2023-08-01-preview",
                openai_api_base = '...',
                temperature = 0
                )

df = pd.DataFrame({  
    'Feature1': np.random.rand(1000000),  
    'Feature2': np.random.rand(1000000),  
    'Class': np.random.choice(['Class1', 'Class2', 'Class3'], 1000000)  
})  

agent = create_pandas_dataframe_agent(
                                                        llm, 
                                                        df, 
                                                        verbose=False, 
                                                        agent_type=AgentType.OPENAI_FUNCTIONS,
                                                        reduce_k_below_max_tokens=True, 
                                                        max_execution_time = 1,
                                                     )

agent.run('print 100 first rows in dataframe')
```




### Expected behavior

The `max_execution_time` is set to 1, indicating that the query should run for one second before stopping. However, it currently runs for approximately 10 seconds before stopping. This is a simple example, but in the case of the actual dataframe that I have (which contains a lot of textual data), the agent runs for around one minute before I receive the results. At the same time, if the query doesn't request a large amount of data from the model to output, the agent would stop in one second. For instance, if my query is agent.run('give some examples of delays mention?'), the results would not be returned because the max_execution_time is 1, and it needs roughly three seconds to output the results. Therefore, this troubleshooting indicates that there's an issue with the `max_execution_time` when the requested output is too lengthy.
fix typo in aleph_alpha.ipynb
Labels: name: area: embeddings, name: auto:documentation

fixes the aleph_alpha.ipynb typo from contnt to content

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: fix a typo in the docs, 
  - Issue: make docs more comprehensible,
  - Dependencies: -,
  - Tag maintainer: -,
  - Twitter handle: -

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Make entire element accessible for processing when loading with Unstructured loaders
Labels: name: area: doc loader, name: auto:improvement

### Feature request

Currently, Unstructured loaders allow users to process elements when loading the document. This is done by applying user-specified `post_processors` to each element. These post processing functions are str -> str callables.

When using Unstructured loaders, allow element processing using `(Element) -> Element` or `(Element) -> str` callables.

### Motivation

A user using `UnstructuredPDFLoader` wants to take advantage of the inferred table structure when processing elements. They can't use the `post_processors` argument to access `element.metadata.text_as_html` because the input to each `post_processors` callable is a string:
>I'm finding that the mode='elements' option already does str(element) to every element, so I can't really use element.metadata.text_as_html

They evaluated this workaround:
```
class CustomPDFLoader(UnstructuredPDFLoader):
    def __init__(
        self,
        *args,
        pre_processors: list[Callable[[elmt.Element], str]] | None,
        **kwargs,
    ) -> None:
        super().__init__(*args, **kwargs)
        self.pre_processors = pre_processors
​
    def _pre_process_elements(self, elements: list[elmt.Element]) -> elmt.Element:
        for element in elements:
            for cleaner in self.pre_processors:
                element.text = cleaner(element)
​
    def load(self) -> str:
        if self.mode != "single":
            raise ValueError(f"mode of {self.mode} not supported.")
​
        elements = self._get_elements()
        self._pre_process_elements(elements)
​
        metadata = self._get_metadata()
        text = "\n\n".join([str(el) for el in elements])
        docs = [Document(page_content=text, metadata=metadata)]
        return docs
```

The intent is for the `_pre_process_elements` method above to replace the call to `_post_process_elements` in the second line of the [original load function](https://github.com/langchain-ai/langchain/blob/737b75d278a0eef8b3b9002feadba69ffe50e1b1/libs/langchain/langchain/document_loaders/unstructured.py#L87). Using this workaround would require copying the rest of the `load` method's code in the subclass, too.

### Your contribution

The team at Unstructured can investigate this request and submit a PR if needed.
BedrockChat model mistakenly removed in latest version?
Labels: name: auto:bug, name: area: models

### System Info

It looks like BedrockChat was removed from the chat_models/__init__.py when ChatKonko was added in this commit: https://github.com/langchain-ai/langchain/pull/10267/commits/280c1e465c4b89c6313fcc2c0679e3756b8566f9#diff-04148cb9262d722a69b81a119e1f8120515532263a1807239f60f00d9ff2a755

I'm guessing this was accidental, because the BedrockChat class definitions still exist.

@agola11 @hwchase17 

### Who can help?

_No response_

### Information

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

.

### Expected behavior

I expect `from langchain.chat_models import BedrockChat` to work
Add Runnable.input_keys
Labels: name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->