delayedkarma/langchain-issues huggingface dataset:
Confused behavior of CharacterTextSplitter with regex
Labels: name: area: doc loader, name: auto:bug

### System Info

langchain=0.0.294
python=3.10

### Who can help?

@hwchase17  @agola11 

### 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
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
loader = TextLoader("state_of_the_union.txt")
documents = loader.load()

pattern = "\.|,|\n\n"
text_splitter = CharacterTextSplitter(separator=pattern, is_separator_regex=True,
                                      chunk_size=100, chunk_overlap=0,
                                      keep_separator=False)
docs = text_splitter.split_documents(documents)

for doc in docs:
    print(doc.page_content)
```
the output would be
```
'Madam Speaker\\.|,|\n\n Madam Vice President\\.|,|\n\n our First Lady and Second Gentleman'
'Members of Congress and the Cabinet\\.|,|\n\n Justices of the Supreme Court\\.|,|\n\n My fellow Americans'
'\\.|,|\n\nLast year COVID-19 kept us apart\\.|,|\n\n This year we are finally together again\\.|,|'
```
which includes my regex expression. I even set keep_seperator=False.

with keep_seperator=True, the seperator become the leading character, which is still stange.
```
'Madam Speaker, Madam Vice President, our First Lady and Second Gentleman'
'. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans.'
'Last year COVID-19 kept us apart. This year we are finally together again.'
```

### Expected behavior

```
'Madam Speaker, Madam Vice President, our First Lady and Second Gentleman.'
'Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans.'
'Last year COVID-19 kept us apart. This year we are finally together again.'
```
Fix PyMUPDFLoader kwargs
Labels: name: area: doc loader, name: auto:bug

- **Description:**  Fix the `PyMuPDFLoader` to accept `loader_kwargs` from the document loader's `loader_kwargs` option. This provides more flexibility in formatting the output documents.

- **Issue:**  The `loader_kwargs` is not passed into the `load` method from the document loader, which limits configuration options.

- **Dependencies:**  None
below code is not able to show grpahs at frontend , rather it returns code ,
Labels: name: area: agent, name: auto:bug, name: area: models

### Discussed in https://github.com/langchain-ai/langchain/discussions/10835

<div type='discussions-op-text'>

<sup>Originally posted by **astro-siddhesh** September 20, 2023</sup>
import pandas as pd
import streamlit as st
from langchain.chat_models import ChatOpenAI
from langchain.agents.agent_toolkits import create_pandas_dataframe_agent
from langchain.agents.agent_types import AgentType

df = pd.read_csv('/Users/siddheshphapale/Desktop/project/sqlcsv.csv')


llm = ChatOpenAI(openai_api_key= "my key" , temperature=0 ,max_tokens= 500 , verbose= False)
agent = create_pandas_dataframe_agent(llm, df, agent_type=AgentType.OPENAI_FUNCTIONS)


from langsmith import Client
client = Client()
def send_feedback(run_id, score):
    client.create_feedback(run_id, "user_score", score=score)

st.set_page_config(page_title='🦜🔗 Ask the CSV App')
st.title('🦜🔗 Ask the CSV App')
query_text = st.text_input('Enter your question:', placeholder = 'Who was in cabin C128?')
# Form input and query
result = None
with st.form('myform', clear_on_submit=True):
	submitted = st.form_submit_button('Submit')
	if submitted:
		with st.spinner('Calculating...'):
			response = agent({"input": query_text}, include_run_info=True)
			result = response["output"]
			run_id = response["__run"].run_id
if result is not None:
	st.info(result)
	col_blank, col_text, col1, col2 = st.columns([10, 2,1,1])
	with col_text:
		st.text("Feedback:")
	with col1:
		st.button("👍", on_click=send_feedback, args=(run_id, 1))
	with col2:
		st.button("👎", on_click=send_feedback, args=(run_id, 0))

<img width="600" alt="Screenshot 2023-09-20 at 5 21 38 PM" src="https://github.com/langchain-ai/langchain/assets/118797304/536155f7-fb12-4fa2-8dc8-80aea70e7389">
</div>
PyPDF2 used in Google Drive loader has vulnerability issues
Labels: name: area: doc loader, name: auto:bug

### System Info

The GoogleDrive loader currently uses the PyPDF2 library instead of the PyPDF. 
Since PyPDF2 was already merged to the original one, it shouldn't be used anymore. 
[https://data.safetycli.com/v/59234/f17/?utm_source=pyupio&utm_medium=redirect&utm_campaign=pyup_rd&utm_id=081](url)
This is the vulnerability issue that gets picked up, note that it is fixed in PyPDF

Also I tried to change the loader using `file_loader_cls` but it just doesn't work 


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

### Reproduction

No functionality issue but https://data.safetycli.com/v/59234/f17/?utm_source=pyupio&utm_medium=redirect&utm_campaign=pyup_rd&utm_id=0817&utm_content=data showcases the bug

### Expected behavior

This error should not pop up
Issue: use QianfanChatEndpoint and RetrievalQA Error
Labels: name: auto:bug, name: auto:question, name: stale, name: area: models, name: integration: chroma

### Issue you'd like to raise.

`
llm = QianfanChatEndpoint(
    model="ChatGLM2-6B-32K",
    qianfan_ak="xxx",
    qianfan_sk="xxx"
)

