delayedkarma/langchain-issues huggingface dataset:
added template repo for CI/CD deployment on Google Cloud Run
Labels: name: lgtm, name: auto:enhancement, name: auto:documentation

Replace this comment with:
  - Description: added documentation for a template repo that helps dockerizing and deploying a LangChain using a Cloud Build CI/CD pipeline to Google Cloud build serverless
  - Issue: None,
  - Dependencies: None,
  - Tag maintainer: @baskaryan,
  - Twitter handle: EdenEmarco177

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.
Add retries to VertexAI models
Labels: name: auto:improvement

### Feature request

Add retry policy to VertexAI models.

### Motivation

E.g., when trying to run a summarization chain on many chunks (I reproduce the error with 99 chunks), an exception `ResourceExhausted: 429 Quota exceeded` might be returned by Vertex. 

### Your contribution

yes, I'll submit a PR shortly.
DOC: DOCUMENT interface in Javascript but not in Python
Labels: name: auto:question, name: auto:documentation

### Issue with current documentation:

More of a clarification than an issue. In the javascript documentation, it describes the Document interface. https://js.langchain.com/docs/modules/schema/document. Does an equivalent thing exist in the Python version. When I try 'from langchain.document import Document` in python, it throws an error?

### Idea or request for content:

_No response_
Remove extra base model
Labels: name: lgtm, name: auto:improvement

<!-- 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!

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
 -->
Update scenexplain.py to use new API endpoint
Labels: name: lgtm, name: auto:bug

  - Description: Update SceneXplain API endpoint URL (taken from official docs: https://scenex.jina.ai/api)
  - Issue: The old sceneXplain API endpoint: "https://us-central1-causal-diffusion.cloudfunctions.net/describe" is deprecated and now returns 500 internal error codes.
  - Dependencies: N/A
  - Tag maintainer: @hinthornw
  - Twitter handle: @deoxykev
Master test build
Labels: name: auto:enhancement, name: auto:documentation

<!-- 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!

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
 -->
Undesired outputs when using map_reduce
Labels: name: auto:bug

### System Info

There seem to be some hallucinations involving the president and Michael Jackson. 
I use the following, where `data` is loaded using `UnstructuredURLLoader(urls).load()` and `urls` is just a list of URLs I'm interested in. Needless to say that none of the URLs involve Michael Jackson (or the president, for that matter)


### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [X] Prompts / Prompt Templates / Prompt Selectors
- [X] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
chain = RetrievalQAWithSourcesChain.from_chain_type(
            llm= HuggingFaceHub(
                    repo_id="tiiuae/falcon-7b-instruct",
                    model_kwargs={"max_new_tokens": 500}
                ),
            chain_type="map_reduce",
            retriever=FAISS.from_documents(doc_splitter.split_documents(data), 
                                           HuggingFaceEmbeddings()).as_retriever()
        )
```
followed by
```
prompt = "some text unrelated to Michael Jackson."
chain({"question": prompt}, return_only_outputs=True)
```

I believe this occurs as part of the `map_reduce.py` file:
```
        result, extra_return_dict = self.reduce_documents_chain.combine_docs(
            result_docs, callbacks=callbacks, **kwargs
        )
```

### Expected behavior

should have provided some answer w.r.t to the provided data, stored in FAISS vectorbase
fix: missing parameter in POST/PUT/PATCH HTTP requests
Labels: name: auto:bug

<!-- 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!

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
 -->
@hinthornw
ConversationalRetrievalChain return only the prompt not the answer
Labels: name: auto:bug

### System Info

**Python : Python 3.9.13
Langchain: langchain==0.0.219
OS : Ubuntu**

### 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

```
    from langchain.chains import ConversationalRetrievalChain
    from langchain.vectorstores import Chroma
    from langchain.embeddings import SentenceTransformerEmbeddings
    embeddings =  SentenceTransformerEmbeddings(model_name="paraphrase-MiniLM-L6-v2")
    from langchain.document_loaders import PyPDFLoader
    loader = PyPDFLoader("file.pdf")
    documents = loader.load()
    from langchain.llms import HuggingFaceHub
    model = HuggingFaceHub(repo_id="facebook/mbart-large-50",
                       model_kwargs={"temperature": 0, "max_length":200},
                       huggingfacehub_api_token=HUGGING_FACE_API_KEY)
    from langchain.text_splitter import CharacterTextSplitter
    text_splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=0)
    texts=text_splitter.split_documents(documents)
    db = Chroma.from_documents(texts, embeddings)
    retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 1})
    qa = ConversationalRetrievalChain.from_llm(model,retriever)
    chat_history= []
    query = "sample query"
    result = qa({"question": query,"chat_history":chat_history})
    print("\nResult of ConversationalRetrievalChainMethod")
    print(result)
