delayedkarma/langchain-issues huggingface dataset:
langchain is not `pyinstaller` friendly due to dependency on external files, e.g. `llm_summarization_checker`
Labels: name: auto:bug, name: area: models

### System Info

```
langchain==0.0.335
```

```
python 3.11
```

### Who can help?

@hwchase17 

### 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
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. Create simple `test.py`:

```python
from langchain.chains.llm_summarization_checker.base import LLMSummarizationCheckerChain
from langchain.llms.fake import FakeListLLM

llm = FakeListLLM(responses=[])

chain = LLMSummarizationCheckerChain.from_llm(llm)
```

2. Install `pyinstaller` via `pip install -U pyinstaller`

3. Run

```
pyinstaller test.py`
```

4. Wait until it's done.

5. Run

```
$ ./dist/test/test 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from langchain.chains.llm_summarization_checker.base import LLMSummarizationCheckerChain
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "langchain/chains/__init__.py", line 51, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "langchain/chains/llm_summarization_checker/base.py", line 20, in <module>
  File "langchain_core/prompts/prompt.py", line 202, in from_file
FileNotFoundError: [Errno 2] No such file or directory: '/home/tiger/junk/tt/dist/test/_internal/langchain/chains/llm_summarization_checker/prompts/create_facts.txt'
[789522] Failed to execute script 'test' due to unhandled exception!
```

### Expected behavior

```
CREATE_ASSERTIONS_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "create_facts.txt")
CHECK_ASSERTIONS_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "check_facts.txt")
REVISED_SUMMARY_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "revise_summary.txt")
ARE_ALL_TRUE_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "are_all_true_prompt.txt")
```

These lines from https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/llm_summarization_checker/base.py should be changed to something like lazy loading, or just hard code the `.txt` files.

PS - I'm using `llama2` so these prompts do not work anyway.
DynamoDBChatMessageHistory saved Human Message duplicate
Labels: name: area: memory, name: auto:bug, name: integration: aws

### System Info

Langchain version: 0.0.351
boto3==1.34.3
Python version: 3.11.7

### Who can help?

I use DynamoDBChatMessageHistory as the conversation_history,  seems duplicate Human messages saved to DynamoDB table every time, AI message saved once.
Here is the duplicate messages:

![image](https://github.com/langchain-ai/langchain/assets/13569268/a395a097-47b8-429a-8d6e-3d8eaa9e5d0a)



Below is my code: 

`    def ask_stream(
        self,
        input_text: str,
        conversation_history: ConversationBufferMemory = ConversationBufferMemory(
            ai_prefix="Assistant"
        ),
        verbose: bool = False,
        **kwargs,
    ):
        """Processes a stream of input by invoking the engine.

        Parameters
        ----------
        conversation_history: ConversationBufferMemory
            The conversation history
        input_text: str
            The input prompt or message.
        verbose: boolean
            if the langchain shall show the detailed logging
        kwargs: dict
            Additional keyword arguments to pass to the engine.
            For example, you can pass in temperature to control the model's
            creativity.
        Returns
        -------
        str
            The response generated by the engine.

        Raises
        ------
        Any exceptions raised by the engine.
        """

        temp_stop = kwargs.get("stop", self.stop)

        template = """The following is a friendly conversation between a human and an AI."""
        PROMPT = PromptTemplate(input_variables=["history", "input"], template=template)

        chain = ConversationChain(
            llm=self.engine,
            memory=conversation_history,
            verbose=verbose,
            prompt=PROMPT,
        )

        return chain.predict(input=input_text, stop=temp_stop)

