delayedkarma/langchain-issues huggingface dataset:
Langchain ai master
Labels: name: auto:enhancement, 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.
 -->
CharacterTextSplitter inconsistent/wrong output using regex pattern
Labels: name: area: doc loader, name: auto:bug

### System Info

Langchain version 0.0.259
Ubuntu 20.04
Python 3.9.15

### Who can help?

@eyurtsev

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

### Reproduction

Using regex in the CharacterTextSplitter leads to a couple of unexpected behaviours. 
 1. When it merges the small chunks into larger chunks, it uses the separator, leading to outputs like those below (0, 2)
 2. This could be arguable, and personally I don't think it's so problematic. The number of splits could be different depending on whether `keep_separator` is True or False. (0, 1)

```python 
from langchain.text_splitter import CharacterTextSplitter
import string

char_chunk = string.ascii_uppercase[:5] # ABCDE
text = "\n\n".join([f"{k}\n\n{char_chunk}" for k in range(4)])

splitter = CharacterTextSplitter(chunk_size=20, chunk_overlap=0, separator="\n+[0-9]+\n+", is_separator_regex=True, keep_separator=False)
res_0 = splitter.split_text(text)
print(res_0) # ['0\n\nABCDE', 'ABCDE\n+[0-9]+\n+ABCDE', 'ABCDE']

splitter = CharacterTextSplitter(chunk_size=20, chunk_overlap=0, separator="\n+[0-9]+\n+", is_separator_regex=True, keep_separator=True)
res_1 = splitter.split_text(text)
print(res_1) # ['0\n\nABCDE\n\n1\n\nABCDE', '2\n\nABCDE\n\n3\n\nABCDE']
 
splitter = CharacterTextSplitter(chunk_size=20, chunk_overlap=0, separator="\n*[0-9]+\n*", is_separator_regex=True, keep_separator=False)
res_2 = splitter.split_text(text)
print(res_2) # ['ABCDE\n*[0-9]+\n*ABCDE', 'ABCDE\n*[0-9]+\n*ABCDE']

splitter = CharacterTextSplitter(chunk_size=20, chunk_overlap=0, separator="\n*[0-9]+\n*", is_separator_regex=True, keep_separator=True)
res_3 = splitter.split_text(text)
print(res_3) # ['0\n\nABCDE\n\n1\n\nABCDE', '2\n\nABCDE\n\n3\n\nABCDE']

```

### Expected behavior

1. Use the actual characters to merge the two chunks into a larger chunk instead of the regex sepatator. I.e:
```python
# ['0\n\nABCDE', 'ABCDE\n\n2\n\nABCDE', 'ABCDE']
``` 
2. Consistency among the number of splits in both cases of `keep_separator`
Being able to see model's responses when using verbose mode
Labels: name: auto:improvement, name: area: models

### Feature request

Currently, when the _verbose_ attribute is set to True in the constructor of an _LLMChain_ object, only the input passed to the LLM is shown. It would be desirable to also see the raw output of the LLM before it is parsed.

### Motivation

