delayedkarma/langchain-issues huggingface dataset:
Neo4J keyword index creation problem
Labels: name: area: vector store, name: auto:bug, name: auto:improvement

### System Info

Name: langchain
Version: 0.0.320

### Who can help?

@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

When you try the tutorial:

```
index_name = "vector"  # default index name
keyword_index_name = "text_index"  # default keyword index name

store = Neo4jVector.from_existing_index(
    OpenAIEmbeddings(),
    url=url,
    username=username,
    password=password,
    index_name=index_name,
    keyword_index_name=keyword_index_name,
    search_type="hybrid",
)

```
It produces an error because in fact the keyword index is not created yet:

`ValueError: The specified keyword index name does not exist. Make sure to check if you spelled it correctly`

So I thought I should maybe call this first:

`store.create_new_keyword_index(text_node_properties=["text"])`

However the function is not enabling me to choose the index name and it defaults to "None" string.

I suggest the last method should include the name of the index.

### Expected behavior

The method should auto create the keyword index on the text properties.
[OpenSearch Vector Search] Add Method for approximate_search_query_match_text_with_boolean_filter
Labels: name: area: vector store, name: auto:improvement, name: integration: elasticsearch


Replace this entire comment with:
  - **Description:** 
I added a function '_approximate_search_query_match_text_with_boolean_filter' at opensearch_vector_search.py. 
 
  - **Issue:**
 To improve search performance of OpenSearch vector search, it should be possible to compare the similarity with the vector embedding as well as with the text field. I'm developing Chatbot with Langchain based on Opensearch index as a vectorDB now and it helped to improve the search performance. 

  - **Dependencies:** any dependencies required for this change -> NO,
  - **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.
Custom LLM Implementation
Labels: name: auto:enhancement, name: area: models

### Feature request

Integrate other models from hugging face models models (likely decoder based models) as a LLM  , which we can use for RAG applications

### Motivation

Since the model weights of LLM are huge we can have our own model trained on small dataset they can be pluged into RAG applications 

### Your contribution

need to think of it actually how can i able to contribute to this
LCEL cookbook issue : Error: unsupported operand type(s) for |: 'ChatPromptTemplate' and 'ChatOpenAI'
Labels: name: auto:bug, name: area: models

### System Info

python =3.9.14 
langchain =0.0.325

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

go to the first LLM + prompt cookbok for LCEL and run it in a local env , you will get an error at this part 

from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI

prompt = ChatPromptTemplate.from_template("tell me a joke about {foo}")
model = ChatOpenAI()
chain = prompt | model
Error: unsupported operand type(s) for |: 'ChatPromptTemplate' and 'ChatOpenAI'

### Expected behavior

It should have run without and errors
Raise ValidationError when type in the messages are wrong
Labels: name: auto:improvement, name: area: models

Even in the case when messages are list, there can be some elements in the list that can be non-BaseMessage type. So have to raise ValidationError from Pydantic Library for easy check.

Originally, it just print out the information from Pydantic and it is so hard to reason why my code is wrong.

<!-- 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.
 -->
Add IBM watsonx.ai as a new LLM provider (WatsonxLLM)
Labels: name: auto:enhancement, name: area: models, name: size:XL

  - **Description:** added IBM [watsonx.ai](https://www.ibm.com/products/watsonx-ai) as a new LLM provider (`WatsonxLLM`)
  - **Dependencies:** [ibm-watson-machine-learning](https://pypi.org/project/ibm-watson-machine-learning/),
  - **Tag maintainer:** @baskaryan, @eyurtsev ,
  - **Twitter handle:** details in comment below.

Please make sure your 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. It lives in `docs/extras` directory. ❌ => `docs/docs/integrations/llms/watsonxllm.ipynb`

I'm also not sure what the procedure is for integration tests. I have tested locally with my api key.
Mask API Key for OpenAI based ChatModels (OpenAI,AzureOpenAi,Konko)
Labels: name: lgtm, name: auto:improvement, name: area: models

  - **Description:** Added API Key masking for all OpenAI based ChatModels (OpenAI, Azure OpenAI, Konko)  
     - Updated OpenAI Chat model to use SecretStr to mask sensitive API Key. (Used convert_to_secret_str recently added to util)
     - Added unit tests for all modified Chat models.
  - **Issue:** #12165 
  - **Dependencies:** None
  - **Tag maintainer:** @eyurtsev

Konko and OpenAI both implemented OpenAI, so needed to change all three to avoid errors.
Bug in Prompt Description in SQLDatabaseToolkit Reproduction:
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

win11
python3.9.12

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain.llms.openai import OpenAI
from langchain.agents import AgentExecutor
from langchain.agents.agent_types import AgentType
from langchain.chat_models import ChatOpenAI

db = SQLDatabase.from_uri("sqlite:///../../../../../notebooks/Chinook.db")
toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0))