`

### 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
- [X] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. Start a new conversation with DynamoDBChatMessageHistory as memory.

### Expected behavior

Each HumanMessage should be saved once in DynamoDB table.
Bing Search Tool has key value error
Labels: name: area: agent, name: auto:bug

### System Info

Python=3.10
Langchain=0.0.352
langchain-community==0.0.6

I'm using a custom Bing search engine. When I asked something that my Bing search was not able to return results "Webpages" does not exist. 

I had to change this:  search_results["webPages"]["value"] (line 47) to 

 if "webPages" in search_results:
            return search_results["webPages"]["value"]
        else:
            return []

### 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
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. Create an OpenAI Functions agent with Bing
2. Have a custom bing search
3. Search for something that will not return results from Bing

### Expected behavior

Expect the tool to return "No bing results found" and then a response from an agent
ModuleNotFoundError: No module named 'langchain.vectorstores.neo4j_vector'
Labels: name: area: vector store, name: auto:documentation

### Issue with current documentation:

from langchain.vectorstores.neo4j_vector import Neo4jVector

ModuleNotFoundError: No module named 'langchain.vectorstores.neo4j_vector'

### Idea or request for content:

The existing documentation for the Neo4J Vector Index incorrectly indicates the use of "Neo4jVector" from the "langchain.vectorstores" module. However, it appears that there is no implementation of "Neo4jVector" within the Vector stores.
community:qianfan endpoint support init params & remove useless params definition
Labels: name: lgtm, name: area: embeddings, name: auto:improvement, name: size:M

  - **Description:**
    - support custom kwargs in object initialization. For instantance, QPS differs from multiple object(chat/completion/embedding with diverse models), for which global env is not a good choice for configuration.
  - **Issue:** no
  - **Dependencies:** no
  - **Twitter handle:** no

@baskaryan PTAL
docs(ollama): Fix Documentation in `CallbackManager`, missing `])`
Labels: name: lgtm, name: area: doc loader, name: auto:documentation, name: size:XS

  - **Description:** This PR corrects a documentation error in the `ollama` usage tutorial. Specifically, it fixes a missing `])` in the `CallbackManager()` example, ensuring that the code snippet is syntactically correct and can be successfully executed.
  - **Issue:** N/A
  - **Dependencies:** No additional dependencies are required for this change.
  - **Twitter handle:** My twitter is @yhzhu99
Update LLaMA2_sql_chat.ipynb
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:XS

Updated prompt input suggestions

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

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,
  - **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` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Update Multi_modal_RAG.ipynb
Labels: name: lgtm, name: area: doc loader, name: auto:documentation, name: size:XS

Updated comment for better understanding

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

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,
  - **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` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
[MongoDB] Async Support for Vector Store 
Labels: name: area: vector store, name: auto:enhancement

### Feature request

To add Async Client support to MongoDB Vector Stores

### Motivation

Currently, Langhain works very well with the PyMongo Client but not with the Async Clients like Motor it throws error, probably I hope it may not be implemented yet? 

Reference: 
PyMongo Working Docs - https://python.langchain.com/docs/integrations/vectorstores/mongodb_atlas
Async Error in Colab - https://colab.research.google.com/drive/1uBfiqoRH6rfiCCXhbxYlNxfc9ILizecl?usp=sharing

### Your contribution

I am not sure.
mistralai[patch]: warn on stop token, fix on_llm_new_token
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:M, name: partner

## Description
First, thanks for adding Mistral AI support to LangChain. I started to use it in my application and found that async LLM calls — both for streaming and generation — led to `Unclosed connector` warnings when executed twice or more. In `acompletion_with_retry` the Mistral AI client gets instantiated over and over again without being closed.

To achieve this for both generation and streaming, I've introduced a client manager. The `ClientManager` class inherits from `AsyncCallbackHabdler` and is therefore ready to detect the end of a stream to close the client. And it's a container for client handling in case of not streamed generation.

Besides this feature, I fixed two little bugs:
1. The `stop` parameter is not yet implemented in the API, or am I missing something? I thought it makes sense to keep `_create_message_dicts` and log a warning because support may be added in the future?
2. I completed the call to `on_llm_new_token`, since the library I am currently using relies on it.

What do you think? Looking forward to your feedback.

## Issue
* https://github.com/langchain-ai/langchain/issues/15269

## Dependencies
No dependencies required for this change

## Integration Tests
Executing integration tests on the `master` branch shows multiple `Unclosed connector` warnings. **These are gone when integration tests are executed on this feature branch**. So, IMHO, there is no need to add extra tests here.

✅ `MISTRAL_API_KEY=XYZ make integration_tests` passes

## Misc
**Twitter handle:** @aisneaks

✅ `make format` passes
✅ `make lint` passes
✅ `make test` passes
Playwright Utilities Removed In 0.0.353, Documentation Not Updated
Labels: name: auto:bug, name: area: langserve

### System Info

Langchain Version: 0.0.353

### Who can help?

_No response_

### 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
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. Update to 0.0.353
2. Try to import create_async_playwright_browser
3. Get error

### Expected behavior

1. No Error ;D


I can tell that the import was supported as recently as 0.0.350
ValueError: 'lib/python3.11/site-packages/langchain/agents/agent_toolkits' is not in the subpath of 'lib/python3.11/site-packages/langchain_core' OR one path is relative and the other is absolute.
Labels: name: area: agent, name: auto:bug

### System Info

MacOS 14.0, Jupiter with Python 3.11.6

 (base) ➜  llm-env pip show langchain    
Name: langchain
Version: 0.0.353
Summary: Building applications with LLMs through composability
Home-page: https://github.com/langchain-ai/langchain
Author: 
Author-email: 
License: MIT
Location: /lib/python3.11/site-packages
Requires: aiohttp, dataclasses-json, jsonpatch, langchain-community, langchain-core, langsmith, numpy, pydantic, PyYAML, requests, SQLAlchemy, tenacity


### Who can help?

_No response_

### 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
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

when try to execute,
from langchain.agents.agent_toolkits import create_python_agent
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType
from langchain.tools.python.tool import PythonREPLTool
from langchain.python import PythonREPL

Jupiter gave an error:
ValueError: 'lib/python3.11/site-packages/langchain/agents/agent_toolkits' is not in the subpath of 'lib/python3.11/site-packages/langchain_core' OR one path is relative and the other is absolute.


### Expected behavior

Import agent related thing correctly.
refactor `langchain.prompts.example_selector`
Labels: name: auto:refactor, name: area: models, name: size:L

The `langchain.prompts.example_selector` [still holds several artifacts](https://api.python.langchain.com/en/latest/langchain_api_reference.html#module-langchain.prompts) that belongs to `community`. If they moved to `langchain_community.example_selectors`, the `langchain.prompts` namespace would be effectively removed which is great.
- moved a class and afunction to `langchain_community`

Note:
- Previously, the `langchain.prompts.example_selector` artifacts were moved into the `langchain_core.exampe_selectors`. See the flattened namespace (`.prompts` was removed)!
Similar flattening was implemented for the `langchain_core` as the `langchain_core.exampe_selectors`.
refactor `tools`
Labels: name: auto:refactor, name: area: models, name: size:L

The `langchain` [still holds several artifacts](https://api.python.langchain.com/en/latest/langchain_api_reference.html#module-langchain.tools) that belongs to `core`. If they moved then `langchain.tools` would be split between `core` and `community` (no `langchain` artifacts), which is nice. It effectively removes the `langchain.tools` namespace.
- moved a class and functions to `core`
docs: revamp redirects
Labels: name: area: doc loader, name: auto:documentation, name: size:L

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

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,
  - **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` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Ability to set ollama serve url