embedding = ErnieEmbeddings(
  qianfan_ak="xxx",
  qianfan_sk="xxx"
)
db = Chroma.from_documents(texts, embedding)
retriever = db.as_retriever()

qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)

qa.run("请问事项的名称是什么？")
`

an error occurred in the above code.

`
File "/Users/xxx/Workspace/xxx/smart_gov_nav/chatbot/venv/lib/python3.11/site-packages/langchain/chat_models/baidu_qianfan_endpoint.py", line 63, in convert_message_to_dict
    raise TypeError(f"Got unknown type {message}")
TypeError: Got unknown type content="Use the following pieces of context to answer the users question. \nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\n办事大厅名称\n " additional_kwargs={}
`

Because the type of message in the convert_message_to_dict argument is SystemMessage. That's why this error occurred. How to use it correctly?
 

### Suggestion:

_No response_
Refactor(ernie): support function_call, reimplment ernie_bot with erniebot SDK.
Labels: name: auto:refactor, name: area: models

- **Description:** 
    * Introducing the [ERNIE-Bot SDK](https://github.com/PaddlePaddle/ERNIE-Bot-SDK) to refactor the current implementation of Ernie in Langchain
    * Rename ernie.py -> ernie_bot. py, because the usage of `xx-bot` models is only for chat completion generation.
    * Support Function Calling capability in chat_models/ernie_bot.py
    * Add ipynb and test  
- **Issue:** no
- **Dependencies:** no
- **Tag maintainer:** @baskaryan 
- **Twitter handle:** no
Title：fixed a bug that was causing the streaming transfer to not work…
Labels: name: auto:bug, name: area: models, name: size:L

… properly

Fixed a bug that was causing the streaming transfer to not work properly.
 - **Description: 
    1、The on_llm_new_token method in the streaming callback can now be called properly in streaming transfer mode. 
    2、In streaming transfer mode, LLM can now correctly output the complete response instead of just the first token.
- **Tag maintainer: @wangxuqi 
- **Twitter handle: @kGX7XJjuYxzX9Km
Add ConversationBufferMemory to ConversationalRetrievalChain
Labels: name: area: memory, name: auto:improvement

This should help to add memory buffer directly when create ConversationalRetrievalChain from_llm

<!-- 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.
 -->
Use shallow copy on runnable locals
Labels: name: auto:improvement

- deep copy prevents storing complex objects in locals

<!-- 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.
 -->
MongoDBAtlasVectorSearch: Make It Work with Existing MongoDB Collection (rather than having to create a new one)
Labels: name: area: vector store, name: auto:improvement

### Feature request

When using MongoDBAtlasVectorSearch, the user is limited to only first populate a MongoDB collection of documents using either add_document or add_text methods. Those methods create documents on the given collection using a fixed structure. What if the user already has a collection on MongoDB with custom structure (still containing the field 'embedding' which is used to measure similarity)? This is not currently supported and the user would have to implement a wrapper around MongoDBAtlasVectorSearch to achieve that. 

For instance the following code won't work (docs will be empty):
```
from langchain.vectorstores import MongoDBAtlasVectorSearch
from langchain.embeddings import HuggingFaceEmbeddings

embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
index_name = "index_name_from_MongoDB"

docsearch = MongoDBAtlasVectorSearch(embeddings, collection=collection, index_name=index_name)

query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)

print(docs[0].page_content)
```
This is because the collection is not populated using any of the original methods of MongoDBAtlasVectorSearch, e.g. add_document or add_text, hence the structure of the collection might be different (containing additional fields and missing the 'text' field for example).
Further Enhancement to WeaviateHybridSearchRetriever
Labels: name: auto:improvement, name: area: models

**Description:**
Upon working with the retriever further, I realized that when it is used in an existing chain, you don’t directly call `get_relevant_documents()`. This makes it challenging to pass the `hybrid_search_kwargs` to the underly function.

To address this, I’ve introduced a minor patch in this commit. By adding `hybrid_search_kwargs` as a class variable, we can now handle a wider range of realistic use cases without conflicting with the previously pushed version.

Here is a simple example:
```python
retreiver = WeaviateHybridSearchRetriever(
    client=client,
    index_name="Document",
    text_key="content",
    hybrid_search_kwargs={"properties": ["title", "summary", "content"]}, 
)

llm = OpenAI()
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm,retriever=retreiver)

# When called within conversation_chain invocation
def _get_relevant_documents(self, ...):
    ...
    # Prioritizes function argument, then class var, finally empty {}
    if hybrid_search_kwargs is None:
        hybrid_search_kwargs = self.hybrid_search_kwargs or {}  
    ...

```

**Tag maintainer:**
@hwchase17
Update search.py
Labels: name: auto:nit

changed return type from string to List

continuation of the closed PR 
https://github.com/langchain-ai/langchain/pull/10743#discussion_r1330806902

<!-- 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.
 -->
SeleniumURLLoader load asynchronous js, need wait
Labels: name: area: doc loader, name: auto:improvement

### System Info

Mac OS ventura 13.4.1

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

langchain/document_loaders/url_selenium.py                
def load(self) -> List[Document]:
        """Load the specified URLs using Selenium and create Document instances.

        Returns:
            List[Document]: A list of Document instances with loaded content.
        """
        from unstructured.partition.html import partition_html

        docs: List[Document] = list()
        driver = self._get_driver()

        for url in self.urls:
            try:
                driver.get(url)
                sleep(30)   // need wait
                page_content = driver.page_source
                elements = partition_html(text=page_content)
                text = "\n\n".join([str(el) for el in elements])
                metadata = {"source": url}
                docs.append(Document(page_content=text, metadata=metadata))
            except Exception as e:
                if self.continue_on_failure:
                    logger.error(f"Error fetching or processing {url}, exception: {e}")
                else:
                    raise e

        driver.quit()
        return docs


### Expected behavior

timer is config parms, user can use 
SeleniumURLLoader({waittime: 30})
Update base.py
Labels: name: area: agent, name: auto:nit

as per definition, `include_df_in_prompt` should either be true or false

<!-- 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:** None
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** 

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
set litellm max_tokens=None
Labels: name: auto:improvement, name: area: models

  - **Description:** The default value of the `max_tokens` for litellm is 256. It should be increased to avoid truncation of replies.

<!-- 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.
 -->
SQLAgent fails to connect to Postgres multiple schemas
Labels: name: area: agent, name: auto:bug

### System Info

I'm using latest langchain version 0.0.295.  It turns out langchain SQLAgent always connects to Postgres public schema.  I need SQLAgent to check all schemas to generate SQL query.  How to configure SQLAgent to connect to all Postgres schemas?

Tried both pg_uri = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}?currentSchema=myschema",  pg_uri = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}?search_path=myschema" when creating SQLDatabase: db = SQLDatabase.from_uri(pg_uri).  It doesn't work. 
 

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

When creating SQLDatabase for postgres, I can't specify schema.  It only connects to postgres public schema.  As a result, SQLAgent doesn't produce meaningful result.

# pg_uri = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}?search_path=myschema"
pg_uri = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}?currentSchema=myschema"

db = SQLDatabase.from_uri(pg_uri)

### Expected behavior

Expect SQLAgent or SQLDatabase can configure schemas for Postgres so that SQLAgent can generate meaningful SQL query.
OpenAI class missing `predict` method as described in the Quickstart guide
Labels: name: auto:bug, name: auto:documentation, name: area: models

### Issue with current documentation:

While following the Quickstart guide in the LangChain documentation, I encountered an AttributeError when trying to use the `predict` method with an instance of the OpenAI class. It seems like the `predict` method is not available in the OpenAI class as described in the guide.


I'm running the following code from the Langchain Quickstart Guide, LLMs section:

```
from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI

