delayedkarma/langchain-issues huggingface dataset:
Sub Question Query Engine
Labels: name: auto:enhancement, name: area: models

### Feature request

Hi, does langchain have a feature similar to LlamaIndex's [Sub Question Query Engine](https://gpt-index.readthedocs.io/en/latest/examples/query_engine/sub_question_query_engine.html)? If not, I'd like to submit a feature request!

### Motivation

This capability is very useful!

### Your contribution

Not sure.
rename repo namespace to langchain-ai
Labels: name: lgtm, name: auto:refactor

### Description
renamed several repository links from `hwchase17` to `langchain-ai`.

### Why
I discovered that the README file in the devcontainer contains an old repository name, so I took the opportunity to rename the old repository name in all files within the repository, excluding those that do not require changes.

### Dependencies
none

### Tag maintainer
@baskaryan

### Twitter handle
[kzk_maeda](https://twitter.com/kzk_maeda)
ChatOpenAI: Exception InvalidRequestError changes bound "self"
Labels: name: auto:bug, name: area: models

### System Info

|Name|Detail|
|--------|--------|
| Python | `3.10.13` |
| LangChain | `0.0.301` |
| System | MacOS `12.2.1` |

### Bug Detail
Playing around with a recursive function to decrement value `k` and ran into an issue whereby `self` is overwritten and bound to instance of `openai.error.InvalidRequestError` when the exception is caught. Note in the code below, the `AttributeError` exception is thrown when `self.save()` is executed upon a successful `run()` or `try` where `openai.error.InvalidRequestError` is not thrown.

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

**The code below is a gross oversimplification, but it illustrates how I found this bug:**

```python
class SomeModel(models.Model):
    query = models.CharField(max_length=255)
    response = models.TextField()
    
    def save(self, *args, **kwargs):
        # Unmodified Django save method
        return super().save(*args, **kwargs)
    
    def run(self, kb, k=5):
        try:
            llm = ChatOpenAI()
            chain = load_qa_chain(llm=llm, chain_type='stuff')
            self.response = chain.run(input_documents=[], human_input=self.query)
            self.save()    #  AttributeError: 'InvalidRequestError' object has no attribute 'save'
        except (openai.error.InvalidRequestError,) as e:
            if k < 2:
                raise e
            new_k_val = k - 1
            print('K value too high. Trying with %s' % new_k_val)
            return self.run(kb, k=new_k_val)
```

### Expected behavior

Where exception happens, `self` should not be bound to another instance/instance of `openai.error.InvalidRequestError`
[fix] create redis vector index before adding docs, add prefix to doc…
Labels: name: area: vector store, name: auto:bug, name: integration: redis

Fix Description: 
For Redis Vector integration in add_texts method, there were two issues that lead to this bug. 
1. Vector index is not being created leading to no such_index error 
2. `doc:index` prefix was also missing for Redis Keys. 

resolves #11197 
Maintainer: @baskaryan
Fix typo in docstring
Labels: name: area: agent, name: lgtm, name: auto:nit

Description : Remove meaningless 's' in docstring

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Implement a custom LangChain class wrapper (LLM model/Agent) for StarCoder model
Labels: name: area: agent, name: auto:enhancement, name: area: models

### Feature request

Is it possible to integrate any language model (LM) trained on source code or opensource codebases on various programming languages e.g. :
- [StarCoder](https://github.com/bigcode-project/starcoder)
- [replit/replit-code-v1-3b](https://huggingface.co/replit/replit-code-v1-3b)
- [Bloom](https://bigscience.huggingface.co/blog/bloom)
- etc...

as an [LLM Model](https://python.langchain.com/en/latest/modules/models.html) or an [Agent](https://python.langchain.com/en/latest/modules/agents.html) with [LangChain](https://github.com/hwchase17/langchain), and [chain](https://python.langchain.com/en/latest/modules/chains.html) it in a complex usecase?

It would be really cool if, during a general query, the LangChain system has the capability to understand code context (possibly when chained to a vector DB or any data source that contains code or a full code repo), _kind of like chatting with your codebase_!

Any help / hints on the same would be appreciated!

### Motivation

Initially inspired by this [Issue #173](https://github.com/nomic-ai/gpt4all/issues/173)
Raised a similar Issue long back with StarCoder [Issue #53](https://github.com/bigcode-project/starcoder/issues/53)

### Your contribution

n/a
Clarifai integration doc improvements
Labels: name: lgtm, name: area: doc loader, 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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
  - **Description:** Doc corrections and resolve notebook rendering issue on GH 
  - **Issue:** N/A
  - **Dependencies:** N/A
  - **Tag maintainer:** @baskaryan
  - **Twitter handle:** `@isaacchung1217`
MathpixPDFLoader never finishes
Labels: name: area: doc loader, name: auto:bug

### System Info

langchain==0.0.305
MacOS M1 Silicon


### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

I have a basic methon for loading the pdf via mathpix

```
def load_pdf(path):
    loader = MathpixPDFLoader(path)
    pages = loader.load()
    return pages;

pages = load_pdf("example_data/DOF-230519AFYXBECVECGY-0028747724.pdf")

```

but if I run this, I gen only this:

Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
Status: None, waiting for processing to complete
...

in backend of mathpix I see the document aldready parsed.

Any idea on this?

### Expected behavior

Expect the document to return.
Doc: fix doc to explain the difference between `OpenAIMultiFunctionsAgent` and `OpenAIFunctionsAgent`
Labels: name: area: agent, name: auto:documentation

  - **Description:** This update adds an explanation detailing the differences between OpenAIMultiFunctionsAgent and OpenAIFunctionsAgent to both the docstring and the documentation of OpenAIMultiFunctionsAgent.
  - **Issue:** the issue #8934
  - **Dependencies:** None
  - **Tag maintainer:** @baskaryan
minor fix: remove redundant code from OpenAIFunctionsAgent
Labels: name: area: agent, name: lgtm, name: auto:nit

Replace this entire comment with:
  - **Description:** A very minor fix. Just changed `list([t.name for t in self.tools])` to `[t.name for t in self.tools]` because the `list()` is redundant.
  - **Issue:** None
  - **Dependencies:** None
  - **Tag maintainer:** @baskaryan
Hierarchical Planner - Observation: requests_put is not a valid tool, try one of [requests_get, requests_post].
Labels: name: area: agent, name: auto:bug, name: stale

### System Info

version 0.300
<img width="1397" alt="Screenshot 2023-09-30 at 5 36 41 AM" src="https://github.com/langchain-ai/langchain/assets/17947802/124b1f2a-db02-497f-9cd0-dbad1033b6c8">
\\nObservation: requests_put is not a valid tool, try one of [requests_get, requests_post].\\nThought:I need to use requests_post to update the pet\'s ship date.\\n\\nAction:

This keep happening time and time again!

### Who can help?

hierarchical planner, requests agent

https://github.com/openchatai/OpenCopilot/blob/ecd2f51bfc1f989133a44c4cff15d858b0d2fd30/llm-server/api_caller/planner.py#L319

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

### Reproduction

--

### Expected behavior

The agent should be able to use the `put` tool when it needs to use it
Limit Data and Enforcing Security for SQLDatabase & Agents
Labels: name: area: agent, name: auto:enhancement

### Feature request

We all want to have our clients to interact with the database using LLM, langchain with create_sql_agent, are great, the only problem I see, there is no way to limit user access to the database and fence him to his data. 

For example we have table called AI_Product with many columns and one of them is storeid, for normal user, he should have limited access to this table, I also don't trust the AI to limit that, there should be a way to programmatically do that.

So let's look at AI_Product
```
id, name, price, store_id
1, water, 2, 10001
2, pepsi, 4, 10001
3, cokezero , 5, 10002
```

For the above table, the user only have rights to access storeid= 10001, for security and true data we need a way to limit what this user can see.

One solution could be is to allow include_tables to have sql
`include_tables = ['AI_Product'] 
`
to
`include_tables = ['(select * from AI_Product where store_id = '10001') AI_Product'] 
`
The other one, is allow the SQL query to come back before execution and allow me to modify it
So if I asked , "How many products do we have?"

```
agent: sql:"select count(*) from AI_Product"
Then we can modify the sql to 
protected_sql = sql.replace("AI_Product", "(select * from AI_Product where store_id = '10001') AI_Product")
#sql = "select count(*) from (select * from AI_Product where store_id = '10001') AI_Product"
agent.run (protected_sql)

```












### Motivation

Find a way to protect the data while allow end-user unlimited access to it.

### Your contribution

I'm not familiar with the internal code, but I can help if gudied
Issue: < Urgent Help needed related to VectorstoreIndexCreator >
Labels: name: area: vector store, name: auto:question, name: area: models

### Issue you'd like to raise.

while RAG we create a db and then we ask a query to the db in this way,

`index = VectorstoreIndexCreator(
      vectorstore_cls=DocArrayInMemorySearch
  ).from_loaders([loader])`

`index.query(llm=chat, question=query)`

we get some response.

Now lets say wanted to create dataset with the generations ive got from gpt to fintune llama2 llm.
the main problem comes here, now how to know what is the reference we got from the index search as it is totaly abstracted!!

i need the exact querry that gone into llm(gpt) in this process.

Or else can i have any other meathod that solves my problem(tried similarity search and fed reference+query manualy the quality of the output droped so i need index search it self.

### Suggestion:

_No response_
improved rdf_graph schema generation
Labels: name: auto:improvement, name: area: models

Description: 

The RdfGraph loader provides RDF schema extraction to pass to the GraphSparqlQAChain for Q&A. The  RdfGraph also allows to provide short comments to each entity in the schema; I found this very useful to pass context or even small examples on how to use a particular class/attribute to the LLM that enhanced query generation in the GraphSparqlQAChain. 

In the current version however, adding comments leads to the generation of several artifacts that make the schema too long to fit the context window of the LLM. For example, adding few comments to a medium size graph led to a schema with 40k tokens from the original 200.  This was noted in issue  https://github.com/langchain-ai/langchain/issues/8907; although here it refers to OWL format, the problem persists in RDF. 

In this PR I am resolving the above issue by adding a filter to the original SPARQL query. Referring to the example above, the schema + comments now takes only 280 tokens. 

Another addition is the option to add a minimal list of prefixes to the schema. This is useful when the LLM is not able to infer the correct prefix from the URI or this is completely missing from the schema as I found in few use cases.

I am planning to discuss the use of comments/prefix as an addition to the current documentation in a follow up PR. 

Issue: https://github.com/langchain-ai/langchain/issues/8907,
Dependencies: N/A,
Tag maintainer: @jexp ,
feat(embeddings): display token usage and cost for OpenAIEmbeddings
Labels: name: area: embeddings, name: auto:improvement

This PR aims at (optionally) displaying the token usage and its cost for `OpenAIEmbeddings`, addressing #11093.

Since I don't see the need to support callbacks for embeddings [^1], I only added the logic to log the number of total tokens (which corresponds to the prompt tokens) and its cost as well as a flag to enable It.

[^1]: It's easy to export or store the embeddings in langchain and I don't think any use case would benefit from "postprocessing the embeddings".

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
 @baskaryan @hwchase17
Feat bedrock cohere support
Labels: name: lgtm, name: auto:enhancement, name: area: models

**Description:**
Added support for Cohere command model via Bedrock.
With this change it is now possible to use the `cohere.command-text-v14` model via Bedrock API. 

About Streaming: Cohere model outputs 2 additional chunks at the end of the text being generated via streaming: a chunk containing the text `<EOS_TOKEN>`, and a chunk indicating the end of the stream. In this implementation I chose to ignore both chunks.  An alternative solution could be to replace `<EOS_TOKEN>` with `\n`

Tests: manually tested that the new model work with both `llm.generate()` and `llm.stream()`.
Tested with `temperature`, `p` and `stop` parameters.

**Issue:** #11181 

**Dependencies:** No new dependencies

**Tag maintainer:** @baskaryan 

**Twitter handle:** mangelino
Add support for a variety of languages to LanguageParser
Labels: name: area: doc loader, name: auto:enhancement

### Feature request

[LanguageParser](https://github.com/langchain-ai/langchain/blob/e9b51513e9bab738c741a348ffbf0f36ce19faf6/libs/langchain/langchain/document_loaders/parsers/language/language_parser.py#L21C7-L21C21) is a parser for Document Loaders that, given source code, splits each top-level function or class into separate documents. As stated in its documentation:

> This approach can potentially improve the accuracy of QA models over source code.
>
> Currently, the supported languages for code parsing are Python and JavaScript.

We would like to add support for additional languages, such as C, C++, Rust, Ruby, Perl, and so on.

### Motivation

There is an [open request](https://github.com/langchain-ai/langchain/issues/10996) for "CPP" (presumably C++) support. By integrating a generic parsing library (such as [tree-sitter](https://github.com/tree-sitter/py-tree-sitter#py-tree-sitter)), we could make LanguageParser work with many more languages, and thus be more generally useful.

### Your contribution

We intend to submit a pull request for this issue no later than mid-November, and likely sooner.
Encountering a "type object is not subscriptable" error when invoking hub.pull.
Labels: name: auto:bug

### System Info

Python = 3.8.16
langchain==0.0.304
langchainhub==0.1.13

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

### Reproduction

1. install python 3.8.16
2. install langchain==0.0.304 and langchainhub==0.1.13
3. Run the following script : 

from langchain import hub
# LANGCHAIN_HUB_API_KEY is set on my .env file
# pull a chat prompt
try:
    prompt = hub.pull("efriis/my-first-prompt")
except Exception as e:
    print(e)
    raise e

### Expected behavior

I'm uncertain about the expected behavior, as I've never been able to successfully execute hub.pull.
How to disable logger streaming for async LLMChain calls?
Labels: name: auto:question, name: area: models

When using async `LLMChain` calls, the logger prints out a ton of info statements that looks like this:

```
2023-09-29 08:24:51,038:INFO - message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=7 request_id=0cde8ecb8d402ec3db4ec674f0450ade response_code=200
```

I tried setting the logging level on the execution level in a bunch of ways, but to no avail. Do you have any recommendation on how to get rid of those logs?
Implement RunnablePassthrough.assign(...)
Labels: name: auto:improvement

Passes through dict input and assigns additional keys

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->