Labels: name: auto:improvement, name: area: langserve

### Feature request

The ollama integration assumes that all models are served on "localhost:11434",  if the ollama service is hosted on a different machine, the integration will fail. 

Can we add an environment variable that if present overrides this url, so the correct url for the ollama server can be set. 

### Motivation

In My setup ollama sits on a separate machine that is resourced for serving  LLMs. 

### Your contribution

I'm afraid I don't have any knowledge of python, go, cpp and rust only.
Docs: Fix spelling and grammar on Concepts page
Labels: name: lgtm, name: area: doc loader, name: auto:documentation, name: size:XS

  - **Description:**  Fix a few spelling and grammar issues
  - **Issue:** NA
  - **Dependencies:** NA
  - **Twitter handle:** @donovancmuller
 
<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

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,
  - **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` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
ImportError: cannot import name 'GPT4ALL' from 'langchain.llms'
Labels: name: auto:bug, name: area: models

### System Info

langchain 0.0.353
pygpt4all 1.1.0

### 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

from langchain.llms import GPT4ALL, LlamaCpp

### Expected behavior

ImportError: cannot import name 'GPT4ALL' from 'langchain.llms' (/home/rkuo/.local/lib/python3.10/site-packages/langchain/llms/__init__.py)
SQLDatabase returns result without column names.
Labels: name: auto:bug, name: area: langserve

### System Info

Python 3.9
LangChain 0.0.339

### 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
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I created new instance of SQLDatabase and executed SQL queries using the 'run' method.
The problem is that when I execute a simple SELECT query the result returns without the column names, only the values, and therefore I can't tell which value relates to which column.

I saw in the implementation the following code in the 'run' method:
```
result = self._execute(command, fetch)
        # Convert columns values to string to avoid issues with sqlalchemy
        # truncating text
        res = [
            tuple(truncate_word(c, length=self._max_string_length) for c in r.values())
            for r in result
        ]
```

and I'm wondering if this data manipulation is done by intention or maybe it's a bug.

### Expected behavior

For example:
executes the following SQL: select id, count(*) as num_count from some_table
expected result: [{'id': 383, 'num_count': 10}]
actual result: [(383, 10)]