delayedkarma/langchain-issues huggingface dataset:
Add ChatGLM API for llm and chat_model
Labels: name: auto:enhancement, name: area: models

using sample:
```
endpoint_url = API URL
ChatGLM_llm = ChatGLM(
    endpoint_url=endpoint_url,
    api_key=Your API Key by ChatGLM
)
print(ChatGLM_llm("hello"))
```

```
model = ChatChatGLM(
    chatglm_api_key="api_key",
    chatglm_api_base="api_base_url",
    model_name="model_name"
)
chain = LLMChain(llm=model)
```
Description: The call of ChatGLM has been adapted.
Issue: The call of ChatGLM has been adapted.
Dependencies: Need python package `zhipuai` and `aiostream`
Tag maintainer: None
Twitter handle: None
Bugfix/jsonloader metadata
Labels: name: area: doc loader, name: auto:bug

Hi,

  - Description: 
    - Solves the issue #6478. 
    - Includes some additional rework on the `JSONLoader` class:
      - Getting metadata is decoupled from `_get_text`
      - Validating metadata_func is perform now by `_validate_metadata_func`, instead of `_validate_content_key`
  - Issue: #6478 
  - Dependencies: NA
  - Tag maintainer: @hwchase17
Update mrkl docs
Labels: name: area: agent, 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.
 -->
GPT4All callup failure
Labels: name: auto:bug, name: area: models

### System Info

Colab environment
LangChain version: 0.0.152

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

### Reproduction