```


It return the **result** as follows
{'question': 'sample question', 'chat_history': [], '**answer': "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.**"}

### Expected behavior

Expecting the answer in the result. But it returns the prompt itself now
kwargs are forgot to send to huggingface pipeline call
Labels: name: auto:bug

https://github.com/hwchase17/langchain/blob/e27ba9d92bd2cc4ac9ed7439becb2d32816fc89c/langchain/llms/huggingface_pipeline.py#L169

should modified to 
#response = self.pipeline(prompt)
response = self.pipeline(prompt, **kwargs)
Issue: <Please write a comprehensive title after the 'Issue: ' prefix>
Labels: name: auto:bug

### Issue you'd like to raise.

When using AgentType.OPENAI_FUNCTIONS, the error message "openai.error.InvalidRequestError: 'Gmail: Find Email' does not match '^[a-zA-Z0-9_-]{1,64}$' - '[functions.6.name](http://functions.6.name/)'" suggests that the name you are using for the function ('Gmail: Find Email') does not adhere to the naming conventions.

For AgentType.OPENAI_FUNCTIONS, function names can only contain alphanumeric characters, underscores (_), and hyphens (-). The name must be between 1 and 64 characters long.

To resolve this issue, make sure the name you provide for the function complies with the naming rules mentioned above.

If you need further assistance, please provide more details about the specific function you're trying to use, and I'll be happy to help you further.

### Suggestion:

_No response_
Issue: Missing some input keys: {'question'} when using ConversationalRetrievalChain
Labels: name: auto:bug

### Issue you'd like to raise.

I have written a code to add the memory to ConversationalRetrievalChain but I am getting an error **"Missing some input keys: {'question'}"**. Below is the snippet of my code

    memory = ConversationBufferMemory(
                memory_key="chat_history",
                input_key="question"
            )

    chatTemplate = """
    Answer the question based on the chat history(delimited by <hs></hs>) and context(delimited by <ctx> </ctx>) below.
    -----------
    <ctx>
    {context}
    </ctx>
    -----------
    <hs>
    {chat_history}
    </hs>
    -----------
    Question: {question}
    Answer: 
    """

    promptHist = PromptTemplate(
        input_variables=["context", "question", "chat_history"],
        template=chatTemplate
    )

    retriever = chatDb.as_retriever(search_type="similarity", search_kwargs={"k": 2})

    qa = ConversationalRetrievalChain.from_llm(
        llm=get_openai_model(), chain_type="stuff", retriever=retriever, return_source_documents=True,
        verbose = True,
        combine_docs_chain_kwargs={'prompt': promptHist},
        memory = memory,
    )

    result = qa({"query": prompt["prompt"]})

### Suggestion:

_No response_
Load Chroma database: Invalid Input Error: No magic bytes found at end of file 'database/vectors/chroma-embeddings.parquet'
Labels: name: auto:bug

### System Info

Python 3.11.4
duckdb==0.8.1
chromadb==0.3.26
langchain==0.0.221


### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

I persisted my Chroma database in a EC2 instance, where I have all these files:
chroma-collections.parquet  
chroma-embeddings.parquet  
index/

I download these files for testing the database in my local machine, but I got the error:

> Invalid Input Error: No magic bytes found at end of file 'database/vectors/chroma-embeddings.parquet'

When I tried to: 

```
from langchain.vectorstores import Chroma
db = Chroma(embedding_function=embedding_function, 
                         persist_directory=persist_directory,
                         collection_name=collection_name) 
