delayedkarma/langchain-issues huggingface dataset:
Issue: sqlagent doesn't work when I use GPT-4
Labels: name: area: agent, name: auto:bug, name: auto:question, name: area: models

### System info:
langchain 0.0.289
python 3.10

### Report:
I'm doing experiments with sql agent from langchain. I created three tables in database (employees, customers and suppliers)
First, I ran it on the GPT3-5 model:
```
llm=ChatOpenAI(temperature=0)
toolkit = SQLDatabaseToolkit(db=db, llm=llm)

agent_executor = create_sql_agent(
    llm=llm,
    toolkit=toolkit,
    verbose=True,
    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    top_k=10
)
response = agent_executor({"input":"Show me all employees"})
```
![image](https://github.com/langchain-ai/langchain/assets/19593487/e0c6426d-e57d-41ed-95ff-cba702b6309b)

But, when I changed for GPT-4 model:
```
llm=ChatOpenAI(temperature=0, model_name='gpt-4')
```

It gets lost, insists on putting quotation marks and takes a long time to reason and respond.
![image](https://github.com/langchain-ai/langchain/assets/19593487/620b409b-6d57-46c4-947b-f15cc667b1bf)

Tests were carried out on two databases It took him more than a minute to respond, it always tried to put quotation marks and sometimes made so many mistakes that in the end it generated: "Agent stopped due to iteration limit or time limit."

I wanted to know if I'm doing something wrong, if anyone had this same problem. Because in 3.5, this same test works perfectly well.






### Suggestion:

_No response_
fix litellm FunctionMessage
Labels: name: lgtm, name: auto:bug, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** fix litellm FunctionMessage to use langchain.schema.messages.FunctionMessage,  currently if I use funciton call with litellm, it will be raise an error that "raise ValueError(f"Got unknown type {message}")" which the message is a FunctionMessage.

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.
fix root import
Labels: name: auto:nit

<!-- 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.
 -->
Retriever and Chain to use metadata
Labels: name: area: doc loader, name: auto:question, name: auto:improvement, name: stale

### Issue you'd like to raise.

How can I use the metadata information from retriever? I noticed that only page_content is being used whenever I retrieved information from a chain.

Use Case:

I want to display the page number to the response, these numbers are found in the metadata of the Document.

### Suggestion:

_No response_
Getting "content_filter" as finish_reason from LLMChain.generate without prompting any sensitive content
Labels: name: auto:bug, name: area: models

### System Info

Python v. 3.10.12
Langchain v. 0.0.301

### Who can help?

_No response_

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

### Reproduction

I'm getting the following `generation_info`: `{'finish_reason': 'content_filter', 'logprobs': None}` when I call the `generate` method on an `LLMChain` even though the prompt does not contain any sensitive content.
The LLM is the `langchain.llms.openai.OpenAI` one:

```python
llm = OpenAI(openai_api_key=OPENAI_API_KEY)
```

And the prompt is so defined:
```python
parser = PydanticOutputParser(pydantic_object=MyStructure)

  prompt = PromptTemplate( 
    template="--telling the model what to do--\n{format_instructions}\nVar1:{var1}\nVar2: {var2}\n",
    input_variables=["var1","var2"],
    partial_variables={"format_instructions": parser.get_format_instructions()},
    output_parser = parser
    )
```
Finally:
```python
chain = LLMChain(llm=llm, prompt=prompt)

llm_result = chain.generate(data)
```
I've tried to use the `openai.Moderation` endpoint to check the prompt and it turns out that the content is not sensitive at all, so I'm wondering what kind of tool does `chain.generate()` use to filter content?
Is there a way to shut down the content filtering while using the `chain.generate()` method?

### Expected behavior

I was expecting a generation with no `content_filter` as `finish_reason` from the `chain.generate()` method.
LangChain SQL agent unable to describe a nested bigQuery table
Labels: name: area: agent, name: auto:bug

### System Info

Hi - been trying to get langchain sql agent to describe a nested table within bigquery but getting the following error:

parameters: {'param_1': 3}]
(Background on this error at: https://sqlalche.me/e/14/4xp6)

Does this mean that it cant work with nested tables and instead I need to turn the table into a flat structure?

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

service_account_file = ""
project = ""
dataset = ""
tables = []
sqlalchemy_url = f'bigquery://{project}/{dataset}?credentials_path={service_account_file}' 
db = SQLDatabase.from_uri(sqlalchemy_url, include_tables=tables,)


llm = VertexAI(model_name="text-bison-32k")
chat = ChatVertexAI()

toolkit = SQLDatabaseToolkit(db=db, llm=llm)

agent_executor = create_sql_agent(
    llm=chat,
    toolkit=toolkit,
    verbose=True,
    top_k=1000,
    max_execution_time=100,
    early_stopping_method="generate",
    agent='conversational-react-description', 
    memory=memory,
)

agent_executor.run("Can you describe the nested data table?")

### Expected behavior

I expected it to describe the table and its structure
[ElasticsearchStore] Enable custom Bulk Args
Labels: name: lgtm, name: area: vector store, name: auto:improvement

This enables bulk args like `chunk_size` to be passed down from the ingest methods (from_text, from_documents) to be passed down to the bulk API.

This helps alleviate issues where bulk importing a large amount of documents into Elasticsearch was resulting in a timeout.

Contribution Shoutout
- @elastic

- [x] Updated Integration tests
Add input/output schemas to runnables
Labels: name: auto:improvement, name: area: models

This adds `input_schema` and `output_schema` properties to all runnables, which are Pydantic models for the input and output types respectively. These are inferred from the structure of the Runnable as much as possible, the only manual typing needed is 
- optionally add type hints to lambdas (which get translated to input/output schemas)
- optionally add type hint to RunnablePassthrough

These schemas can then be used to create JSON Schema descriptions of input and output types, see the tests

- [x] Ensure no InputType and OutputType in our classes use abstract base classes (replace with union of subclasses)
- [x] Implement in BaseChain and LLMChain
- [x] Implement in RunnableBranch
- [x] Implement in RunnableBinding, RunnableMap, RunnablePassthrough, RunnableEach, RunnableRouter
- [x] Implement in LLM, Prompt, Chat Model, Output Parser, Retriever
- [x] Implement in RunnableLambda from function signature
- [x] Implement in Tool

<!-- 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.
 -->
ValueError Regarding Required Metadata Variables When Using RedisVectorStoreRetrieverWithScores
Labels: name: area: vector store, name: auto:bug, name: integration: redis

### System Info

LangChain version: **0.0.301**
**Python 3.9.6**
System Version: **macOS 13.5.2 (22G91)**
Kernel Version: **Darwin 22.6.0**

### Who can help?

@hwchase17 @agola11

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

I encountered a ValueError when using a custom Redis retriever (RedisVectorStoreRetrieverWithScores) with the SemanticDocumentSearch component in langchain. Below is the code snippet that reproduces the error:


```python
from langchain.vectorstores.redis.base import Redis, RedisVectorStoreRetriever
from langchain.chains import SemanticDocumentSearch
from langchain.schema import Document
from typing import List

class RedisVectorStoreRetrieverWithScores(RedisVectorStoreRetriever):
    def get_relevant_documents(self, query: str) -> List[Document]:
        docs_and_scores = self.vectorstore.similarity_search_with_score(query, k=self.search_kwargs["k"])
        for doc, score in docs_and_scores:
            doc.metadata = {**doc.metadata, **{"score": score}}
        return [doc for (doc, _) in docs_and_scores]

# Assuming initialization of redis_vector_store with necessary parameters
redis_retriever = RedisVectorStoreRetrieverWithScores(redis_vector_store)
semantic_search = SemanticDocumentSearch(retriever=redis_retriever)

# Error occurs when calling the following method
answer = semantic_search.get_answer("How are you?")

``` 
Error:

```python
Traceback (most recent call last):
  ...
ValueError: Document prompt requires documents to have metadata variables: ['source']. Received document with missing metadata: ['source'].

``` 

Steps to reproduce the behavior:

1. Implement a custom Redis retriever class RedisVectorStoreRetrieverWithScores inheriting from RedisVectorStoreRetriever.
2. Instantiate SemanticDocumentSearch with the custom Redis retriever.
3. Call the get_answer method of the SemanticDocumentSearch instance.

### Expected behavior

I expected the get_answer method to execute without errors and return a relevant answer based on the input query. However, a ValueError is thrown indicating a missing source metadata variable in the Document objects.

I am kindly seeking guidance on how to resolve this issue, and I am very thankful for any assistance or pointers provided. Thank you in advance for your time and help! 😊
BedrockChat has _astream missing
Labels: name: auto:bug, name: area: models

### System Info

After the latest [PR](https://github.com/langchain-ai/langchain/pull/10393/files#diff-9874347f7fa335df661ff4089b0922b3214e08a92e9879610424522f806358f7) it seems that the asynchronous streaming has been missing from libs/langchain/langchain/chat_models/bedrock.py. Why is that? The PR included it, while if you check the file it's not there.

Possible help? @agola11 

I'm using LangChain v0.0.301, Python 3.10.


### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

N/A, just check the files.

### Expected behavior

Async streaming available.
Callback integration for Trubrics
Labels: name: lgtm, name: auto:enhancement

Hello LangChain!

After contributing to some examples in the [langsmith-cookbook](https://github.com/langchain-ai/langsmith-cookbook) with  @hinthornw, here is a PR that adds a callback handler to use LangChain with [Trubrics](https://github.com/trubrics/trubrics-sdk).

Thanks
Refine chain using generator or custom callbacks
Labels: name: auto:improvement, name: stale, name: area: models

### Feature request

Here:
https://github.com/langchain-ai/langchain/blob/a2f7246f0eeafff29b63c90d45ec9e9eb6c21812/libs/langchain/langchain/chains/combine_documents/refine.py#L153C1-L153C1

And here:
https://github.com/langchain-ai/langchain/blob/a2f7246f0eeafff29b63c90d45ec9e9eb6c21812/libs/langchain/langchain/chains/combine_documents/refine.py#L202C14-L202C14

Just using iterator of the generator and `next()` to pick first document for initial LLM request and then for loop over same generator iterator to loop over the rest ones.
The most important is to provide previous response when iterating next Document.

Some callbacks system will also do, which will allow to decide whether to break from the loop and which will accept next document as response from that callback.

### Motivation

This will allow apps to decide which size next Document chunk should be, based on the received/generated response length.

Allowing to develop dynamic chunking based on previous response.

### Your contribution

I have implemented it, but via hacks, mix of python `magic` methods, imitating list operations in above langchain code and overriding _construct_refine_inputs method to read previous response to decide whether to break from the inside loop or not.
Issue: create_csv_agent return the half-unfinished response
Labels: name: area: agent, name: auto:bug, name: stale

### Issue you'd like to raise.

I have one csv file in which 1000 rows and 9 columns are available . When I asked to my agent, provide me the top 10 records, it returns half-unfinished response. 

```
from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain.agents.agent_types import AgentType
from langchain.agents import create_csv_agent

agent = create_csv_agent(
    OpenAI(openai_api_key="sk-xxxx",temperature=0.6),
    "pinecone_training with 1000 data.csv",
    verbose=True,
    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
print(agent.run("Please provide me the top 10 records."))
```

How can I get the complete finished response?

### Suggestion:

_No response_
Github toolkits create_file always return 404 when file does not exists
Labels: name: area: agent, name: auto:bug, name: stale

### System Info

Python 3.11.4
langchain 0.0.301
PyGithub 1.59.1

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

### Reproduction

1. Create a github repository with no README file, create a issue with title `Create README file` and content `Find what the most popular frontend framework is right now and add a short blurb to the readme.md file about how this website will take advantage of it.`. 
2. Run official example [Github Simple Agent](https://python.langchain.com/docs/integrations/toolkits/github#example-simple-agent).
```python
agent.run(
    "You have the software engineering capabilities of a Google Principle engineer. You are tasked with completing issues on a github repository. Please look at the existing issues and complete them."
)
```

3. Get run logs:
```text
> Entering new AgentExecutor chain...
 I need to figure out what issues need to be completed.
Action: Get Issues
Action Input: N/A
Observation: Found 1 issues:
[{'title': 'Create README file', 'number': 1}]
Thought: I need to create the README file
Action: Create File
Action Input: README.md
Observation: Unable to make file due to error:
404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/repos/contents#get-repository-content"}
Thought: I need to create the file in the repository
Action: Create File
Action Input: /test/README.md
Observation: Unable to make file due to error:
404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/repos/contents#get-repository-content"}
Thought: I need to create the file in the correct repository
Action: Create File
Action Input: <repository name>/test/README.md
Observation: Unable to make file due to error:
404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/repos/contents#get-repository-content"}
Thought: I need to make sure I am in the correct repository
Action: Get Issues
Action Input: N/A
Observation: Found 1 issues:
[{'title': 'Create README file', 'number': 1}]
Thought: I now know the correct repository and can create the file
Action: Create File
Action Input: <correct repository name>/test/README.md
Observation: Unable to make file due to error:
404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/repos/contents#get-repository-content"}
Thought:
...
```

### Expected behavior

Successfully create file README.md in repository.
Use embedding model downloaded from tensorflow hub
Labels: name: area: embeddings, name: auto:improvement, name: stale

### Issue you'd like to raise.

'from langchain.embeddings import TensorflowHubEmbeddings' has a model_url parameter to input the embedding model as a url, but I want to use the downloaded embedding model.

### Suggestion:

I would like to be able to embed text offline by using the downloaded tensorflow embedding model locally.
fix: short-circuit black and mypy calls when no changes made
Labels: name: auto:bug

Both black and mypy expect a list of files or directories as input. As-is the Makefile computes a list files changed relative to the last commit; these are passed to black and mypy in the `format_diff` and `lint_diff` targets. This is done by way of the Makefile variable `PYTHON_FILES`. This is to save time by skipping running mypy and black over the whole source tree.

When no changes have been made, this variable is empty, so the call to black (and mypy) lacks input files. The call exits with error causing the Makefile target to error out with:

```bash
$ make format_diff
poetry run black
Usage: black [OPTIONS] SRC ...

One of 'SRC' or 'code' is required.
make: *** [format_diff] Error 1
```

This is unexpected and undesirable, as the naive caller (that's me! 😄 ) will think something else is wrong. This commit smooths over this by short circuiting when `PYTHON_FILES` is empty. 

<!-- 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.
 -->
LangServe
Labels: name: auto:enhancement

Adds LangServe package

* Integrate Runnables with Fast API creating Server and a RemoteRunnable client
* Support multiple runnables for a given server
* Support sync/async/batch/abatch/stream/astream/astream_log on the client side (using async implementations on server)
* Adds validation using annotations (relying on pydantic under the hood) -- this still has some rough edges -- e.g., open api docs do NOT generate correctly at the moment
* Uses pydantic v1 namespace

Known issues: type translation code doesn't handle a lot of types (e.g., TypedDicts)
AnthropicFunctions with Bedrock
Labels: name: auto:enhancement, name: area: models, name: integration: aws

### Feature request

Hi, I'm using the Anthropic Claude V2 model through Amazon Bedrock. I'd like to submit a feature request for function calling simialr to `langchain_experimental.llms.anthropic_functions.AnthropicFunctions`



### Motivation

A large amount of people are using Anthropic's models through Bedrock

### Your contribution

Not sure
add tracer
Labels: name: auto:improvement

<!-- 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.
 -->