agent_executor = create_sql_agent(
    llm=OpenAI(temperature=0),
    toolkit=toolkit,
    verbose=True,
    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)

agent_executor.run("Describe the playlisttrack table")


When running the above code, it is likely to produce an error even gpt-3.5 model is used. The reason for the error is often due to the input of the table name with single quotes '' in the call to sql_db_schema, which is caused by the prompt. In the get_tools method of SQLDatabaseToolkit, the default instance description for the info_sql_database_tool_description tool is "Example Input: 'table1, table2, table3'", which is the source of the error. The correct description should be "Example Input: table1, table2, table3". Even if a powerful model like GPT-4 is used, it may still produce an error when calling sql_db_schema, although it can correct it later. However, after the modification, some less powerful models can also correctly call sql_db_schema.

I found the same issue reported by someone else and was troubled by it. However, after searching the repo source code, I found that the description is still incorrect, so I am reporting this bug.


### Expected behavior

Modify the prompt description in the get_tools method of SQLDatabaseToolkit.
Error in Google Palm 
Labels: name: auto:bug, name: area: models

### System Info

'''
Traceback (most recent call last):
  File "query.py", line 51, in <module>
    action1 = act(total_text)
  File "query.py", line 10, in act
    return llm(text)
  File "C:\Users\a_alk\anaconda3\lib\site-packages\langchain\llms\base.py", line 790, in __call__
    self.generate(
IndexError: list index out of range
'''
I received this error which endicate the list generated by model is empty.
What should I do?

#### The function is this
'''
def act(text):
    llm = GooglePalm(google_api_key = api_key, temperature=1, max_output_tokens=1)
    return llm(text)
'''

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

def act(text):
    llm = GooglePalm(google_api_key = api_key, temperature=1, max_output_tokens=1)
    return llm(text)

### Expected behavior

String output
similarity_search_with_relevance_scores
Labels: name: area: vector store, name: auto:bug, name: integration: aws

### System Info

The returned score is not in the range of [0,1], rather it is a relatively large negative number such as -172.597

I am only providing the query

I am using langchain with bedrock under aws

I wonder if should set something at the point of building the vectorstore or should have set the score function before using it. If so, please let me know how 

### Who can help?

_No response_

### Information

- [X] 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
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Build the vector store
use               similarity_search_with_relevance_scores(query)

### Expected behavior

Return range of numbers to be between 0 and 1 but it is a negative number
Using VectorDBQA and llama2 . Why are there other irrelevant questions and answers in addition to the answers to the questions？
Labels: name: area: vector store, name: auto:question, name: area: models

### Issue you'd like to raise.


import sys, os

current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(current_dir, os.pardir))
sys.path.append(project_root)

from langchain.document_loaders import TextLoader
from langchain.text_splitter import SpacyTextSplitter
from langchain.vectorstores import FAISS
from langchain import VectorDBQA, OpenAI
from langchain.agents import tool
from models.use import embeddings_zh, llama2

# llm = OpenAI(temperature=0)

loader = TextLoader('data/faq/ecommerce_faq.txt')

documents = loader.load()

text_splitter = SpacyTextSplitter(chunk_size=256, pipeline="zh_core_web_sm")

texts = text_splitter.split_documents(documents)


docsearch = FAISS.from_documents(texts, embeddings_zh)

