delayedkarma/langchain-issues huggingface dataset:
Local huggingface model for summarization task 
Labels: name: auto:bug, name: auto:question, name: stale, name: area: models

### Issue you'd like to raise.

I was using Langchain (map reduce) for summarization of longer documents with local HuggingFace model. I am using local models as my work prohibits me to directly connect to huggingface and/or openai. 

I am having some issue in running the model. I am getting the following errors: 

"'HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /gpt2/resolve/main/tokenizer_config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f11d2f511d0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))' thrown while requesting HEAD https://huggingface.co/gpt2/resolve/main/tokenizer_config.json"


My code is:

`from transformers import AutoTokenizer, LlamaForCausalLM,AutoModelForSeq2SeqLM,AutoModel, AutoModelForCausalLM, , LlamaTokenizer, LlamaForCausalLM,AutoModelForCausalLM,pipeline
from langchain.chains.summarize import load_summarize_chain
from langchain.text_splitter import CharacterTextSplitter
from langchain.chains.mapreduce import MapReduceChain
from langchain.docstore.document import Document
from langchain.document_loaders import PyPDFLoader
import os
import torch


model = AutoModelForSeq2SeqLM.from_pretrained("/home/projects/nlp_summarize/led-large-16384")
tokenizer2 = AutoTokenizer.from_pretrained("/home/projects/nlp_summarize/led-large-16384")
tokenizer2.deprecation_warnings["Asking-to-pad-a-fast-tokenizer"] = True

pipe = pipeline(
    "text2text-generation",
    model=model,
    tokenizer=tokenizer2,
    #max_new_tokens= 4096,
    temperature=0.7,
    top_p=0.95,
    repetition_penalty=1.15,device= DEVICE
)
llm = HuggingFacePipeline(pipeline=pipe)


text_splitter = CharacterTextSplitter()
with open("stateoftheunion.txt") as f:
    data = f.read()
texts = text_splitter.split_text(data)

docs = [Document(page_content=t) for t in texts[:]]
chain = load_summarize_chain(llm, chain_type="map_reduce")
output_summary = chain.run(docs)
`

Even though I am not using any gpt2 model2 but still the model is looking for a gpt2 model online. 

Any idea why such behavior is happening and how can I avoid it? 

### Suggestion:

_No response_
Qdrant support for async embedding functions in aadd_texts
Labels: name: area: embeddings, name: area: vector store, name: auto:enhancement

### Feature request

The qdrant vector store currently has an async function for adding texts to the (aadd_texts) which only supports creating embeddings with the _generate_rest_batches function synchronously. 

There could be the option to add a async embedding function and aadd_texts could maybe then have a parameter to create the embeddings async with an async version of _generate_rest_batches.

### Motivation

It would be nice to have the option to have an aadd_texts function with completely non blocking IO.

### Your contribution

I could try to implement this or support with the implementation.
n hyperparameter in AzureOpenai is not updated
Labels: name: auto:bug, name: area: models

### System Info

langchain==0.0.257
Python 3.8.17


### Who can help?

@hwchase17 


### 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

```
from langchain.llms.openai import AzureOpenAI
llm = AzureOpenAI(deployment_name="text-davinci-003", verbose=True)
llm._generate(["You are a chatbot. \nUser: How are you?\nBot:", 
                       "You are a chatbot. \nUser: What is the weather like?\nBot:"], n=2)
```

### Expected behavior

The result should be the same when we are providing 'n' parameter when initiating the 'AzureOpenAI' class in the beginning. However, it is not being handled, when passing it through the 'generate' function.

When n is "2", Generations only contain 1 example for each prompt, however, I expect it to have 2 examples for each. Additionally, 2 responses for the first prompt are returned as the result of two prompts, ultimately losing the result of the second prompt.

result: 
```
[
    [Generation(text=" I'm doing great, thanks for asking! How about you?", generation_info={'finish_reason': 'stop', 'logprobs': None
        })
    ],
    [Generation(text=" I'm doing well, thanks for asking! How about you?", generation_info={'finish_reason': 'stop', 'logprobs': None
        })
    ]
]
```

