delayedkarma/langchain-issues huggingface dataset:
Issue: ReduceDocumentsChain may loop for many iterations
Labels: name: auto:bug, name: auto:improvement

### Issue you'd like to raise.

https://github.com/langchain-ai/langchain/blob/ebe08412ad1649c33501cc80edffbb908cc0157e/libs/langchain/langchain/chains/combine_documents/reduce.py#L247

In this loop:
```
while num_tokens is not None and num_tokens > _token_max:
            new_result_doc_list = _split_list_of_docs(
                result_docs, length_func, _token_max, **kwargs
            )
            result_docs = []
            for docs in new_result_doc_list:
                new_doc = _collapse_docs(docs, _collapse_docs_func, **kwargs)
                result_docs.append(new_doc)
            num_tokens = length_func(result_docs, **kwargs)
```
If num_tokens does not decrease, or decrease very slow, the loop will run a lot of iterations, which takes too much time, as well as high LLM api cost.

Besides, the comment "Combine multiple documents recursively" is misleading. The method is iteration actually, not recursion. 

### Suggestion:

I come up with one solution, if num_tokens decrease less than 10% after one iteration, truncate each doc of result_docs to 90% of original length. If you agree with my proposal, I would like to implement this and submit a pull request.
langchain.chat_models import fails
Labels: name: auto:bug, name: area: models

### System Info

Langchain: 0.0.81
Python: 3.11.5
System: Ubuntu

Trying to install Langchain and run the basic Quick Start sample code. Importing langchain.chat_models thows a ModuleNotFoundError.

```
$ python3
Python 3.11.5 (main, Aug 25 2023, 07:43:52) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from langchain.llms import OpenAI
>>> from langchain.chat_models import ChatOpenAI
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'langchain.chat_models'
```

Any suggestions?

### Who can help?

_No response_

### Information

- [X] 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

Steps to reproduce:

1. pip install langchain[all]
2. run python3 REPL
3. try to import langchain.chat_models

### Expected behavior

chat_models import succeeds.
Issue with GooglePalm class.
Labels: name: auto:bug, name: area: models

### System Info

