delayedkarma/langchain-issues huggingface dataset:
raise value error added for directory loader
Labels: name: area: doc loader, name: auto:bug, name: size:XS

added value error for `DirectoryLoader` if the given path is a valid path but it does not contain any files .

<!-- 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.
 -->
DOC: modules/model_io/concepts in documentation
Labels: name: auto:documentation

### System Info

Issue with current documentation:

I was reading the documentation and in the modules/model_io/concepts page noticed a minor issue with the pagination navigation. Both the "Previous" and "Next" links currently point to the same page ('model_io'), which may lead to confusion for users.

![Screenshot from 2024-01-10 12-53-30](https://github.com/langchain-ai/langchain/assets/19512591/3bc27c0c-f597-41ea-9791-fe682c6f97d5)


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

### Reproduction

// The error is on the documentation website.

### Expected behavior

Upon reviewing the content, I believe that the "Next" link should navigate users to the 'prompts' page of the 'model_io' section, providing a seamless transition for readers.
printing intermediate output from RAG chains
Labels: name: auto:question, name: area: models

### System Info

langchain==0.0.352

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

```python
# Define LLM to generate response
    llm = VertexAI(model_name='text-bison@001', max_output_tokens=512, temperature=0.2)
 
    if not message:
        message = request.form.get('userInput')
    template = """
        appropriate custom prompt context...

        {context}
        Question: {question}
       
    
    """

    qa_prompt = ChatPromptTemplate.from_messages(
        [
            ("system", template),
            MessagesPlaceholder(variable_name="chat_history"),
            ("user", "{question}"),
        ]
    )

    rag_chain = (
        RunnablePassthrough.assign(
            context=contextualized_question | sub_retriever
        )
        | qa_prompt
        | llm
        | remove_prefix
    )
    
    response = rag_chain.invoke(({"question": message, "chat_history": memory.get_history()}))
    memory.add_interaction(message, response)
```

### Expected behavior

I want to get intermediate output of contextualized_question chain, in
```python
RunnablePassthrough.assign(
            context=contextualized_question | sub_retriever
        )
```

so that I can easily debug the whole process.
For now, I am just getting final response from the chain which is,
```python
response = rag_chain.invoke(({"question": message, "chat_history": memory.get_history()}))
```
Issue: How to use ChatPromptTemplate?
Labels: name: auto:question, name: area: models

### Issue you'd like to raise.

Please look at the example below, I used ChatPromptTemplate to chat wit gpt, the output of the gpt always have a prefix "AI: "，how to remove it.

```python
def chat(self, messages):
        history = [("system", SYSTEM)]
        for message in messages:
            if message["role"] == "user":
                history.append(("human", message["content"]))
            else:
                history.append(("ai", message["content"]))
        prompt = ChatPromptTemplate.from_messages(history)
        chat_chain = prompt | self.model
        res = chat_chain.stream({})
        return res
```

![image](https://github.com/langchain-ai/langchain/assets/129026999/22ae2cdc-023c-477d-bbf9-b9271eff6001)

### Suggestion:

_No response_
<Community>: Add Initial Support for TiDB Vector Store

This pull request introduces initial support for the TiDB vector store. The current version is basic, laying the foundation for the vector store integration. While this implementation provides the essential features, we plan to expand and improve the TiDB vector store support with additional enhancements in future updates.

Upcoming Enhancements:
* Support for Vector Index Creation: To enhance the efficiency and performance of the vector store.
* Support for max marginal relevance search. 
* Customized Table Structure Support: Recognizing the need for flexibility, we plan for more tailored and efficient data store solutions.

Simple use case exmaple

```
## Loading Environment Variables
from typing import List, Tuple
from langchain.docstore.document import Document
from langchain_community.vectorstores.tidb_vector import TiDBVector
from langchain_openai import OpenAIEmbeddings

collection_name = "tidb_vector_langchain"
db = TiDBVector.from_texts(
    embedding=embeddings,
    texts=['Andrew like eating oranges', 'Alexandra is from England', 'Ketanji Brown Jackson is a judge'],
    collection_name=collection_name,
    connection_string=tidb_connection_url,
    distance_strategy="cosine",
)

query = "Can you tell me about Alexandra?"
docs_with_score: List[Tuple[Document, float]] = db.similarity_search_with_score(query)
for doc, score in docs_with_score:
    print("-" * 80)
    print("Score: ", score)
    print(doc.page_content)
    print("-" * 80)
```
langchain[patch]: Improve stream_log with AgentExecutor and Runnable Agent
Labels: name: area: agent, name: lgtm, name: auto:improvement, name: size:XL

This PR fixes an issue where AgentExecutor with RunnableAgent does not allow
users to see individual llm tokens if streaming=True is not set explicitly on
the underlying chat model.

The majority of this PR is testing code:

1. Create a test chat model that makes it easier to test streaming and supports
   AIMessages that include function invocation information.
2. Tests for the chat model
3. Tests for RunnableAgent (previously untested)
4. Tests for openai agent (previously untested)
create_structured_output_chain doesn't invoke the given callback and on_llm_new_token with tokens
Labels: name: auto:bug

### System Info

```
            end_response = chain.run(
                input=input["input"],
                question=input["question"],
                callbacks=[StreamingHandler()],
                tags=tags,
            )
```

```
StreamingHandler() is an extension of the langchain class `BaseCallbackHandler` and extends its methods:

```
    def on_llm_new_token(self, token: str, **kwargs) -> None:
        if token:
            self.queue_event(event_data=token)
```

With a regular `LLMChain`:
```
    conv_chain = LLMChain(
         llm=llm,
         memory=memory,
         prompt=chain_prompt,
         verbose=True,
    )
```

this `on_llm_new_token` method gets invoked each call with each new token.

However, with create_structured_output_chain, it seems to get invoked with empty tokens each time:

```
 conv_chain = create_structured_output_chain(
        output_schema=APydanticClass,
        llm=llm,
        prompt=chain_prompt,
        verbose=True,
    )
```

### Who can help?

@agola11 seems the right perrson to tag 🙏 

### Information

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

### Related Components

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

### Reproduction

1. Use create_structured_output_chain with a pydantic schema
2. Attach a callback with on_llm_new_token overriden
3. on_llm_new_token gets invoked with empty tokens.

### Expected behavior

Tokens streamed back in the json format of the schema requested. E.g. if the schema is:

```
class XYZ(BaseModel):
    matches: Optional[List[str]] = Field(
        default=None, description="abc"
    )
    not_matches: Optional[List[str]] = Field(
        default=None,
        description="def",
    )
```

I'd expect it to be streamed back token by token or even category by category.
community: add collection_properties parameter to Milvus
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: size:S

  - **Description:** add collection_properties parameter to Milvus. See [pymilvus set_properties() description](https://milvus.io/api-reference/pymilvus/v2.3.x/Collection/set_properties().md)
  - **Issue:** None
  - **Dependencies:** None
  - **Twitter handle:** None
GoogleCloudEnterpriseSearchRetriever returned 'datastore not found' error even with the 'us' configurations
Labels: name: area: vector store, name: auto:bug

### System Info

langchain==0.0.352

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

### Reproduction

```python
from langchain.retrievers import (
    GoogleVertexAIMultiTurnSearchRetriever,
    GoogleVertexAISearchRetriever,
    GoogleCloudEnterpriseSearchRetriever
)
    
PROJECT_ID = "my_project_id"
SEARCH_ENGINE_ID = "I tried both for datastore_id and app_id at Vertex Search"
LOCATION_ID = "us"

retriever = GoogleCloudEnterpriseSearchRetriever(
    project_id=PROJECT_ID,
    search_engine_id=SEARCH_ENGINE_ID,
    location_id=LOCATION_ID,
    max_documents=3
)

while 1:
    message = input()
    result = retriever.get_relevant_documents(message)
    for doc in result:
        print(doc)
```

### Expected behavior

I expected it works well with the defined datastore, but it returned the error saying,

```
google.api_core.exceptions.NotFound: 404 DataStore projects/500618827687/locations/us/collections/default_collection/dataStores/['datastore_id'] not found
```
Issue with LangChain v0.0.335 - Error in ChatOpenAI Callbacks Expected Runnable Instances
Labels: name: auto:bug, name: area: models, name: integration: pinecone

### Issue you'd like to raise.

I am currently utilizing LangChain version 0.0.335 in my Fast API Python application. In the main.py file, the following code snippet is implemented:

main.py 
 ```
        streaming_model = ChatOpenAI(
            model_name="gpt-4",
            temperature=0.1,
            openai_api_key=os.getenv("OPENAI_API_KEY2"),
        )

        non_streaming_model = ChatOpenAI(
            model_name="gpt-4",
            temperature=0.1,
            openai_api_key=os.getenv("OPENAI_API_KEY2"),
        )

        retriever = vector_store.as_retriever()

        sales_persona_prompt = PromptTemplate.from_template(SALES_PERSONA_PROMPT)
        condense_prompt = PromptTemplate.from_template(CONDENSE_PROMPT)


        chain = ConversationalRetrievalChain.from_llm(
            llm=streaming_model,
            retriever=retriever,
            condense_question_prompt=condense_prompt,
            condense_question_llm=non_streaming_model,
            combine_docs_chain_kwargs={"prompt": sales_persona_prompt},
            verbose=True,
        )
        return chain(
            {"question": sanitized_question, "chat_history": conversation_history}
        )
        
   except Exception as e:
       return {"error": str(e)} 
```
        
However, this implementation throws the following error: 

 ` "error": "2 validation errors for LLMChain\nllm\n  instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)\nllm\n  instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)"`
       
    Expected Behavior:
I expected the code to execute without errors. The issue seems to be related to the expected types for the llm parameter in the ConversationalRetrievalChain.from_llm method.

Request for Assistance:
I kindly request assistance in understanding and resolving this issue. Any insights, recommendations, or specific steps to address the error would be highly appreciated.

Thank you for your time and support.



### Suggestion:

_No response_
docs[patch]: Fix bad headers in output parser docs
Labels: name: lgtm, name: auto:documentation, name: size:M

Currently looks like this:

<img width="282" alt="Screenshot 2024-01-09 at 1 08 53 PM" src="https://github.com/langchain-ai/langchain/assets/6952323/58f3d368-6588-418e-8502-30d13757cb99">

CC @efriis @baskaryan
templates: robocorp action server template
Labels: name: area: agent, name: auto:documentation, name: template, name: size:L

- Hardwire release actions
- Revert "Hardwire release actions"
- Initial implementation
- Initial tests update
- Test fixes
- Remove redundant description
- Initial docs update
- - Add missing Langsmith dependency - Update docs
- Add template
- Fix linting
- remove code duplicate use urljoin to ensure openapi path
- lint
- docs/toolkit update
- fix typo and test..
- Update README
- fix case where action has no doc string
- refactoring
- Conditionally return structured/unstructured tools
- Update docs
- Fix formatting
- Leave template only
community: Fix String-List Comparison Bug in AzureAIDocumentIntelligenceParser
Labels: name: lgtm, name: area: doc loader, name: auto:bug, name: size:XS

This pull request addresses a bug found in `AzureAIDocumentIntelligenceParser` where a string was incorrectly being compared to a list. 

The code currently uses the expression `self.mode == ["page"]` to check which mode the user has selected. In Python, this comparison is always `False` (self.mode is asserted to be str in line 35), thus the if-statement would always result in the execution of `_generate_docs_object` instead of `_generate_docs_page`.

The fix is to remove the brackets resulting in a correct comparison.
chain.batch() doesn't use config options properly (max concurrency)
Labels: name: auto:bug, name: investigate

### System Info

**Platform**: Ubuntu 22.04

**Python**: 3.10

**Langchain**:
langchain                                0.1.0
langchain-community                      0.0.10
langchain-core                           0.1.8
langchain-openai                         0.0.2
langsmith                                0.0.78


### 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

I used this code :
```py
out = chain.batch(entries, config={"max_concurrency": 3})
``` 
I can see in Langsmith that more than 12 requests were made at parallel, causing rate limit failure with OpenAI API (TPM).

```
RateLimitError: Error code: 429 - {'error': {'message': 'Rate limit reached for gpt-3.5-turbo-1106 in organization org-W83OoPhCAmgMx2r35aLyv9Tr on tokens per min (TPM): Limit 60000, Used 54134, Requested 6465. Please try again in 599ms. Visit https://platform.openai.com/account/rate-limits to learn more.', 'type': 'tokens', 'param': None, 'code': 'rate_limit_exceeded'}}
```

### Expected behavior

I would expect max_concurrency to limit the amount of concurrency used, but actually that doesn't seem to be the case.
Batch doesn't seem to limit concurrency at all. 

This code works perfectly : 
```py
from concurrent.futures import ThreadPoolExecutor

def batch_chain(inputs: list) -> list:
    with ThreadPoolExecutor(max_workers=3) as executor:
        return list(executor.map(chain.invoke, inputs))

out = batch_chain(entries)
```
community: Add CometLLM integration notebook example
Labels: name: auto:documentation, name: area: models, name: size:L

I also added LANGCHAIN_COMET_TRACING to enable the CometLLM tracing integration similar to other tracing integrations. This is easier for end-users to enable it rather than importing the callback and pass it manually.

(This is the same content as https://github.com/langchain-ai/langchain/pull/14650 but rebased and squashed as something seems to confuse Github Action).
Async with EnsembleRetriever
Labels: name: auto:question

### Issue you'd like to raise.

How can EnsembleRetriever be called asynchronously? I have a dataset with ~1k questions and I wish to find the documents that can best answer each of them. However, calling it sequentially takes a lot of time. Can I run the retriever in parallel for all rows (or chunks of it)? Or is there a different way to optimise the run times?

I'm calling it like this now but it gives out a segmentation fault after getting stuck for an hour
```
import asyncio

queries = [query1, query2, ...]

async def process_query(profile):
    result = await ensemble_retriever.aget_relevant_documents(profile)
    return result

async def process_all_queries():
        
    tasks = [process_query(query) for query in queries]
    results = await asyncio.gather(*tasks)
    return results

results = asyncio.run(process_all_queries())
```

### Suggestion:

_No response_
Add NVIDIA Canonical RAG example chain
Labels: name: lgtm, name: area: embeddings, name: auto:enhancement, name: template, name: size:L

- **Description:** Adds a RAG template that uses NVIDIA AI playground and embedding models, along with Milvus vector store

- **Dependencies:** This template depends on the AI playground service in NVIDIA NGC. API keys with a significant trial compute are available (10k queries at the time of writing). This template also depends on the Milvus Vector store which is publicly available.

Note: [A quick link to get a key](https://catalog.ngc.nvidia.com/orgs/nvidia/teams/ai-foundation/models/codellama-13b/api) when you have an NGC account. Generate Key button at the top right of the code window.
docs: remove unnecessary description
Labels: name: lgtm, name: auto:documentation, name: size:XS


| before | after |
| ---- | ---- |
| ![image](https://github.com/langchain-ai/langchain/assets/1635118/c108c53c-2665-46c3-82bf-8f74005f9ac9) | ![image](https://github.com/langchain-ai/langchain/assets/1635118/2da3427a-1bac-4e9e-9fb2-509c9674d8a1) |
docs: Updated MongoDB Chat history example notebook to use LCEL format.
Labels: name: area: memory, name: lgtm, name: auto:documentation, name: size:L

  - **Description:** Updated the MongoDB example integration notebook to latest standards
  - **Issue:** [15664](https://github.com/langchain-ai/langchain/issues/15664)
  - **Dependencies:** None
  - **Twitter handle:** @davedecaprio
Issue: Streaming agent's response to Streamlit UI
Labels: name: auto:bug, name: area: lcel

### Issue you'd like to raise.

I am developing a Streamlit application where I aim to stream the agent's responses to the UI. Previously, I was able to achieve this by utilizing chains with a simple call to ```chain.stream()```. However, after switching to agents, I cannot stream its response in the same way given that it is implemented in LCEL.

I've tried to use ```StreamingStdOutCallbackHandler``` but the response gets streamed in the terminal only and not to the UI.
Any insights, guidance, or fixes regarding this issue would be greatly appreciated

### Suggestion:

_No response_
adding parameter for changing the language in SpacyEmbeddings
Labels: name: area: embeddings, name: auto:improvement, name: size:M

Description: Added the parameter for a possibility to change a language model in SpacyEmbeddings. The default value is still the same: "en_core_web_sm", so it shouldn't affect a code which previously did not specify this parameter, but it is not hard-coded anymore and easy to change in case you want to use it with other languages or models.

Issue: At Barcelona Supercomputing Center in Aina project (https://github.com/projecte-aina), a project for Catalan Language Models and Resources, we would like to use Langchain for one of our current projects and we would like to comment that Langchain, while being a very powerful and useful open-source tool, is pretty much focused on English language. We would like to contribute to make it a bit more adaptable for using with other languages.

Dependencies: This change requires the Spacy library and a language model, specified in the model parameter.

Tag maintainer: @dev2049

Twitter handle: @projecte_aina
community: Support milvus partition key.
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: size:XS


  - **Description:** Milvus's partition key is an important feature. It can support multi-tenancy. We hope to introduce this feature.     https://milvus.io/docs/partition_key.md
  - **Issue:** No
  - **Dependencies:** No
  - **Twitter handle:** No