delayedkarma/langchain-issues huggingface dataset:
Added stop sequence support to replicate
Labels: name: auto:improvement

Stop sequences are useful if you are doing long-running completions and need to early-out rather than running for the full max_length... not only does this save inference cost on Replicate, it is also much faster if you are going to truncate the output later anyway. 

Other LLMs support stop sequences natively (e.g. OpenAI) but I didn't see this for Replicate so adding this via their prediction cancel method.

Housekeeping: I ran `make format` and `make lint`, no issues reported in the files I touched.

I did update the replicate integration test and ran `poetry run pytest tests/integration_tests/llms/test_replicate.py` successfully.

Finally, I am @tjaffri https://twitter.com/tjaffri for feature announcement tweets... or if you could please tag @docugami https://twitter.com/docugami we would really appreciate that :-)

Tagging model maintainers @hwchase17  @baskaryan 

Thank for all the awesome work you folks are doing.
DOC: Link broken for Python Guide on Prompts Page
Labels: name: auto:documentation

### Issue with current documentation:

The hyperlink which should navigate to the Python guide for Prompts seems to be broken.

Affected link -> https://docs.langchain.com/docs/components/prompts/

Click on the `Python Guide` link under the `info` section. It leads to `Page Not Found`.

![image](https://github.com/hwchase17/langchain/assets/50095990/6a008b08-60a1-4736-b45d-ee37f38e1664)


### Idea or request for content:

_No response_
Update SageMaker Endpoint Embeddings docs to be up to date with current requirements
Labels: name: lgtm, name: area: embeddings, name: auto:documentation

  - **Description:** Simple change of the Class that ContentHandler inherits from. To create an object of type SagemakerEndpointEmbeddings, the property content_handler must be of type EmbeddingsContentHandler not ContentHandlerBase anymore, 
  - **Maintainer:** @baskaryan
  - **Twitter handle:** @Juanjo_Torres11
Web research retriever
Labels: name: area: embeddings, name: auto:enhancement

Given a user question, this will -
* Use LLM to generate a set of queries.
* Query for each.
* The URLs from search results are stored in self.urls.
* A check is performed for any new URLs that haven't been processed yet (not in self.url_database). 
* Only these new URLs are loaded, transformed, and added to the vectorstore.
* The vectorstore is queried for relevant documents based on the questions generated by the LLM.
* Only unique documents are returned as the final result.

This code will avoid reprocessing of URLs across multiple runs of similar queries, which should improve the performance of the retriever. It also keeps track of all URLs that have been processed, which could be useful for debugging or understanding the retriever's behavior.
mv module integrations docs
Labels: name: area: doc loader, 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
SQL Query Prompt update + added _execute method for SQLDatabase
Labels: name: auto:improvement

 
- Description: This pull request (PR) includes two minor changes:

1. Updated the default prompt for SQL Query Checker: The current prompt does not clearly specify the final response that the LLM (Language Model) should provide when checking for the query if `use_query_checker` is enabled in SQLDatabase Chain. As a result, the LLM adds extra words like "Here is your updated query" to the response. However, this causes a syntax error when executing the SQL command in SQLDatabaseChain, as these additional words are also included in the SQL query. 

2. Moved the query's execution part into a separate method for  SQLDatabase: The purpose of this change is to provide users with more flexibility when obtaining the result of an SQL query in the original form returned by sqlalchemy. In the previous implementation, the run method returned the results as a string. By creating a distinct method for execution, users can now receive the results in original format, which proves helpful in various scenarios. For example, during the development of a tool, I found it advantageous to obtain results in original format rather than a string, as currently done by the run method.

- Tag maintainer: @hinthornw
Refactored `example_generator`
Labels: name: auto:refactor

Refactored `example_generator.py`. The same as #7961 
`example_generator.py` is in the root code folder. This creates the `langchain.example_generator: Example Generator ` group on the API Reference navigation ToC, on the same level as `Chains` and `Agents` which is not correct.

Refactoring:
- moved `example_generator.py` content into `chains/example_generator.py` (not in `utils` because the `example_generator` has dependencies on other LangChain classes. It also doesn't work for moving into `utilities/`)
- added the backwards compatibility ref in the original `example_generator.py`

@hwchase17
Refactored `env`
Labels: name: auto:refactor

Refactored `env.py`. The same as #7961 
`env.py` is in the root code folder. This creates the `langchain.env: Env ` group on the API Reference navigation ToC, on the same level as `Chains` and `Agents` which is not correct.

Refactoring:
- moved env.py content into utils/env.py
- added the backwards compatibility ref in the original `env.py`

@hwchase17
Human Tool with websocket 
Labels: name: auto:question

### Issue you'd like to raise.

How can i use Human Tool along with the websocket. As we cannot use async with tool.Can anyone please provide the solution for  this.

def please_take_test():
  score = 0
  for i, data in enumerate(questions):
    print(ask_for_info(data["question"], data["options"]))
    provided_answer = str(input())
    score += check_answer(provided_answer, data["answer"])

  first_prompt = ChatPromptTemplate.from_template(
        """You are the assisant to greet the user on the basis of score

 

        """
    )

  info_gathering_chain = LLMChain(llm=llm, prompt=first_prompt)
  ai_chat = info_gathering_chain.run(score = score)
  return ai_chat



Here I need this input() should be directly taken from the user interface 

### Suggestion:

_No response_
retrieve email metadata from email stored as pdf
Labels: name: area: doc loader, name: auto:enhancement

### Feature request

parse the text in a pdf to determine whether it contains header fields such as From:, To:, Date: etc which make it likely that the original data was an email. if so, return the contents of those fields as Document metadata which can, for example, be used as metadata in a database.

### Motivation

Sometimes it as important to know who said what to whom when as it is to determine what actual facts are. Investigative reporting is one example. There are adequate tools to retrieve email and its metadata from Gmail or Exchange. A similar tool for email which has been saved as a collection of PDFs which parses and retrieves the metadata will make these document collections more accessible and useful.

### Your contribution

I have created a pdf to email tool in the proper format to incorporated with existing langchain document loaders. It's at [https://github.com/tevslin/emailai](https://github.com/tevslin/emailai). If there's interest I will do the linting etc to submit as a pr.
Removing score threshold parameter of faiss _similarity_search_with_r…
Labels: name: area: vector store, name: auto:refactor

Removing score threshold parameter of faiss _similarity_search_with_relevance_scores as the thresholding part is implemented in similarity_search_with_relevance_scores method which calls this method. 

As this method is supposed to be a private method of faiss.py this will never receive the score threshold parameter as it is popped  in the super method similarity_search_with_relevance_scores.

@baskaryan @hwchase17
remove CVEs
Labels: name: auto:refactor

This PR aims to move all code with CVEs into `langchain.experimental`. Note that we are NOT yet removing from the core `langchain` package - we will give people a week to migrate here.

See MIGRATE.md for how to migrate

Zero changes to functionality

Vulnerabilities this addresses:

PALChain:
- https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAIN-5752409
- https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAIN-5759265

SQLDatabaseChain
- https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAIN-5759268

`load_prompt` (Python files only)
- https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAIN-5725807
add kwargs support for Baseten models
Labels: name: auto:bug

This bugfix PR adds kwargs support to Baseten model invocations so that e.g. the following script works properly:

```python
chatgpt_chain = LLMChain(
    llm=Baseten(model="MODEL_ID"),
    prompt=prompt,
    verbose=False,
    memory=ConversationBufferWindowMemory(k=2),
    llm_kwargs={"max_length": 4096}
)
```
Issue: OpenSearch painless scripting scoring function could be improved
Labels: name: area: vector store, name: auto:improvement

### Issue you'd like to raise.

Painless scripting shows an example scoring function here

https://opensearch.org/docs/latest/search-plugins/knn/painless-functions/#get-started-with-k-nns-painless-scripting-functions

You can see that they reference the query vector by `params.query_value`.  This is better, in my opinion than simply pasting it in as we do here
https://github.com/hwchase17/langchain/blob/17c06ee45634cafb9aa8fcd06848a4213b2d58e2/libs/langchain/langchain/vectorstores/opensearch_vector_search.py#L246

### Suggestion:

_No response_
YoutubeLoader to load documents from transcripts as chunks
Labels: name: area: doc loader, name: auto:improvement

### Feature request

Currently, The YoutubeLoader class loads transcripts and converts all of them into a single large piece of text loosing all the information regarding when it was said in the video to be able to reference it later.
I understand we cannot have very small/ unpridictable lengths of transcripts, which is why it would be great to chunk them according to a input duration by user and retain some information regarding when its said. which get the best of both worlds by having large enough data and also retaining context

### Motivation

I was trying to make a vedio qa retriever, Then I noticed how the transcripts were being loaded, I have also noticed this issue with other transcript loaders such as VTT, then I had to make my custom function to load the transcripts in chunks of duration that made sense to me, which lead me to making this issue

### Your contribution

I already have the code for chunking the transcripts, would love to submit a PR.
Issue #8089 Improve painless script scoring with params.query_value.
Labels: name: lgtm, name: area: vector store, name: auto:improvement

This is a minor improvement that replaces the full query_vector with the reference string `params.query_value` used in the painless scripting docs.  I have tested it manually and it works on an example.  This makes the query about half the size and much easier to read.

https://opensearch.org/docs/latest/search-plugins/knn/painless-functions/#get-started-with-k-nns-painless-scripting-functions

@babbldev 
#8089
Issue 8081 Fix query results size bug.  Other bug: pass vector_field param.
Labels: name: lgtm, name: area: vector store, name: auto:bug

@baskaryan
#8081 

Likely the reason why the issue occurred is that OpenSearch's default k is 10, so it needs to be specified.

Here's a similar question about its cousin ElasticSearch
https://discuss.elastic.co/t/elasticsearch-returns-only-10-records-but-the-hit-is-507/136605

I tested this manually and also fixed the same issue in `_default_painless_scripting_query`.  In addition,  `_default_painless_scripting_query` was not passing the `vector_field` name to a sub call, so I fixed that too.

![image](https://github.com/hwchase17/langchain/assets/32244272/cfb7aad1-f701-49d9-9beb-a723aa276817)

I also tested this in the aws opensearch developer tools.

![image](https://github.com/hwchase17/langchain/assets/32244272/24544682-1578-4bbb-9eb5-980463c5b41b)
fix api ref
Labels: 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
add kwargs support to Baseten LLMs
Labels: name: auto:bug

This bugfix PR adds kwargs support to Baseten model invocations so that e.g. the following script works properly:

```
chatgpt_chain = LLMChain(
    llm=Baseten(model="MODEL_ID"),
    prompt=prompt,
    verbose=False,
    memory=ConversationBufferWindowMemory(k=2),
    llm_kwargs={"max_length": 4096}
)
``
OpenSearchVectorStore's similarity search functions can't handle k>10 with script_scoring
Labels: name: area: vector store, name: auto:bug

### System Info

Langchain version 0.0.225
M1 Mac
Python 3.11.3

### Who can help?

@naveentatikonda 

### 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.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import OpenSearchVectorSearch
from opensearchpy import RequestsHttpConnection
from requests_aws4auth import AWS4Auth
import os

aws_auth = AWS4Auth(
    os.environ["AWS_ACCESS_KEY"], 
    os.environ["AWS_SECRET_KEY"],
    "us-east-1",
    "es"
)
embeddings = HuggingFaceEmbeddings(
    model_name="sentence-transformers/distiluse-base-multilingual-cased-v2",
    model_kwargs={'device': 'cpu'}
)
opensearch_vector_search = OpenSearchVectorSearch(
    os.environ["OPENSEARCH_URL"],
    "testindex",
    embeddings,
    http_auth=aws_auth,
    connection_class=RequestsHttpConnection,
)
texts = []
for i in range(1, 41):
    texts.append(f"This is document {i}")
opensearch_vector_search.add_texts(texts)

query = "This is a document"
search_result = opensearch_vector_search._raw_similarity_search_with_score(
    query,
    k=30,
    metadata_field="*",
    search_type="script_scoring"
)
print("Number of docs in response: ", len(search_result))
```
Output:
```
Number of docs in response:  10
```

When using script_scoring, the code does not pass a "size=k" option to the client query, so it returns a maximum of 10 hits by default.  Therefore, the user cannot receive more than 10 results regardless of the value of k.  I believe all that is necessary it to add a `size=k` parameter to line 537 in `opensearch_vector_search.py`, and then the `[:k]` in line 539 is superfluous.

### Expected behavior

The above code should produce 30 results, not 10.
Calling the OpenAI Functions agent with an empty tool list crashes
Labels: name: area: agent, name: auto:bug

### System Info

langchain version 0.0.238
openai version 0.27.8

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

### Reproduction

Set up your Open AI keys in your .env file then run this python script:

```py
from dotenv import load_dotenv

from langchain.agents import initialize_agent, AgentType
from langchain.chat_models import ChatOpenAI

load_dotenv()

llm = ChatOpenAI(model_name="gpt-3.5-turbo")

agent = initialize_agent(
    tools=[],
    llm=llm,
    agent=AgentType.OPENAI_FUNCTIONS
)

agent.run("Hello World!")
```

### Expected behavior

The agent should be run successfully and just not be able to use any tools if none are provided. This does happen if the functions parameter is not passed to the openai interface when its empty. So should be an easy fix:
1. Detect if the tools list is empty
2. Only pass the function parameter to the openai interface if its not empty

The interface call in question (`langchain/chat_models/openai.py` in line 319):
```py
        @retry_decorator
        def _completion_with_retry(**kwargs: Any) -> Any:
            return self.client.create(**kwargs) # <-- HERE, just filter out key functions if empty
```
Fix InvalidVectorQuery error
Labels: name: area: vector store, name: auto:bug

- Description:  Fixed the InvalidVectorQuery error in several functions of the AzureSearch class in azuresearch.py. The changes were based on the code found in [this Azure cognitive-search-vector-pr sample](https://github.com/Azure/cognitive-search-vector-pr/blob/main/demo-python/code/azure-search-vector-recall-python-sample.ipynb).
- Issue:  This addresses an observed InvalidVectorQuery error when using AzureSearch with vectors.
- Dependencies: With this fix, the import `from azure.search.documents.models import Vector` is no longer necessary and has been removed.
- Tag maintainer: @rlancemartin, @eyurtsev
- Issue: #7841
bump 239
Labels: name: release, name: auto:nit

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Change with_history option to False for ChatGLM by default
Labels: name: lgtm, name: auto:improvement

ChatGLM LLM integration will by default accumulate conversation history(with_history=True) to ChatGLM backend api, which is not expected in most cases. This PR set with_history=False by default, user should explicitly set llm.with_history=True to turn this feature on.  Related PR: #8048 #7774 

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Issue: <Please write a comprehensive title after the 'Issue: ' prefix>
Labels: name: area: vector store, name: auto:documentation

### Issue you'd like to raise.

This is that the documentation has to be improved 

from langchain.indexes.vectorstore import VectorstoreIndexWrapper

to from langchain.indexes.vectorstore import VectorStoreIndexWrapper

<img width="762" alt="image" src="https://github.com/hwchase17/langchain/assets/32350453/7ef0656c-69ca-4f09-bc49-fb4230eaf93a">


### Suggestion:

edit this **from langchain.indexes.vectorstore import VectorstoreIndexWrapper**

to **from langchain.indexes.vectorstore import VectorStoreIndexWrapper**