Getting errors while using GooglePalm class. Have a look at the error below.

  File "/opt/conda/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/home/jupyter/vertexai-pocs-in-python/contact-centre/palm2-contact-centre-automation.py", line 114, in <module>
    result = display_row(selected_enquery)
  File "/home/jupyter/vertexai-pocs-in-python/contact-centre/palm2-contact-centre-automation.py", line 100, in display_row
    return overall_chain(customer_enquery)
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/base.py", line 243, in __call__
    raise e
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/base.py", line 237, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/sequential.py", line 105, in _call
    outputs = chain(known_values, return_only_outputs=True, callbacks=callbacks)
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/base.py", line 243, in __call__
    raise e
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/base.py", line 237, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/llm.py", line 93, in _call
    return self.create_outputs(response)[0]
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/llm.py", line 217, in create_outputs
    result = [
  File "/opt/conda/lib/python3.10/site-packages/langchain/chains/llm.py", line 220, in <listcomp>
    self.output_key: self.output_parser.parse_result(generation),
  File "/opt/conda/lib/python3.10/site-packages/langchain/schema/output_parser.py", line 69, in parse_result
    return self.parse(result[0].text)
IndexError: list index out of range

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

using LLM chain

### Expected behavior

The error is not coming with other LLM classes.
Error get_num_tokens_from_messages() with gpt-3.5-turbo-0613
Labels: name: area: memory, name: auto:bug, name: area: models

### System Info

Windows(server on linux), python, poetry

### Who can help?

@hwchase17
@agola11

### Information

- [X] 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
- [X] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Langchain has problems with working with model casts
```
 File "C:\Users\zabre\PycharmProjects\sales-bot\bot\src\sales_bot\text_handler.py", line 445, in get_response
    memory.prune()
  File "C:\Users\zabre\AppData\Local\pypoetry\Cache\virtualenvs\sales-bot-f2_0xw7_-py3.11\Lib\site-packages\langchain\memory\summary_buffer.py", line 65, in prune
    curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zabre\AppData\Local\pypoetry\Cache\virtualenvs\sales-bot-f2_0xw7_-py3.11\Lib\site-packages\langchain\chat_models\openai.py", line 420, in get_num_tokens_from_messages
    raise NotImplementedError(
NotImplementedError: get_num_tokens_from_messages() is not presently implemented for model gpt-3.5-turbo-0613.See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.
```
For example, when working with gpt-3.5-turbo-0613, he is not able to count the number of tokens, because the moment of checking the model is hard-coded
Please correct the following in def get_num_tokens_from_messages(langchain\chat_models\openai.py)":
```
        if model == "gpt-3.5-turbo":
            # gpt-3.5-turbo may change over time.
            # Returning num tokens assuming gpt-3.5-turbo-0301.
            model = "gpt-3.5-turbo-0301"
        elif model == "gpt-4":
            # gpt-4 may change over time.
            # Returning num tokens assuming gpt-4-0314.
            model = "gpt-4-0314"
```
Replase:
```
        if "gpt-3.5-turbo" in model:
            # gpt-3.5-turbo may change over time.
            # Returning num tokens assuming gpt-3.5-turbo-0301.
            model = "gpt-3.5-turbo-0301"
        elif "gpt-4" in model:
            # gpt-4 may change over time.
            # Returning num tokens assuming gpt-4-0314.
            model = "gpt-4-0314"
```

### Expected behavior

Sorry, because the project is closed, there is no way to provide sources, but the problem arises when using blind models and when calculating the number of tokens

```
memory = ConversationSummaryBufferMemory(
    llm=self.analyse_llm,
    ai_prefix="1",
    human_prefix="2",
    max_token_limit=self.max_memory_token_limit,
)

#  loaded old memory, and check length with prune causes an error

memory.prune()
```
ReAct agent support using Google PaLM 2
Labels: name: area: agent, name: auto:question, name: auto:enhancement, name: area: models

### Feature request

Hi Team,

I'm not sure if this is possible: ReAct agent support using Google PaLM 2. 
Now, when using PaLM 2 as the supporting model for ReAct agent, as following code:

```python
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.chat_models import ChatOpenAI

# First, let's load the language model we're going to use to control the agent.
llm = ChatOpenAI(model_name='google/palm-2-chat-bison', temperature=0,
                             openai_api_key='...',
                             openai_api_base='https://...')

# Next, let's load some tools to use. Note that the `llm-math` tool uses an LLM, so we need to pass that in.
tools = load_tools(["llm-math"], llm=llm)

# Finally, let's initialize an agent with the tools, the language model, and the type of agent we want to use.
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)

# Now let's test it out!
agent.run("What is the result of 1+3")
```

An error will occur：
```
OutputParserException: Parsing LLM output produced both a final answer and a parse-able action:: I need to use the calculator to answer this question
Action: Calculator
Action Input: 1+3
Observation: 4
Thought: I now know the final answer
Final Answer: 4
```

It looks like PaLM doesn't understand the prompt requirement of using the tool and waiting for the result.
Are there any solutions to this problem so far? Or is PaLM unable to implement this function?

### Motivation

We need to build a smart scheduler based on PaLM 2.

### Your contribution

If there is no ready-made solution in LangChain, I will try to see if I can use PaLM's dialogue capabilities to achieve this requirement. I also hope to get your feedback and judge whether this is feasible based on experience.
fix the Loader 'BiliBiliLoader' 
Labels: name: area: doc loader, name: auto:bug

  - **Description:** fix the Loader 'BiliBiliLoader' and it's doc
  - **Issue:** Due to recent modifications in Bilibili's API regulations, it is now imperative to include credentials when making a request to obtain subtitles.
Furthermore, it is important to note that not all videos will necessarily have associated subtitles.
As a result, I have revised the logic for acquiring subtitles. Presently, in the absence of credentials, the response will include the video's title and description, with subtitles only retrieved if valid credentials are provided.
And I also changed the doc,adding how to get and provide the credential.
  - **Dependencies:** Nope
Implement llm stream api of Alibaba Tongyi model.
Labels: name: auto:enhancement, name: area: models

Hi there
This PR is aim to refactor and implement new api for Alibaba Tongyi LLM model. It contains work below: 
1. Implements langchain.llms.Tonyi stream call function.
2. Remove the _call() function as it is deprecated.
3. Add more code examples in tongyi.ipynb. One case for users who need to to use different model with Tongyi.
One case for streaming response call and with callbacks.

Note async completion for the Text API is not yet supported.
Dependencies: dashscope. It will be installed manually cause it is not need by everyone.

Happy for feedback on any aspect of this PR @hwchase17  @baskaryan.
choose to prepend an index of page_content in retriever
Labels: name: area: vector store, name: auto:improvement


- **Description:** Allow users to prepend each document in the result with its index number by setting the add_index parameter to True in VectorStoreRetiever(), then it's much easier for QA inline citation, 
- **Issue:** #7239,
- **Dependencies:** No dependencies required for this change,
- **Tag maintainer:** @baskaryan,
- **Twitter handle:**
Issue: How to set the language (default is English) when using UnstructuredImageLoader with PaddleOCR
Labels: name: area: doc loader, name: auto:question

### Issue you'd like to raise.

I am using langchain.document_loaders.image.UnstructuredImageLoader to load data from an image with a table on it. I chose PaddleOCR by setting os.environ["TABLE_OCR"] = "paddle" . However, I didn't find a place to set the detection language to other language. Could you please let me know how to do it. I have gotten stuck on it for a while.

### Suggestion:

_No response_
Python - Stop generate response functionality 
Labels: name: auto:enhancement, name: area: models

### Feature request

First of all BIG thanks for the working you are doing guys!!!
It will be nice if you can add a stop generate response implementation.

### Motivation

I'm always frustrated when I need to wait until the final response returned and then ask new question.
Sometimes my chatbot sending long JSON response that takes 55sec end-to-end it will be nice if I could stop it manually. 

### Your contribution

No
Upstash redis integration
Labels: name: area: memory, name: lgtm, name: auto:enhancement, name: integration: redis

  - **Description:** Introduced Upstash provider with following wrappers: UpstashRedisCache, UpstashRedisEntityStore, UpstashRedisChatMessageHistory, UpstashRedisStore 
  - **Issue:** -,
  - **Dependencies:** upstash-redis python package is needed,
  - **Tag maintainer:** @baskaryan 
  - **Twitter handle:** @BurakY744
Fix chat_history message order
Labels: name: area: memory, name: auto:improvement

Not all databases uses id as default order, so add it explicitly

sqlite uses rawid as default order in select statement: [https://www.sqlite.org/lang_createtable.html#rowid](https://www.sqlite.org/lang_createtable.html#rowid), but some other databases like postgresql not behaves like this. since this class supports multiple db engine. we should have an order.
implement async exec for base.py
Labels: name: auto:improvement

This is my implementation of async exec. This code is similar to the synchronous version, but it uses async and await to make it asynchronous. To use this asynchronous version of _acall, we can simply call it with the async keyword: `output = await chain.acall(inputs)`

<!-- 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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Adding a connector for CogniSwitch.ai
Labels: name: area: doc loader, name: auto:enhancement, name: size:XL


  - **Description:** CogniSwitch focusses on making GenAI usage more reliable. It abstracts out the complexity & decision making required for tuning processing, storage & retrieval. Using simple APIs documents / URLs can be processed into a Knowledge Graph that can then be used to answer questions.
  - **Dependencies:** No dependencies. Just network calls & API key required
  - **Tag maintainer:** @hwchase17
  - **Twitter handle:** @CogniSwitch
  - **Documentation:** Please check `docs/extras/use_cases/cogniswitch_chain_usage.ipynb`
  - **Tests:** Unit tests added within chains/ `test_cogniswitch_store` & `test_cogniswitch_answer` 
 
PR has passed linting and testing before this submission.
redirect platform to provider
Labels: name: auto:documentation

<!-- 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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Issue: running integration tests
Labels: name: auto:bug, name: auto:documentation

### integration tests.

I have tried to follow the readme in langchain/tests to run the integration tests but got these errors : 

`ModuleNotFoundError: No module named 'qdrant_client'`

Using poetry with python version = 3.10

I already tried the `poetry install` and` poetry install --with test_integration` but does't helped. The readme seems don't have much information around this and couldn't find any document that what is guideline to run the integration tests.
The unit tests are running fine.
Is it maybe something wrong with my env or I might missing a step before running integration tests? 

### Suggestion:

_No response_
ValueError: The following `model_kwargs` are not used by the model while running Microsoft/Phi-1.5 using HuggingFacePipeline 
Labels: name: auto:bug, name: area: models

### System Info

Python                      3.9.18
langchain                 0.0.292
transformers            4.33.2
torch                         2.0.1
os                              macOs Ventura 13.5.2

### Who can help?

_No response_

### 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
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from transformers import pipeline
from langchain import PromptTemplate
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
from langchain.chains import LLMChain

model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5",
                                             trust_remote_code=True)

tokenizer = AutoTokenizer.from_pretrained(
    "microsoft/phi-1_5", trust_remote_code=True, use_cache=True, return_attention_mask=False)

question = "Who won the FIFA World Cup in the year 1994? "

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

# llm_pipeline = HuggingFacePipeline(pipeline=generate)

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
llm_pipeline = HuggingFacePipeline(pipeline=pipe)
generator_chain = LLMChain(llm=llm_pipeline, prompt=prompt)
generator_outputs = generator_chain.run(question)

print(generator_outputs)
```

ValueError: The following `model_kwargs` are not used by the model: ['attention_mask'] (note: typos in the generate arguments will also show up in this list)

### Expected behavior

Return the response from the model
doc: update the openai_function_agent document
Labels: name: area: doc loader, name: auto:documentation

  - **Description:** This pull request updates the openai_function_agent document. The update enhances the document in three significant ways:
    - Firstly, it eliminates imports that lead to import errors such as `langchain_experimental`.
    - Secondly, it initializes the agent by directly calling the `OpenAIFunctionsAgent`, instead of using the less intuitive `initialize_agent`.
    - Lastly, it substitutes the tools with those that don't require additional external services, simplifying the process for users to reproduce the notebook.
  - **Tag maintainer:** @baskaryan
Installing from source (pip install -e .) fails with multiple top-level packags found
Labels: name: auto:bug

### System Info

Linux, Python 3.11.5

### 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
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. `python -m venv .venv`
2. `. .venv/bin/activate`
3. `pip install -e .`

### Expected behavior

To install package in a local virtualenv.

What happens:
```
% pip install -e .  
Obtaining file:///home/iskren/src/deepinfra/libs/langchain
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build editable did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      error: Multiple top-level packages discovered in a flat-layout: ['libs', 'langchain'].
      
      To avoid accidental inclusion of unwanted files or directories,
      setuptools will not proceed with this build.
      
      If you are trying to create a single distribution with multiple packages
      on purpose, you should not rely on automatic discovery.
      Instead, consider the following options:
      
      1. set up custom discovery (`find` directive with `include` or `exclude`)
      2. use a `src-layout`
      3. explicitly set `py_modules` or `packages` with a list of names
      
      To find more information, look for "package discovery" on setuptools docs.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
```
Directory loader does not extract text between <strong> </strong> tags in HTML
Labels: name: area: doc loader, name: auto:bug

### System Info

LANGCHAIN - 0.0.0286
OS - Windows

### Who can help?

@eyurtsev

### Information

- [ ] 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
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

To reproduce, take a HTML document that has text between STRONG tags of HTML tags and extract using directoryloader

### Expected behavior

It should extract all the text from HTML