This may be because when the 'create_llm_result' function is called, it does not receive the recent value of 'n', instead of 2 it shows 'n' as 1. When I manually set 'self.n' to 2, it returns the expected result.

code change:

```
    def create_llm_result(
        self, choices: Any, prompts: List[str], token_usage: Dict[str, int]
    ) -> LLMResult:
        """Create the LLMResult from the choices and prompts."""
        generations = []
++      self.n = 2
        for i, _ in enumerate(prompts):
            sub_choices = choices[i * self.n : (i + 1) * self.n]
```

result:
```
[
    [Generation(text=" I'm doing great, thanks for asking! How can I help you today?", generation_info={'finish_reason': 'stop', 'logprobs': None
        }), Generation(text=" I'm doing well, thank you for asking! How can I help you?", generation_info={'finish_reason': 'stop', 'logprobs': None
        })
    ],
    [Generation(text=' The weather today is mostly sunny with a high of 70 degrees Fahrenheit and a low of 45 degrees Fahrenheit.', generation_info={'finish_reason': 'stop', 'logprobs': None
        }), Generation(text=' The current weather is sunny and warm with temperatures in the high 70s.', generation_info={'finish_reason': 'stop', 'logprobs': None
        })
    ]
]

```
Remove Evaluation from Modules page
Labels: name: lgtm, name: auto:documentation

Remove Evaluation link (which gives 404 now) from Modules page, since it lives under Guides page now

<!-- Thank you for contributing to LangChain!

Replace this 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 you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Fix typo in Vectara docs
Labels: name: lgtm, name: area: vector store, name: auto:documentation

Fixed a typo in the Vectara docs description.
<!-- Thank you for contributing to LangChain!

Replace this 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 you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Fix Pinecone cosine relevance score
Labels: name: lgtm, name: area: vector store, name: auto:bug

Fixes: #8207

Description:
Pinecone returns scores (not distances) with cosine similarity. The values according to the docs are [-1, 1], although I could never reproduce negative values.

This PR ensures that the score returned from Pinecone is preserved, rather than inverted, so the most relevant documents can be filtered (eg when using similarity thresholds)

I'll leave this as a draft PR as I couldn't run the tests (my pinecone account might not be enough - some errors were being thrown around namespaces) so hopefully someone who _can_ will pick this up. 

Maintainers:
@rlancemartin, @eyurtsev
feat: helper function to filter metadata for Chroma
Labels: name: area: vector store, name: auto:bug

### Summary

Adds a utility function to filter complex (i.e. list, dict) metadata from documents. This is helpful because some vector dbs such as Chroma do not support loading list metadata. Currently, if your `Document` has a metadata item that's a list, you get the following when you run `Chroma.from_documents`. 

```python
File ~/.pyenv/versions/chromadb/lib/python3.10/site-packages/chromadb/api/types.py:140, in validate_metadata(metadata)
    138     # isinstance(True, int) evaluates to True, so we need to check for bools separately
    139     if not isinstance(value, bool) and not isinstance(value, (str, int, float)):
--> 140         raise ValueError(
    141             f"Expected metadata value to be a str, int, float or bool, got {value} which is a {type(value)}"
    142         )
    143 return metadata

ValueError: Expected metadata value to be a str, int, float or bool, got [{'text': 'CNN', 'url': '/'}] which is a <class 'list'>
```

The helper function operates on `Document` objects and you can call it like this.

```python
from langchain.vectorstore.utils import filter_complex_metadata

updated_documents = filter_complex_metadata(documents)
```

### Testing