llm = OpenAI()
chat_model = ChatOpenAI()

llm.predict("hi!")
>>> "Hi"

chat_model.predict("hi!")
>>> "Hi"
```

Below are the steps I took before running:

1. Installed LangChain using `pip install langchain`.
2. Installed OpenAI Python package using `pip install openai`.
3. Set up the OpenAI API key as described in the guide.
4. Created an instance of the OpenAI class and attempted to call the `predict` method with a string argument, as shown in the guide.

**Expected behavior:** Based on the Quickstart guide, I expected to be able to call the `predict` method with a string argument and receive a string as the output.

**Actual behavior:** When attempting to call the `predict` method, I received the following error message:

AttributeError: 'OpenAI' object has no attribute 'predict'

**Environment:**
- LangChain version: (0.0.112)
- OpenAI Python package version: (0.27.2)
- Python version: 3.9.5
- Operating System: macOS

I checked the available methods of the OpenAI class using the `dir()` function and confirmed that the `predict` method is not available. I also tried passing a list of strings to the `generate` method as an alternative, based on the methods that are available, but this did not produce the expected result.

### Idea or request for content:

_No response_
misc: add gpt-3.5-turbo-instruct to model_token_mapping
Labels: name: lgtm, name: auto:bug, name: area: models

A one-line fix to get`max_tokens=-1` working `OpenAI` class for `gpt-3.5-turbo-instruct` model. 

Closes https://github.com/langchain-ai/langchain/issues/10806
Error when using gpt-3.5-turbo-instruct: model_token_mapping is missing an entry for gpt-3.5-turbo-instruct
Labels: name: auto:bug, name: area: models

### System Info

LangChain version: 0.0.295 (just upgraded to this version to use gpt-3.5-turbo-instruct)

### Who can help?

@hwchase17 @agola

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

Minimal code to reproduce:

```python
# load OpenAI API Key
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.1, model_name="gpt-3.5-turbo-instruct", max_tokens=-1)
llm("give me a list of Chinese dishes and their recipes")
```

Error message:
>```ValueError: Unknown model: gpt-3.5-turbo-instruct. Please provide a valid OpenAI model name.Known models are: gpt-4, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0314, gpt-4-32k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k, gpt-3.5-turbo-16k-0613, text-ada-001, ada, text-babbage-001, babbage, text-curie-001, curie, davinci, text-davinci-003, text-davinci-002, code-davinci-002, code-davinci-001, code-cushman-002, code-cushman-001```

Cause of the error: looks like it's because the `model_token_mapping` is missing an entry for `gpt-3.5-turbo-instruct`: https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/llms/openai.py#L555

### Expected behavior

The code succeeds without error