Seeing both inputs and outputs of the LLM would help debug the chain. Exceptions often occur when an output parser is used and the parser throws an exception (because the LLM's output was not in the expected format). In that case one cannot see what the LLM's output was.

### Your contribution

I had a look at the code of LLMChain and it seems that a print (or a callback) could be added in the _call method, between the call to _generate_ and the call to _create_outputs_:
```
    def _call(
        self,
        inputs: Dict[str, Any],
        run_manager: Optional[CallbackManagerForChainRun] = None,
    ) -> Dict[str, str]:
        response = self.generate([inputs], run_manager=run_manager)
        # Add a print/callback here
        return self.create_outputs(response)[0]
```
VLLM: Can't instantiate abstract class VLLM with abstract method _agenerate
Labels: name: auto:bug, name: auto:documentation, name: area: models

### System Info

**langchain 0.0.274:**
When trying to instantiate a VLLM object, I'm getting the following error:

**TypeError: Can't instantiate abstract class VLLM with abstract method _agenerate**

This is the code I'm using which is 1-1 as the VLLM example on langchain documentation:
https://python.langchain.com/docs/integrations/llms/vllm

```
from langchain.llms.vllm import VLLM

vlmm = VLLM(model="mosaicml/mpt-7b",
           trust_remote_code=True,  # mandatory for hf models
           max_new_tokens=128,
           top_k=10,
           top_p=0.95,
           temperature=0.8,
)
```

It seems that the VLLM model is derived from the BaseLLM object, which has an abstract method of _agenerate, but is not providing an implementation for it. 

In addition to that, you might notice that I used **from langchain.llms.vllm import VLLM** instead of from **langchain.llms import VLLM** as the documentation, that's because for from langchain.llms import VLLM I'm getting an "cannot import name 'VLLM' from 'langchain.llms'" error 

Any insights regarding this one? 

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

instantiate a VLLM object just like in the official documentation: https://python.langchain.com/docs/integrations/llms/vllm

### Expected behavior

The object should be created and load model successfully
DOC: Generative Agents Page In JS/TS but not Python
Labels: name: area: agent, name: area: doc loader, name: area: vector store, name: auto:documentation

### Issue with current documentation:

How come there is a generative agents page https://js.langchain.com/docs/use_cases/agent_simulations/generative_agents in JS, but not one in python? I was reading this [blog post](https://blog.langchain.dev/agents-round/) and the links to the generative_agents page didn't work. 

I also noticed [`MemoryVectorStore`](https://js.langchain.com/docs/api/vectorstores_memory/classes/MemoryVectorStore#methods) exists in the JS/TS docs but not in the python [`vectorstores`](https://[api.python.langchain.com/en/latest/module-langchain.vectorstores](https://api.python.langchain.com/en/latest/module-langchain.vectorstores)) doc. Why is that?

Thanks.
DOC: Add clarification to Modules/ModelsI/O/Prompts/Prompt Templates/Few-shot examples for chat models
Labels: name: auto:documentation, name: area: models

### Issue with current documentation:

In https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/few_shot_examples_chat under Dynamic few-shot prompting,

```
example_selector = SemanticSimilarityExampleSelector(
    vectorstore=vectorstore,
    k=2,
)

# The prompt template will load examples by passing the input do the `select_examples` method
example_selector.select_examples({"input": "horse"})
```

Does the key value "input" matter when calling select_examples? I was playing around with this and it doesn't seem to change the output. Maybe more clarification could be added to both `select_examples` in the API reference and in the doc examples.

---

![image](https://github.com/langchain-ai/langchain/assets/58043265/b4f7642a-32e7-41e8-b0a5-65087d025591)
"instruct" is misspelled.

---

```
from langchain.prompts import (
    FewShotChatMessagePromptTemplate,
    ChatPromptTemplate,
)

# Define the few-shot prompt.
few_shot_prompt = FewShotChatMessagePromptTemplate(
    # The input variables select the values to pass to the example_selector
    input_variables=["input"],
    example_selector=example_selector,
    # Define how each example will be formatted.
    # In this case, each example will become 2 messages:
    # 1 human, and 1 AI
    example_prompt=ChatPromptTemplate.from_messages(
        [("human", "{input}"), ("ai", "{output}")]
    ),
)
```

Also, is it possible to clarify `input_variables=["input"]` a bit more and how this works downstream in the `final_prompt`? I toyed with it a bit and found it a lil confusing to understand.

![image](https://github.com/langchain-ai/langchain/assets/58043265/98504eec-f6c5-4908-81a2-7c6c68469270)
_What I understood from playing around with the parameters._

![image](https://github.com/langchain-ai/langchain/assets/58043265/82e01f7b-e479-4d74-b762-abd6b12542e2)
_What I found out later._

Even after understanding how the variables worked here, I think a lot of the other cases weren't explained so I was still confused up till I started experimenting. Maybe more clarification can be added to this?

Thanks!
New chain to allow for logical fallacy removal of model output
Labels: name: auto:enhancement, name: area: models

Description: a new chain to test and remove logical fallacies from model output in a chain if found
Issue: n/a
Dependencies: none
Tag maintainer: @hinthornw helped me in the past, not sure if this PR falls outside any maintainer area but feel free to maintain if so
Twitter handle: not on twitter - tag my git handle if any shout out needed j-space-b

Note: added documentation to docs/extras
Logical fallacy removal
Labels: name: auto:enhancement, name: area: models

Description:  a new chain to output logical fallacies from model in a chain
Issue: fixes no existing issue other than this not yet existing 
Dependencies: none 
Tag maintainer: @hinthornw in the past for another area, not sure if this an area outside of maintenance
Twitter handle: not on twitter, feel free to tag my git user if any shout-outs: j-space-b

Note: a doc showing use of this chain is in docs/extras as apropos
Update web_scraping.ipynb
Labels: name: lgtm, 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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Logical fallacy removal
Labels: name: auto:enhancement, name: area: models

Description: a new chain to filter logical fallacies from 
Issue: does not fix an issue other than adding any needed logical fallacy filtering to an output from a base model within a chain
Dependencies: no dependencies 
Tag maintainer: have worked w @hinthornw in the past - not seeing tag on list, so more likely @baskaryan 
Twitter handle: Not on twitter/x feel free to ping my github if shout-out needed @j-space-b 

Note: added a doc of an example in docs/extras
feat(llms): improve ERNIE-Bot chat model
Labels: 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.
 -->
  - Description:  improve ERNIE-Bot chat model, add request timeout and more testcases.
  - Issue: None
  - Dependencies: None
  - Tag maintainer: @baskaryan
Fix add callbacks to spark_sql due to depreciation of callback_manager
Labels: name: area: agent, name: lgtm, name: auto:bug

Description: Due to depreciation (regarding to line 109 in [langchain/libs/langchain/langchain/chains/base.py](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/base.py) of callback_manager i replaced several parts

Issue: None
Dependencies: 
Maintainer: @baskaryan
Feature: PGVector Collection Documents Update
Labels: name: area: vector store, name: auto:improvement

## Description
Enhancement to the PGVector functionality: the addition of an update function `update_documents(...)`.

Currently, updating the documents of a collection requires emptying the collection and filling it again. This can cause more calls to be made to the model than are actually needed. In fact, if a text chunk (and therefore its embedding) is already present in the vector store in the current collection, what is currently done is to delete it and insert (therefore calling the embedding model) the same embedding again.

The new feature identifies differences between input and existing documents. It requests new embeddings only for different documents, inserting them into the DB, and deletes missing ones.

##  Issue
#9461 (Add Functionality to Update Embeddings in pgvector)

## Using Sample

```python
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores.pgvector import PGVector
from langchain.docstore.document import Document

COLLECTION_NAME = "..."
CONNECTION_STRING = '...'
documents = [Document(page_content="foo", metadata={"page": "0"}), 
             Document(page_content="bar", metadata={"page": "1"})]

# Instance new collection in pgvector from documents
pgvector = PGVector.from_documents(
    embedding=OpenAIEmbeddings(),
    documents=documents,
    collection_name=COLLECTION_NAME,
    connection_string=CONNECTION_STRING,
    pre_delete_collection=True)

# Update/Add some documents
documents[1].page_content = "baz"
documents.append(Document(page_content="far", metadata={"page": "2"}))

# Call update function
pgvector.update_documents(documents)
```
Extraction Chain - Custom Prompt
Labels: name: lgtm, name: auto:improvement

# Description

This change allows you to customize the prompt used in `create_extraction_chain` as well as `create_extraction_chain_pydantic`. 

It also adds the `verbose` argument to `create_extraction_chain_pydantic` - because `create_extraction_chain` had it already and `create_extraction_chain_pydantic` did not.

# Issue
N/A

# Dependencies
N/A

# Twitter
https://twitter.com/CamAHutchison
DOC: Import path for NewsURLLoader needs to fixed
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:

At https://python.langchain.com/docs/integrations/document_loaders/news, there is an issue with the path for importing `NewsURLLoader`. Currently, it's being imported from `from langchain.document_loaders`, but it gives `importerror`.

### Idea or request for content:

The import path for `NewsURLLoader` needs to be updated. The correct path is `from langchain.document_loaders.news import NewsURLLoader`
Issue: Help to make a callback for Elevenlabs API streaming endpoint
Labels: name: auto:question, name: area: models

Hi, 

I'm hoping someone smarter than me can help me understand how to write a callback that works with Elevenlabs.

I'm trying to get Elevenlabs to stream TTS based on a response from the GPT-4 API. I can do this easily using OpenAIs own libarary, but I cannot figure out how to do this using langchains callbacks instead. 

Here is the working code for the OpenAI library (without the various imports etc).



```
def write(prompt: str):
    for chunk in openai.ChatCompletion.create(
        model = "gpt-4",
        messages = [{"role":"user","content": prompt}],
        stream=True,
    ):
        content = chunk["choices"][0].get("delta", {}).get("content")
        if content is not None:
            yield content
            print("ContentTester:", content)

promtp = "Say a long sentence"

text_stream = write(wife)

audio_stream = elevenlabs.generate(
    text=text_stream,
    voice="adam",
    stream=True,
    latency=3,
)

output = elevenlabs.stream(audio_stream)
```

I think I need to use an Async callback, but I can't get it to work. I've tried simply adding the following custom callback, but it doesn't work.

```
class MyStreamingResonseHandler(StreamingStdOutCallbackHandler):
    def on_llm_new_token(self, token: str, **kwargs: Any) -> None:
        yield token
```

The idea is to replicate what this part does as a callback:
```
        content = chunk["choices"][0].get("delta", {}).get("content")
        if content is not None:
            yield content
            print("ContentTester:", content)
            
```

This is probably a trivial thing to solve for someone more experienced, but I can't figure it out. Any help would be greatly appreciated!!
Claude XML parser
Labels: name: auto:enhancement, name: area: models

### Feature request

I find StructuredOutputParser to not work that well with Claude. It also takes quite a few tokens to output its format instructions.

It would be great to have a built-in support for using XMLs as a meaning of transportation.

### Motivation

Claude supports and works really well with XML tags. 

An example output:
> When you reply, first find exact quotes in the FAQ relevant to the user's question and write them down word for word inside <thinking></thinking> XML tags.  This is a space for you to write down relevant content and will not be shown to the user.  Once you are done extracting relevant quotes, answer the question.  Put your answer to the user inside <answer></answer> XML tags.

As you can see, it works really well providing the answer inline the paragraph. Unlike StructuredOutputParser, we don't have to provide examples, explain the schema as well as ask to wrap the output in the markdown delimiter.

I would personally use something like regular expressions to look and parse the contents inside the tags, not forcing Claude itself to stick to any particular output format (such as "your response must be a valid XML document" etc.).

### Your contribution

I would be happy to own this feature and send a PR to TypeScript implementation. [I have already written this locally and have tested it to work quite well](https://gist.github.com/grabbou/fdd0816275968f0271e09e19b2ac82b8). Note it is a very rough implementation, as my understanding of the codebase is (at this point) rather limited. I am making my baby steps tho!

I would be happy to pair with someone on the Python side to explain how the things work with Claude.
Update CONTRIBUTING.md
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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->

Hi LangChain :) Thank you for such a great project! 
I was going through the CONTRIBUTING.md and found a few minor issues.
Issue: Final Answer missing Document sources when using initialize_agent RetrievalQA with Agent tool boolean flag return_direct=False 
Labels: name: area: agent, name: auto:bug

### Issue you'd like to raise.

```
llm = ChatOpenAI(
            max_retries=3,
            temperature=0.7,
            model_name="gpt-4",
            streaming=True,
            callbacks=[AsyncStreamingCallbackHandler],
        )
```


Tool params 

` return_direct=False` # Toggling this to TRUE provides the sources, but it won't work with the streaming flag, so I set it to false so the Final answer can be streamed as part of the output. This works as expect its just the Final answer has no sources which are clearly there as part of the observation section

```text 
Observation: 
                        At Burger king, you will get 50 days of paid annual leave, 50 days of paid sick leave, 12 public holidays, and two additional floating holidays for personal use. If applicable, you can also get up to six weeks of paid parental leave. 
                        For more in-depth coverage, refer to these sources:
                        1. Company Benefits.pdf, page: 32

``` 


```
qa = RetrievalQA.from_chain_type(
            llm=self.llm,
            chain_type="stuff",
            retriever=retriever,
            return_source_documents=True,
            chain_type_kwargs=chain_type_kwargs
        )
```

Has any experienced missing document sources as part of the final answer 

while within the context of the RetrievalQA, source documents exist as am explicitly concatenating them as part of the answer, which I expect to be part of the Final Answer. 

```
result = qa({"query": question})
        chat_answer = result["result"]
        if self.hide_doc_sources:
            return chat_answer
        formatted_sources = format_sources(result["source_documents"], 2)
        chat_answer = f"""
                {chat_answer}\n\n 
                \n\n{formatted_sources}
        """
```


### Suggestion:

_No response_