Confirmed the notebook in [this `unstructured` PR](https://github.com/Unstructured-IO/unstructured/pull/1054) runs on the feature branch, where previously it failed. Additionally, run the following to execute the unit test:

`pytest tests/unit_tests/vectorstores/test_utils.py`

### Reviewers

- @rlancemartin 
- @eyurtsev
- @hwchase17
Fixes to the Nebula LLM Integration
Labels: name: auto:bug, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this 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 you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->

This addresses some issues with introducing the Nebula LLM to LangChain in this PR:
https://github.com/langchain-ai/langchain/pull/8876

This fixes the following:
- Removes `SYMBLAI` from variable names
- Fixes bug with `Bearer` for the API KEY


Thanks again in advance for your help!
cc: @hwchase17, @baskaryan
SearchFieldDataType.Single raises error in azuresearch.py, under AzureSearch() class.
Labels: name: area: vector store, name: auto:bug

### System Info

Platform: MacOS
Python version: Python 3.10.12
LangChain version: 0.0.257
Azure Search package version: 1.0.0b2
Azure Search Document package version: 11.3.0

azure-search==1.0.0b2
azure-search-documents==11.3.0
langchain==0.0.257

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

1. pip install packages langchain, azure-search, azure-search-documents.
2. Try to create an instance of AzureSearch as described [here](https://python.langchain.com/docs/integrations/vectorstores/azuresearch). (Official LangChain documentation.)
3. Receive error `AttributeError: module ‘azure.search.documents.indexes.models._edm’ has no attribute ‘Single’` from:
```
vector_store: AzureSearch = AzureSearch(
    azure_search_endpoint=vector_store_address,
    azure_search_key=vector_store_password,
    index_name=index_name,
    embedding_function=embeddings.embed_query,
)
```

### Expected behavior

AzureSearch instance should be created without any errors from langchain dependencies. _edm.py file in azure-search-documents package does not define Single as a data type.
Fixed inaccurate import in integrations:providers:bedrock documentation
Labels: name: lgtm, name: auto:documentation

Description:
Fixed inaccurate import in integrations:providers:bedrock documentation

In the current version of the bedrock documentation, page https://python.langchain.com/docs/integrations/providers/bedrock it states that the import is from langchain import Bedrock

This has been changed to from langchain.llms.bedrock import Bedrock as stated in https://python.langchain.com/docs/integrations/llms/bedrock

Issue:
Not applicable

Dependencies
No dependencies required

Tag maintainer
@baskaryan

Twitter handle:
Not applicable
running HuggingFaceTextGenInference from an agent gives token limit warning
Labels: name: area: agent, name: auto:bug, name: stale, name: area: models

### System Info

LangChain version - 0.0.257

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

### Reproduction

i run the following

```
 llm = HuggingFaceTextGenInference(
            inference_server_url="http://" + settings.self_hosted_server_ip+":8080",
            max_new_tokens=2000,
            top_k=5,
            top_p=0.95,
            typical_p=0.95,
            temperature=0.01,
            repetition_penalty=1.23,
            callbacks = callbacks,
                stream = True
        )
my_chain = LLMChain(
        llm=llm,  # type: ignore
        prompt=prompt,
        verbose=False,

    )

    tools = [PythonAstREPLTool()]

    custom_agent = LLMSingleActionAgent(
        llm_chain=my_chain,
        output_parser=my_output_parser,
        stop=["\nObservation:"],
    )

    agent_memory = CustomConversationTokenBufferMemory(
        k=1,
        llm=llm,  # type: ignore
        max_token_limit=4096,
        memory_key="history"
    )  

    return AgentExecutor.from_agent_and_tools(
        agent=custom_agent,
        tools=tools,
        verbose=True,
        memory=agent_memory,
    )
```
where the HF inference endpoint is running with the following docker :
```
model=meta-llama/Llama-2-70b-chat-hf
docker run -d --gpus all --shm-size 1g -e HUGGING_FACE_HUB_TOKEN=$token -p 8080:80 -v $volume:/data ghcr.io/huggingface/text-generation-inference:latest --max-input-length 3000 --max-total-tokens 4096 --quantize bitsandbytes --json-output --model-id $model --trust-remote-code
```

the error i get is :
**Token indices sequence length is longer than the specified maximum sequence length for this model (1286 > 1024). Running this sequence through the model will result in indexing errors**

but the Llama-2-70B model token limit is 4096....
i tried to test using just the :
```
llm_local = HuggingFaceTextGenInference(
    inference_server_url=inference_server_url_local,
    max_new_tokens=2000,
    top_k=10,
    top_p=0.95,
    typical_p=0.95,
    temperature=0.7,
    repetition_penalty=1.03,
)
```
with :
```
llm_chain_local = LLMChain(prompt=prompt, llm=llm_local)
print(llm_chain_local("some query"))
```

and didnt get any error

### Expected behavior

i am not expecting any token limit issue
GCSFileLoader stores a wrong source in the metadata
Labels: name: area: doc loader, name: auto:bug

### System Info

`0.0.257`

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

### Reproduction

Load a document from GCS and check the metadata["source"], it would point to the file in `/tmp` directory

### Expected behavior

source pointing to an original file on GCS
addition to docs at 'Store and reference chat history'
Labels: name: lgtm, name: area: doc loader, name: auto:documentation


  - Description: I have added an example showing how to pass a custom template to ConversationRetrievalChain. Instead of CONDENSE_QUESTION_PROMPT we can pass any prompt in the argument condense_question_prompt. Look in Use cases -> QA over Documents -> How to  -> Store and reference chat history, 
  - Issue: #8864,
  - Dependencies: NA,
  - Tag maintainer: @hinthornw,
  - Twitter handle:
add tests to trajectory eval chain
Labels: name: area: agent, name: auto:improvement

# What
- add tests to trajectory eval chain

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: add tests to trajectory eval chain
  - Issue: None
  - Dependencies: None
  - Tag maintainer: @baskaryan
  - Twitter handle:@MLOpsJ

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Improve query prompt of BGE embeddings
Labels: name: lgtm, name: area: embeddings, name: auto:improvement

Replace this comment with:
  - Description: Improved query of BGE embeddings after talking with the devs of BGE embeddings , 
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: @hwchase17 ,
  - Twitter handle: @ManabChetia3
VectorStore: Add entries by providing embeddings and not an embedding function
Labels: name: area: embeddings, name: area: vector store, name: auto:enhancement

### Feature request

I'm looking for a way to add entries to a vector store when the embeddings already exist and I don't want to calculate them again. However, it seems like this is not possible with langchain at the moment. Maybe something like an `add_entries()` function would be nice, where the data needs to be exactly in the form as it's stored in the DB.

### Motivation

What if you want to add entries but you already have embeddings? What if you need to calculate embeddings separately from the "add to db" step?

### Your contribution

I already built a workaround for my own problem but it's very hacky. It would be nice if langchain could do this natively.
There is a bug in [Integration]-->[ChatGLM]
Labels: name: auto:bug, name: area: models

### System Info

Name: langchain
Version: 0.0.256

platform: Linux
Python 3.9.16

### 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

There is a mistake in langchain.llms.chatglm.py
![image](https://github.com/langchain-ai/langchain/assets/62985169/f138020e-8f86-4aa4-a7be-fbd801a7b600)


in line 128, where:

**`self.history = self.history + [[None, parsed_response["response"]]]`**

when you run this code, the log file shows like this:

2023-08-08 16:44:26,370 - ChatGLM - Query - 谢谢
2023-08-08 16:44:26,370 - ChatGLM - History - [['我将从美国到中国来旅游，出行前希望了解中国的城市', '欢迎问我任何问题。'], [None, '我是一个人工智能助手,我将尽力回答您的问题。'], [None, '我能回答各种问题、提供信息、帮助解决问题等。']]

Actually,it should be:

**`self.history = self.history + [[prompt, parsed_response["response"]]]`**


In this way, my input prompt can be recorded in the list correctly!

### Expected behavior

record my input prompt in a list with correspond response as history.