```

Can I download these persisted files and test them on another machine?


### Expected behavior

To read all the embeddings
DOC: https://python.langchain.com/docs/modules/model_io/models/llms/integrations/sagemaker
Labels: name: auto:bug, name: auto:documentation

### Issue with current documentation:
https://python.langchain.com/docs/modules/model_io/models/llms/integrations/sagemaker

This example is not working. I've just copy pasted the code from here and ran it in my notebook instance. I'm using falcon-40b-instruct model. 

The error I'm getting is as follows
Error raised by inference endpoint: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (422) from primary with message "Failed to deserialize the JSON body into the target type: missing field `inputs` at line 1 column 509".


### Idea or request for content:

_No response_
make textstat optional in the flyte callback handler
Labels: name: auto:improvement

<!-- 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!

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 PR makes the `textstat` library optional in the Flyte callback handler.

@hinthornw, would you mind reviewing this PR since you merged the flyte callback handler code previously?
optimize pgvector `add_texts`
Labels: name: auto:improvement

- Description: At the moment, inserting new embeddings to pgvector is querying all embeddings every time as the defined `embeddings` relationship is using the default params, which sets `lazy="select"`. This change drastically improves the performance and adds a few additional cleanups:
  * remove `collection.embeddings.append` as it was querying all embeddings on insert, replace with `collection_id` param
  * centralize storing logic in add_embeddings function to reduce duplication
  * remove boilerplate

- Issue: No issue was opened.
- Dependencies: None.
- Tag maintainer: this is a vectorstore update, so I think @rlancemartin, @eyurtsev
- Twitter handle: @falmannaa
Issue: RetrievalQAWithSourcesChain gives error 'too many values to unpack (expected 2)' after running.
Labels: name: auto:bug, name: auto:question

Hello,

I'm using _langchain_ for QA with court case documents. More specifically, the RetrievalQAWithSourcesChain to retrieve the answer and document source information. However, when running the chain with embedded documents, I get the following error:

```
ValueError: too many values to unpack (expected 2)
Traceback:


    response = qa({"question": pregunta}, return_only_outputs=True)
File "C:\Anaconda3\envs\iagen_3_10\lib\site-packages\langchain\chains\base.py", line 166, in __call__
    raise e
File "C:\Anaconda3\envs\iagen_3_10\lib\site-packages\langchain\chains\base.py", line 160, in __call__
    self._call(inputs, run_manager=run_manager)
File "C:\Anaconda3\envs\iagen_3_10\lib\site-packages\langchain\chains\qa_with_sources\base.py", line 132, in _call
    answer, sources = re.split(r"SOURCES:\s", answer)

