delayedkarma/langchain-issues huggingface dataset:
fix(embeddings): define task using parameters instead of json payload for HuggingFaceHubEmbeddings
Labels: name: area: embeddings, name: auto:bug, name: size:XS

 **Description:** This pull request explicitly defines the task of an embedding feature extraction. The current issue is the default task for models like `sentence-transformers/all-mpnet-base-v2`, is not `feature-extraction` and when running `HuggingFaceHubEmbeddings` causes an error `SentenceSimilarityInputsCheck expected dict not list`.
 
  **Issue:** By explicitly defining the task as `feature-extraction` as per [Inference documentation](https://huggingface.co/docs/huggingface_hub/v0.19.3/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient.post), it ensures `HuggingFaceHubEmbeddings` is using the right task. Passing the task as a json payload does not work.

Here's the problem,
```
embeddings = HuggingFaceHubEmbeddings(
    model="sentence-transformers/all-mpnet-base-v2",
    task="feature-extraction",
    huggingfacehub_api_token=os.getenv("HF_TOKEN"),
)
embeddings.embed_query("Hello Langchain!")
```

Error:

```
Bad request:
SentenceSimilarityInputsCheck expected dict not list: `__root__` in `parameters`
```

From [huggingface_hub.py](https://github.com/langchain-ai/langchain/blob/d9bfdc95ea9e37b88cdfe7c2baef51ad52713463/libs/langchain/langchain/embeddings/huggingface_hub.py#L95), a simplified problem and fix.

Current, task passed as json payload:
```
client.post(json={"inputs": text, "task": "feature-extraction"})
```

Fix, task passed explicitly:
```
client.post(json={"inputs": text}, task="feature-extraction")
```

The final fix is in the pull request.
```
responses = self.client.post(
    json={"inputs": texts, "parameters": _model_kwargs},
    task=self.task
)
```

 
 **Dependencies:** None
 **Tag maintainer:** @hwchase17
 **Twitter handle:** @randyphoa

<!-- 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/langchain-ai/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.
 -->
VertexAI classs doesn't support request_timeout
Labels: name: auto:bug, name: area: models

### System Info

langchain==0.0.335

### Who can help?

@hwchase17 @agol

### Information

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

### Related Components

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

1. Create new object of `langchain.llms.vertexai.VertexAI` class.
2. Add attribute `request_timeout` with some value.
3. Run the model. Timeout specified is not respected.

### Expected behavior

VertexAI request should timeout as per the `request_timeout` specified and then retried as per retry configuration. This works flawlessly for `AzureChatOpenAI`.
DOC: Need clarity on Pinecone.from_documents and OpenAIEmbeddings.
Labels: name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:question, name: auto:documentation, name: integration: pinecone

### Issue with current documentation:

Hi,

I'm trying to understand _**Pinecone.from_documents**_ as shown [here ](https://python.langchain.com/docs/integrations/vectorstores/pinecone). 

I saw it used the same way in another tutorial as well and it seems like it should be calling OpenAIEmbeddings.embed_documents at some point and then upserting the texts and vectors to the pinecone index, but I can't find the actual python file for the method or any documentation anywhere.

I'm trying to adapt it and need to understand how **_from_documents_** works.  Specifically I am trying to do the following and am curious if the method could be used in this way

My goals:

- Use Pinecone.from_documents(documents, embeddings, index_name=index_name, namespace=namespace) in a for loop where in each iteration namespace change and the "chunked" documents are different. Each namespace represents a different chunking strategy for an experiment.

Note that I defined embeddings=OpenAIEmbeddingsWrapper(model=embedding_model_name) before the for loop, where  OpenAIEmbeddingsWrapper is a wrapper class around the OpenAIEmbeddings object, and embedding_model_name="text-embedding-ada-002".


Why I'm asking: 
- It seems like the number of texts and vectors that I can extract from OpenAIEmbeddingsWrapper (using the OpenAIEmbeddings.embed_documents method) for each namespace doesn't match what's in Pinecone (610 texts/vectors from the method vs 1251 in Pinecone).

### Idea or request for content:

Can you share some details about Pinecone.from_documents and if it can be used multiple times to upsert chunk documents onto a pinecone index?
DeprecationWarning: `input_variables' is deprecated and ignored
Labels: name: auto:bug, name: area: models

### System Info

langchain==0.0.346

### Who can help?

@hwch

### Information

- [ ] The official example notebooks/scripts
- [ ] 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
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

https://github.com/langchain-ai/langchain/pull/14266 added a deprecation for `input_variables` argument of `PromptTemplate.from_file`. It was released in 0.0.346.

However, https://github.com/langchain-ai/langchain/blob/v0.0.346/libs/langchain/langchain/chains/llm_summarization_checker/base.py#L20-L31 still uses `input_variables` at the module-level. So now this `DeprecationWarning` is emitted simply for importing from LangChain.

Can we fix this, so LangChain isn't emitting `DeprecationWarning`s?

### Expected behavior

I expect LangChain to not automatically emit `DeprecationWarning`s when importing from it
SmartLLMChain Output Key Customization
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:XS

**Description**
The `SmartLLMChain` was was fixed to output key "resolution". Unfortunately, this prevents the ability to use multiple `SmartLLMChain` in a `SequentialChain` because of colliding output keys. This change simply gives the option the customize the output key to allow for sequential chaining. The default behavior is the same as the current behavior.

Now, it's possible to do the following:
```
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain_experimental.smart_llm import SmartLLMChain
from langchain.chains import SequentialChain

joke_prompt = PromptTemplate(
    input_variables=["content"],
    template="Tell me a joke about {content}.",
)
review_prompt = PromptTemplate(
    input_variables=["scale", "joke"],
    template="Rate the following joke from 1 to {scale}: {joke}"
)

llm = ChatOpenAI(temperature=0.9, model_name="gpt-4-32k")
joke_chain = SmartLLMChain(llm=llm, prompt=joke_prompt, output_key="joke")
review_chain = SmartLLMChain(llm=llm, prompt=review_prompt, output_key="review")

chain = SequentialChain(
    chains=[joke_chain, review_chain],
    input_variables=["content", "scale"],
    output_variables=["review"],
    verbose=True
)
response = chain.run({"content": "chickens", "scale": "10"})
print(response)
```
Issue: llama2-sql for long queries doesn't return the complete query.
Labels: name: auto:bug, name: area: models

### Issue you'd like to raise.

Hi, I'm using the llama2 model for SQL, and I modified it to work directly using LLM. I also added more tables to test the model, and I'm modifying the prompt. When I do this, it generates longer queries based on the question I send, but when the query is very long, it doesn't complete generating everything. I checked the response character count, and on average, it returns around 400+- maximum response characters (I tried increasing and removing the character limit, but it didn't solve the problem). 
llm = Replicate(
    model=llama2_13b,
    input={"temperature": 0.1, 
            "max_length": 2000,  

Incorrect return type. 
Retrieve the performance of Miles Norris in his most recent game.
```sql
SELECT pg_player_game_stats.Points, pg_player_game_stats.Rebounds, pg_player_game_stats.Assists 
FROM nba_roster_temp 
JOIN player_game_stats ON nba_roster_temp."PlayerID" = player_game_stats."PlayerID" 
WHERE nba_roster
As you can see, the SQL query it returns is incomplete, and here I'm also counting the number of characters.
number character: 401

Any help you can provide would be appreciated

### Suggestion:

_No response_
When using OpenAI Function Calling, change default model in ChatOpenAI
Labels: name: auto:improvement, name: area: models, name: size:XS

  - **Description:** : After reviewing the OpenAI Function Calling official guide at https://platform.openai.com/docs/guides/function-calling,  the following information was noted:

> "The latest models (gpt-3.5-turbo-1106 and gpt-4-1106-preview) have been trained to both detect when a function should be called (depending on the input) and to respond with JSON that adheres to the function signature more closely than previous models. With this capability also comes potential risks. We strongly recommend building in user confirmation flows before taking actions that impact the world on behalf of users (sending an email, posting something online, making a purchase, etc)."

Therefore, I have updated the default model in ChatOpenAI from 'gpt-3.5-turbo' to 'gpt-3.5-turbo-1106' only when function calling is used and no specific model is designated by the user.
Bagatur/community no openai
Labels: name: area: agent, name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:enhancement, name: size:XXL

<!-- 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/langchain-ai/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.
 -->
docs: add missing imports for local_llms
Labels: name: lgtm, name: auto:documentation, name: area: models, name: size:XS

<!-- 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/langchain-ai/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.
 -->
Keeping it consistent with everywhere else in the docs and adding the missing imports to be able to copy paste and run the code example.
Andrewreed
Labels: name: auto:enhancement, name: auto:documentation, name: area: models, name: size:XL

<!-- 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/langchain-ai/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.
 -->
Corrected the argument alias from 'base_store' to 'docstore'
Labels: name: lgtm, name: area: doc loader, name: auto:documentation, name: size:XS

  - **Description:** The sample code in the documentation about MultiVectorRetriever throws an error. The reason is an incorrect reference to an argument alias (`base_store` instead of `docstore`) The definition of the MultiVectorRetriever class shows that the correct argument alias is `docstore`. This fixes the error.,
Web Scraping with ChatOllama gives SSL: WRONG_VERSION_NUMBER 
Labels: name: auto:bug, name: auto:question, name: area: models

### Issue you'd like to raise.

Hi, I'm trying to implement the [web scraping tutorial ](https://python.langchain.com/docs/use_cases/web_scraping#llm-with-function-calling) using ChatOllama instead of ChatOpenAI.

This is what I'm trying to do:

```
import pprint

from langchain.chains import create_extraction_chain
from langchain.document_loaders import AsyncChromiumLoader
from langchain.document_transformers import BeautifulSoupTransformer
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.chat_models import ChatOllama


def extract(content: str, schema: dict, llm):
    return create_extraction_chain(schema=schema, llm=llm).run(content)


def scrape_with_playwright(urls, schema, llm):
    loader = AsyncChromiumLoader(urls)
    docs = loader.load()
    bs_transformer = BeautifulSoupTransformer()
    docs_transformed = bs_transformer.transform_documents(
        docs, tags_to_extract=["span"]
    )
    print("Extracting content with LLM")

    # Grab the first 1000 tokens of the site
    splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
        chunk_size=1000, chunk_overlap=0
    )
    splits = splitter.split_documents(docs_transformed)

    # Process the first split
    extracted_content = extract(schema=schema, content=splits[0].page_content, llm=llm)

    return extracted_content


if __name__ == '__main__':
    llm = ChatOllama(base_url="https://localhost:11434", model="llama2")

    schema = {
        "properties": {
            "news_article_title": {"type": "string"},
            "news_article_summary": {"type": "string"},
        },
        "required": ["news_article_title", "news_article_summary"],
    }

    urls = ["https://www.wsj.com"]
    extracted_content = scrape_with_playwright(urls, schema=schema, llm=llm)

    pprint.pprint(extracted_content)

```
Instead of the results shown I get this error: `requests.exceptions.SSLError: HTTPSConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1006)')))` when the `extract` function is called.

Could anyone please help me understand what I'm doing wrong? Thanks!

### Suggestion:

_No response_
Fix: redundant casting to SecretStr API keys
Labels: name: auto:improvement, name: area: models, name: size:L

  - **Description:** This PR serves as standardization of the masking and testing.
  - Some API keys were not really masked when stored in the `values` dict. They should be masked and cast back to string only during the `POST` request. I fixed 1 occurance of this.
  - Some tests were not covering this flaw because they were repeating the back-and-forth pattern of casting to `SecretStr` and invoking `.get_secret_value()` immediately. This pattern is confusing, and in order to clear this out I added an `extract_secret_str : SecretStr | Str | None -> str` method.
  - The code-base was filled with `secretstr, secret_str, secret_string` names. I replaced all of them with `secretstr`.
  - **Issue:** fixes https://github.com/langchain-ai/langchain/issues/14445, related https://github.com/langchain-ai/langchain/issues/12165
  - **Dependencies:** None
  - **Tag maintainer:** @eyurtsev @hwchase17
Issue: Flawed implementations of SecretStr for API keys
Labels: name: auto:bug, name: area: models

During the recent initiative to secure API keys with `SecretStr` (https://github.com/langchain-ai/langchain/issues/12165), some implementations and their corresponding tests were implemented with some flaws. More specifically, they were not really masking the API key.

For instsance, in `libs/langchain/langchain/chat_models/javelin_ai_gateway.py` we have:
```
    @property
    def _default_params(self) -> Dict[str, Any]:
        params: Dict[str, Any] = {
            "gateway_uri": self.gateway_uri,
            "javelin_api_key": cast(SecretStr, self.javelin_api_key).get_secret_value(),
            "route": self.route,
            **(self.params.dict() if self.params else {}),
        }
        return params
```
In the above snippet, `self.javelin_api_key` is cast to `SecretStr`, and then immediately `.get_secret_value()` is invoked, essentially retrieving the original string. Note that Javelin chat lacks unit tests. This could be used to handle the case where the API key is `None`, but then it might appear like there's no masking and it's preferable to address the `None` case directly.

It's worth noting that this pattern is repeated in tests, such as in `libs/langchain/tests/integration_tests/chat_models/test_baiduqianfan.py`:
```
def test_uses_actual_secret_value_from_secret_str() -> None:
    """Test that actual secret is retrieved using `.get_secret_value()`."""
    chat = QianfanChatEndpoint(
        qianfan_ak="test-api-key",
        qianfan_sk="test-secret-key",
    )
    assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key"
    assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key"
```

The point of the test would be to assert that the API key is indeed a secret, and not just cast it back and forth.
Let me point out that the test suite for baiduqianfan chat does indeed catch whether the API key is indeed masked with a `SecretStr` by capturing the stdout.

@eyurtsev @hwchase17 

### Suggestion:

PR to fix the issues
Update with new VertexAIModelGarden output format
Labels: name: auto:improvement, name: area: models, name: size:M

On December 1st, the Google Cloud Vertex AI Model Garden models runtime received an update in the form of `Prompt:\n\t{prompt}\nOutput:\n\t{prompt}` and now streams tokens throughout the second level list.

This change will break the current behavior of your applications if adequate fixes are not applied.
We are promoting these changes based on our experiences with LLaMA, Falcon, Mistral, and additional models that are distributed directly by Vertex AI Model Garden.

Probably fixes #13370 #10012
Issue: Opensearch manually assigned shards and replicas while using vector_db.add_text(page_contents,metatas)
Labels: name: area: vector store, name: auto:question, name: auto:improvement, name: integration: elasticsearch

### Issue you'd like to raise.

Hello Team,
We are using opensearch vectordb to store the embeddings, then we are using these embeddings to retrieve the similar document during conversastnal retrieval. while checking the settings of the index created by vector_db.add_text(page_content,metadatas). i have seen the number_of_replicas as 5 and shards as 1(this is the default behaviour of vector_db.add_text(page_content,metadats)

**I want to pass as number_of_replicas as 1** and shards as 1 whenever the index is created on opensearch. Can you please help me with this, how can i custom pass this replicas value. Also i am adding code for better understanding below

In the below code if u see the **langchain vector_db.add_text() in Line 109** creating a index with 5 shards by default. i just want to pass this parameter manually lets say 1 shard. Can u please help me out here. Please let me know if you want any more info to understand my issue.
![langchain_num_shard](https://github.com/langchain-ai/langchain/assets/34799343/453e20f7-15c3-4aa5-a862-398696037b0f)


### Suggestion:

_No response_