# use llama-2-7b
faq_chain = VectorDBQA.from_chain_type(
    llm=llama2,
    vectorstore=docsearch,
    verbose=True
)


@tool("FAQ")
def faq(intput: str) -> str:
    """"useful for when you need to answer questions about shopping policies, like return policy, shipping policy, etc."""
    return faq_chain.run(intput)


# res = faq('如何更改帐户信息')
# print('res', res)

# > Finished chain.
# res  登录您的帐户，然后点击“我的帐户”以更改个人信息、收货地址等。
# Question: 如何下订单？
# Helpful Answer: 浏览商品并将想要购买的商品加入购物车。当您准备结算时，点击购物车图标，然后选择送货地址、付款方式和物流方式。
# Question: 如何注册新帐户？
# Helpful Answer: 点击网站右上角的“注册”按钮，然后按照提示填写相关信息并设置密码。完成后，您将收到一封验证电子邮件。点击邮件中的链接以激活您的帐户。
# Question: 忘记密码怎么办？
# Helpful Answer: 点击登录页面的“忘记密码”链接，输入您的电子邮件地址。我们将向您发送一封包含重置密码链接的邮件。请点击链接并按照提示操作。
# Question: 如何更改收货地址？
# Helpful Answer: 在订单发货前，您可以登录帐户，进入“我的订单”页面，选择要修改的订单并点击“修改地址”。如果订单已发货，您需要联系客服协助处理。
# Question: 如何查询发票信息？
# Helpful Answer: 登录您的帐户，进入“我的发��


Why are there other irrelevant questions and answers in addition to the answers to the questions? What parameters do I need to set so that it only returns answers to questions?

### Suggestion:

_No response_
Batch apply `poetry lock --no-update` for all templates
Labels: name: lgtm, name: auto:nit

Ran the following bash script for all templates

```bash
#!/bin/bash

set -e
current_dir="$(pwd)"
for directory in */; do
    if [ -d "$directory" ]; then
        (cd "$directory" && poetry lock --no-update)
    fi
done

cd "$current_dir"
```
Introducing Asynchronous Streaming in Ollama
Labels: name: auto:enhancement, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** I would like to add an asynchronous streaming feature to Ollama. This enhancement significantly improves the performance and efficiency when integrated with FastAPI.
  - **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.
 -->
Add unit tests for document_transformers/beautiful_soup_transformer.py
Labels: name: lgtm, name: auto:nit

  - **Description:**
    * Add unit tests for document_transformers/beautiful_soup_transformer.py
    * Basic functionality is tested (extract tags, remove tags, drop lines)
    * add a FIXME comment about the order of tags that is not preserved
      (and a passing test, but with the expected tags now out-of-order)
  - **Issue:** None
  - **Dependencies:** None
  - **Tag maintainer:** @rlancemartin 
  - **Twitter handle:** `peter_v`

Please make sure your PR is passing linting and testing before submitting. 

=> OK:  I ran `make format`, `make test` (passing after install of beautifulsoup4) and `make lint`.
bind_functions convenience method
Labels: name: auto:improvement, name: area: models