```

The passed documents are the sections from the court case. I added the following **metadata** fields:

1. Source: PDF file name.
2. Section: Name of the section
3. Section_chunk:  Numeral value used for identification in case the section was divided into chunks.
4. Page: Page where the section chunk starts.

The documents are passed as retriever to the chain with FAISS (FAISS.from_documents(documents, self.embeddings)).

I tried out two approaches (both resulting in the same error): 
1. providing the _load_qa_chain_ as chain 
2. creating it using the class method **_.from_chain_type_**

My question is why does this error ocurrs. And also, if the type of metadata used may cause the errors.
Thank you in advance!
Add docs for setting MapReduceChain token_max arg
Labels: name: auto:documentation

- Description: Add docs on how to set and use the token_max arg for MapReduceChains
- Issue: Several issues have been repeatedly raised regarding this, since it is non-intuitive how to pass this arg. This makes usage with larger models such as gpt-3.5-turbo-16k much easier. I also explain how it's a sliding scale between how much the inputs will be summarized vs tokens left for generation.
- Tag maintainer: @baskaryan @hwchase17
- Twitter handle: More PRs incoming! :) https://twitter.com/ShantanuNair

Related Github discussion: https://github.com/hwchase17/langchain/discussions/2746
Related issues: https://github.com/hwchase17/langchain/issues/1349, https://github.com/hwchase17/langchain/issues/7043, https://github.com/hwchase17/langchain/issues/434, https://github.com/hwchase17/langchain/issues/6397, https://github.com/hwchase17/langchain/issues/6714, https://github.com/hwchase17/langchain/issues/6191
does llms.AzureOpenAI support gpt4 or gpt-32k?
Labels: name: auto:bug, name: auto:question

### System Info


llm = AzureOpenAI(
model_name="gpt-4-32k",
engine="gpt-4-32k"
)
llm("tell me a joke")
Exception:
The completion operation does not works with the specific model, gpt-4-32k, pls choose different model....

Environment:
LangChain:0.0.218

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

### Reproduction

Environment:
LangChain:0.0.218


llm = AzureOpenAI(
model_name="gpt-4-32k",
engine="gpt-4-32k"
)
llm("tell me a joke")
run the code above

### Expected behavior

the program should work
fix: prevent adding an empty string to the result queue in AsyncIteratorCallbackHandler
Labels: name: lgtm, name: auto:bug

- Description: Modify the code for AsyncIteratorCallbackHandler.on_llm_new_token to ensure that it does not add an empty string to the result queue.
- Tag maintainer: @agola11

When using AsyncIteratorCallbackHandler with OpenAIFunctionsAgent, if the LLM response function_call instead of direct answer, the AsyncIteratorCallbackHandler.on_llm_new_token would be called with empty string.
see also: langchain.chat_models.openai.ChatOpenAI._generate

An alternative solution is to modify the langchain.chat_models.openai.ChatOpenAI._generate and do not call the run_manager.on_llm_new_token when the token is empty string.
I am not sure which solution is better.

@hwchase17
SupabaseVectorStore.from_documents returns APIError: {'code': '22P02'
Labels: name: auto:bug

### System Info

Langchain version: 0.0.221

### Who can help?

_No response_

### Information

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

### Related Components

- [ ] LLMs/Chat Models
- [X] 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

When trying to index documents return API error
`APIError: {'code': '22P02', 'details': None, 'hint': None, 'message': 'invalid input syntax for type bigint: "54d7bd9c-9822-40ca-ade6-ae173b65d34e"'}`

This code perfectly worked on previous versions of Langchain. 
After upgrading, got the error. 

Supabase backend didn't change.

`
# load required libraries
from langchain.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import SupabaseVectorStore
from supabase import Client, create_client
import os
from dotenv import load_dotenv

# load document from web
url = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/supabase"
loader = WebBaseLoader(url)
documents = loader.load()

# split documents into chunks
docs_splitter = RecursiveCharacterTextSplitter(chunk_size=2500,chunk_overlap=250)
splitted_docs = docs_splitter.split_documents(documents=documents)

# initialize embeddings model
embeddings = OpenAIEmbeddings()

# initialize vector store
supabase_url = os.getenv('SUPABASE_URL')
supabase_key = os.getenv('SUPABASE_KEY')
supabase = create_client(supabase_url, supabase_key)

# save values to supabase
vector_store = SupabaseVectorStore.from_documents(documents=splitted_docs, embedding=embeddings, client=supabase)
`

### Expected behavior

document embeddings should be saved in a Supabase database
Fix: Recognize `List` at `from_function`
Labels: name: lgtm, name: auto:bug

  - Description: pydantic's `ModelField.type_` only exposes the native data type but not complex type hints like `List`. Thus, generating a Tool with `from_function` through function signature produces incorrect argument schemas (e.g., `str` instead of `List[str]`)
  - Issue: N/A
  - Dependencies: N/A
  - Tag maintainer: @hinthornw
  - Twitter handle: `mapped`

All the unittest (with an additional one in this PR) passed, though I didn't try integration tests...