Please follow the tutorial [here](https://learn.activeloop.ai/courses/take/langchain/multimedia/46317672-using-the-open-source-gpt4all-model-locally) and run the code below to reproduce
```
template = """Question: {question}

Answer: Let's answer in two sentence while being funny."""

prompt = PromptTemplate(template=template, input_variables=["question"])

callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = GPT4All(model="./models/ggml-model-q4_0.bin", callback_manager=callback_manager, verbose=True)
llm_chain = LLMChain(prompt=prompt, llm=llm)

question = "What happens when it rains somewhere?"
llm_chain.run(question)
```

### Expected behavior

TypeError: GPT4All.generate() got an unexpected keyword argument 'n_ctx'
Update json_loader.py: encoding bug
Labels: name: lgtm, name: area: doc loader, name: auto:bug

JSONLoader.load does not specify `encoding` in `self.file_path.read_text()` as `self.file_path.open()`

<!-- 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.
 -->
document loader google drive for javascript version
Labels: name: area: doc loader, name: auto:enhancement

### Feature request

Hi, Actually exists a document loader for Google Drive in the Python version, I would like to propose this feature in the javascript version, it is important to our company.

### Motivation

Hi, Actually exists a document loader for Google Drive in the Python version, I would like to propose this feature in the javascript version, it is important to our company.

### Your contribution

no :( I don´t have the knowledge
docs: Fix `CustomLLM` and `Question_answering` docs
Labels: name: auto:documentation, name: area: models

### Description
- Update `CustomLLM._call`: Corrected the _call method in CustomLLM to include **kwargs, ensuring consistency with parent class.
- Update `Question_answering`: To fix `Page not found` error
   - https://python.langchain.com/docs/use_cases/code -> https://python.langchain.com/docs/use_cases/code_understanding

### Issue
N/A

### Dependencies
N/A

### Tag maintainer
N/A

### Twitter handle
N/A
Issue #2241 Support nested code blocks in agent response JSON.
Labels: name: area: agent, name: auto:bug

Resolves https://github.com/langchain-ai/langchain/issues/2241.

ConversationalChatAgent prompt contains JSON examples nested in triple-ticked codeblocks.

When response contains a triple-ticked codeblock, this breaks the response.

PR updates prompt to use quadruple-ticked code blocks, enabling responses to include code examples in markdown.

cc: @hwchase17 @agola11
Pass headers arg (requests library) to loaders that fetch from web
Labels: name: area: doc loader, name: auto:improvement

### Feature request

Some urls will return status code 403 if the right headers are not passed to the requests.get(path) function. My workaround was to provide the headers of that website to get the approval from the server. Would be great to be able to pass headers to PyMuPDFLoader and all the other web based document_loaders 

headers = {
            "User-Agent": "Chrome/109.0.5414.119",
            "Referer": "https://www.ncbi.nlm.nih.gov" if 'ncbi' in self.file_path else None
            }
            r = requests.get(self.file_path, headers=headers)

the execution would be PyMuPDF(path, headers).load() and if it detects that headers is provided itll provide it downstream to 'get'

### Motivation

Some urls will return status code 403 if the right headers are not passed to the requests.get(path) function. My workaround was to provide the headers of that website to get the approval from the server. Would be great to be able to pass headers to PyMuPDFLoader and all the other web based document_loaders 

Mainly an issue with websites like NCBI

### Your contribution

Not experienced enough
fixed regex to match sources for all cases, also includes source
Labels: name: needs test, name: auto:bug

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: Updated the regex to handle all the different cases for string matching (SOURCES, sources, Sources), 
  - Issue: https://github.com/langchain-ai/langchain/issues/9774
  - Dependencies: N/A
  - 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.
 -->
The RetrievalQAWithSourcesChain with the ExamplePrompt doesn't always return SOURCES as part of it's answers.
Labels: name: auto:bug

https://github.com/langchain-ai/langchain/blob/709a67d9bfcff475356924d8461140052dd418f7/libs/langchain/langchain/chains/qa_with_sources/base.py#L123

I've noticed that the retrieval qa chain doesn't always return SOURCES, it sometimes returns "Sources", "sources" or "source".
Issue: SagemakerEndpoint does not support async calls
Labels: name: auto:question, name: auto:enhancement, name: area: models

### Issue you'd like to raise.

Right now, the Sagemaker Inference Endpoint LLM does not allow for async requests and it's a performance bottleneck.
I have an API gateway set up such that I have a restful api endpoint backed by the sagemaker inference endpoint.

In an ideal world:
1. Langchain should allow for arbitrary http requests to a backend LLM of our choice fronted by your LLM interfaces. This way, we can standardize async calls for this sort of flow.
2. SagemakerEndpoint should allow for async requests.

Is this feasible?
Does this exist at the moment?

### Suggestion:

_No response_
Cassandra support for LLM cache (exact-match and semantic)
Labels: name: area: memory, name: lgtm, name: auto:enhancement

This PR implements two new classes in the cache module: `CassandraCache` and `CassandraSemanticCache`, similar in structure and functionality to their Redis counterpart: providing a cache for the response to a (prompt, llm) pair.

Integration tests are included. Moreover, linting and type checks are all passing on my machine.

Dependencies: the `pyproject.toml` and `poetry.lock` have the newest version of cassIO (the very same as in the Cassandra vector store metadata PR, submitted as #9280).

If I may suggest, this issue and #9280 might be reviewed together (as they bring the same poetry changes along), so I'm tagging @baskaryan who already helped out a little with poetry-related conflicts there. (Thank you!)

I'd be happy to add a short notebook if this is deemed necessary (but it seems to me that, contrary e.g. to vector stores, caches are not covered in specific notebooks).

Thank you!
Add neo4j vector support
Labels: name: area: vector store, name: auto:enhancement

Neo4j has added vector index integration just recently. To allow both ingestion and integrating it as vector RAG applications, I wrapped it as a vector store as the implementation is completely different from `GraphCypherQAChain`. Here, we are not generating any Cypher statements at query time, we are simply doing the vector similarity search using the new vector index as if we were dealing with a vector database.

Todo:

* [x] Tests
Add Notebook demonstrating how to use Poetry
Labels: name: area: doc loader, name: auto:documentation

-It can be useful to understand how to load modified code from a custom fork
- Using Poetry as a dependency and virtualenv manager is helpful, but requires a different workflow within a Jupyter Notebook context

[Link to rendered Notebook for easier review.](https://github.com/langchain-ai/langchain/blob/dc331e33695137affbe4ded1f5bf2b7633f4df15/docs/extras/integrations/vectorstores/pineconepoetry.ipynb)

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: Add a new example Jupyter Notebook demonstrating how to work with Poetry to load modified library code, such as langchain, from a branch of a fork 

  - Dependencies: None, the Notebook fetches the data it needs remotely at runtime,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: zackproser

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.
 -->
PySpark error message and token limits in spark_sql
Labels: name: auto:improvement

### Issue you'd like to raise.

The issue with PySpark messages is that they could become quite lengthy and after some iterations they could potentially causing problems with token limits. In this context, I would like to initiate a discussion about this topic and explore potential solutions.


### Suggestion:
My suggestion would be to generate a summary of the error message before returning. I am currently not deep enough into the langchain topic and maybe there are better options so feel free to comment.

It is regarding following part [langchain/libs/langchain/langchain/utilities/spark_sql.py](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/spark_sql.py):
```python
def run_no_throw(self, command: str, fetch: str = "all") -> str:
        """Execute a SQL command and return a string representing the results.

        If the statement returns rows, a string of the results is returned.
        If the statement returns no rows, an empty string is returned.

        If the statement throws an error, the error message is returned.
        """
        try:
            return self.run(command, fetch)
        except Exception as e:
            """Format the error message"""
            return f"Error: {e}"
```
Utility to run commands in docker containers as isolated execution environment.
Labels: name: auto:enhancement

**DRAFT**

Description: It is a wrapper around docker python library, allowing to pull/build docker images with ability to run and execute command in a container. It is a low-level building block which allows to isolate execution and constrain resources - should allow to improve security a bit after integration with things like PythonREPL.

Dependencies: docker

Twitter handle: @deepsense_ai

**WIP**:  For now I think integration tests are required. I run tests outside langchain so I need yet to see if they pass & can run on CI.
fix call _get_keys for custom_evaluator
Labels: name: auto:bug

In the function _load_run_evaluators the function _get_keys was not called if only custom_evaluators parameter is used


  - Description: In the function _load_run_evaluators the function _get_keys was not called if only custom_evaluators parameter is used, 
  - Issue: no issue created for this yet,
  - Dependencies: None,
  - Tag maintainer: @vowelparrot,
  - Twitter handle: Buckler89
Streaming doesn't work correctly with caching
Labels: name: auto:bug, name: area: models

### System Info

LangChain version : 0.0.273
Python version : 3.10.8
Platform : macOS 13.5.1

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

### Reproduction

```python
import langchain
from langchain.chat_models import ChatOpenAI
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.cache import InMemoryCache


langchain.llm_cache = InMemoryCache()

llm = ChatOpenAI(model_name="gpt-3.5-turbo", streaming=True, callbacks=[StreamingStdOutCallbackHandler()])
resp = llm.predict("Tell me a joke")
resp1 = llm.predict("Tell me a joke")
```

output:

```
Sure, here's a classic one for you:

Why don't scientists trust atoms?

Because they make up everything!
```

### Expected behavior

I'd expect both responses to be streamed to stdout but as the second one is coming from the memory cache, the callback handler `on_llm_new_token` is never called and thus the second response never printed.

I guess `on_llm_new_token` should be called once with the full response loaded from cache to ensure a consistent behavior between new and cached responses.
Synthetic data generation
Labels: name: auto:enhancement

### Description

Implements synthetic data generation with the fields and preferences given by the user. Adds showcase notebook.
Corresponding prompt was proposed for langchain-hub.

### Example

```
output = chain({"fields": {"colors": ["blue", "yellow"]}, "preferences": {"style": "Make it in a style of a weather forecast."}})
print(output)

# {'fields': {'colors': ['blue', 'yellow']},
 'preferences': {'style': 'Make it in a style of a weather forecast.'},
 'text': "Good morning! Today's weather forecast brings a beautiful combination of colors to the sky, with hues of blue and yellow gently blending together like a mesmerizing painting."}
```

### Twitter handle 

@deepsense_ai @matt_wosinski
Issue:  To be able to store Weaviate (for that matter any vector store) Vector Store in REDIS
Labels: name: area: vector store, name: auto:bug, name: auto:question

### Issue you'd like to raise.

Hello,

have two separate docker images as follows.
1. for the purpose of Loading documents and then tokenizing and creating embeddings and storing in Vector store DB like this `vector_store_db:Weaviate = weaviateInstance.from_documents(documents, self.embeddings, by_text=False) `
2. Another docker image running FASTAPI which receives the actual Query. Now we want to be ablet to store the `vector_store_db` (created by the first docker image) in Redis Store so that the second docker image can get the `vector_store_db` from REDIS and execute the Query against it by invoking function like `similar_doc=vector_store_db.similarity_search("Question ?",k=1)`

we tried number of options to be able to store the `vector_store_db` ( which is of type Weaviate as per the documentation here [https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.weaviate.Weaviate.html#langchain.vectorstores.weaviate.Weaviate.from_texts](url) ) REDIS , but we are getting SERIALIZATION issues.  We tried ` pickle, dill and json` and NO luck yet.
And then we came across the issue link [https://github.com/langchain-ai/langchain/issues/9288](url) and we tried the `dumps()` option and our relevant code snippet looks like this 

```vs_redis_obj = dumps(vector_store_db)
 redis_client = redis.Redis(host='localhost', port=6379, encoding="utf-8", decode_responses=True)
 redis_client.set("ourkey", vs_serialized)
 vs_obj:Weaviate = redis_client.get("ourkey")   
 #Start: sample code for Querying the Vector store DB
 similar_doc=vector_store_db.similarity_search("Who is trying to invade earth?",k=1)
```
but we are getting the error `Error :'str' object has no attribute 'similarity_search'` 

Basically we kind of get why the error is coming because of the following....
1. when we store the object `vector_store_db` in REDIS its getting serialized to its `str` equivalent.
2. So when we do redis.get() we get the vector_store_db to be its `str` equivalent.  And this is the reason why our call to `similarity_search()` fails .

Any ideas how can we fix this please.
Basically we need to be able to make the vector_store_db (created by one docker image) to another docker image through REDIS, 
Any help / suggestion is much appreciated and thanks in advance.




### Suggestion:

_No response_
Custom Map-Reduce chain
Labels: name: auto:enhancement

### Feature request

Hey wanted to request a feature within the map-reduce chain where a person can send his own list of chunks data of a corpus instead of creating chunks of data based on sending a textsplitter and a corpus.

### Motivation

Sometime one might see map-reduce cases where one wants to use their own chunks of data and don't want to split a data corpus based on sending a textsplitter or character splitter.

### Your contribution

I can work on it by raising a PR.
docs: Fix `CustomLLM` and `QA over Documents` docs
Labels: name: auto:documentation, name: area: models

 ### Description
- Update  `CustomLLM._call`: Corrected the _call method in CustomLLM to include **kwargs, ensuring consistency with parent class.
- Update `QA over Documents`: To fix `Page not found` error
   - https://python.langchain.com/docs/use_cases/tabular -> https://python.langchain.com/docs/use_cases/sql
   - https://python.langchain.com/docs/use_cases/code -> https://python.langchain.com/docs/use_cases/code_understanding
 ### Issue
N/A
 ### Dependencies
N/A
 ### Tag maintainer
N/A
 ### Twitter handle
N/A
Add 'download_dir' argument to VLLM
Labels: name: lgtm, name: auto:improvement, name: area: models

- Description:
Add a 'download_dir' argument to VLLM model (to change the cache download directotu when retrieving a model from HF hub)
- Issue:
On some remote machine, I want the cache dir to be in a volume where I have space (models are heavy nowadays). Sometimes the default HF cache dir might not be what we want.
- Dependencies:
None
Nc/runnables seqmap tags
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.
 -->