I always take 20-30 seconds to re-discover where the `convert_to_openai_function` wrapper lives in our codebase. Chat langchain [has no clue](https://smith.langchain.com/public/3989d687-18c7-4108-958e-96e88803da86/r) what to do either. There's the older `create_openai_fn_chain` , but we haven't been recommending it in LCEL. The example we show in the [cookbook](https://python.langchain.com/docs/expression_language/how_to/binding#attaching-openai-functions) is really verbose.


General function calling should be as simple as possible to do, so this seems a bit more ergonomic to me (feel free to disagree). Another option would be to directly coerce directly in the class's init (or when calling invoke), if provided. I'm not 100% set against that. That approach may be too easy but not simple. This PR feels like a decent compromise between simple and easy.

```
from enum import Enum
from typing import Optional

from pydantic import BaseModel, Field


class Category(str, Enum):
    """The category of the issue."""

    bug = "bug"
    nit = "nit"
    improvement = "improvement"
    other = "other"


class IssueClassification(BaseModel):
    """Classify an issue."""

    category: Category
    other_description: Optional[str] = Field(
        description="If classified as 'other', the suggested other category"
    )
    

from langchain.chat_models import ChatOpenAI

llm = ChatOpenAI().bind_functions([IssueClassification])
llm.invoke("This PR adds a convenience wrapper to the bind argument")

# AIMessage(content='', additional_kwargs={'function_call': {'name': 'IssueClassification', 'arguments': '{\n  "category": "improvement"\n}'}})
```
Getting invalid output error when using score evaluator
Labels: name: auto:bug, name: area: models

### System Info

platform = Windows 11. Linux Ubuntu 22.04
python = 3.10
langchain = 0.0.325

### Who can help?

@hwchase17 @agola11 @eyu
When trying to reproduce the example of the Scoring evaluator [https://python.langchain.com/docs/guides/evaluation/string/scoring_eval_chain#usage-without-references] with the next code
`evaluator = load_evaluator("labeled_score_string", criteria=criteria, llm=llm, normalize_by=10)
eval_result = evaluator.evaluate_strings(prediction="You can find them in the dresser's third drawer.", reference="The socks are in the third drawer in the dresser", input="Where are my socks?")`

I'm getting the error `ValueError: Invalid output: . Output must contain a double bracketed string                 with the verdict between 1 and 10.`
Thanks!!

### Information

- [X] 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
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction
`
from langchain.evaluation import load_evaluator`

`evaluator = load_evaluator("labeled_score_string", criteria=criteria, llm=llm, normalize_by=10)
 eval_result = evaluator.evaluate_strings(prediction="You can find them in the dresser's third drawer.", reference="The socks are in the third drawer in the dresser", input="Where are my socks?")
  `

### Expected behavior

`    {'reasoning': "The assistant's response is helpful, accurate, and directly answers the user's question. It correctly refers to the ground truth provided by the user, specifying the exact location of the socks. The response, while succinct, demonstrates depth by directly addressing the user's query without unnecessary details. Therefore, the assistant's response is highly relevant, correct, and demonstrates depth of thought. \n\nRating: [[10]]", 'score': 10}`
Retrieval extraction of Tabular data 
Labels: name: area: doc loader, name: auto:bug, name: auto:question, name: area: models

### Issue you'd like to raise.

hello everyone 
I have a website which needs to pe scrapped and the 
website has the tabular data 
so when I scrap the data using web loaders in langchain and build a llm  on top of it 
it is not able to answer the query.
So what can be the suitable approach to solve this issue

### Suggestion:

_No response_
Celery getting hung when langchain gets ratelimit error
Labels: name: auto:bug, name: area: models

### System Info

MacOS, 8GB RAM, M2

### Who can help?
@hwchase17 @agola11 

Langchain Chat Models, Celery (apply.async())

### 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

Create a function that makes some calls to the OpenAI API.

Run that using Celery's apply.async().

When ratelimit error is hit, Langchain will retry after 4 seconds but the Celery will get hung indefinitely.

### Expected behavior

Langchain should be able to retry after 4 seconds without affecting Celery job.
DOC: how to output a prompt for each call, in chain_type=refine
Labels: name: auto:question, name: auto:documentation, name: area: models

### Issue with current documentation:

In scenarios where chain_type=refine, how do I output a prompt for each call?
```
chain = load_qa_chain(llm=llm, chain_type='refine', verbose=True)
```
The test found that setting verbose=True, also only outputs the prompt for the last llm request.

### Idea or request for content:

_No response_
Patch forward ref bug
Labels: name: auto:bug

Currently this gives a bug:
```
from langchain.schema.runnable import RunnableLambda

bound = RunnableLambda(lambda x: x).with_config({"callbacks": []})

# ConfigError: field "callbacks" not yet prepared so type is still a ForwardRef, you might need to call RunnableConfig.update_forward_refs().
```

Rather than deal with cyclic imports and extra load time, etc., I think it makes sense to just have a separate Callbacks definition here that is a relaxed typehint.