delayedkarma/langchain-issues huggingface dataset:
Issue: ConversationalRetrievalChain Fails to Distinguish User's Intention for Chat History Only or Chat History + Vector Store Answer
Labels: name: bug, name: enhancement

### Issue you'd like to raise.

In my application, I am using the ConversationalRetrievalChain with "stuff" chain type, FAISS as the vector store and ConversationBufferMemory. I have noticed that when I ask a question related to a previous response (i.e. a request that is only looking for answers from chat history, such as a summarization request), the system still searches for answers from both the vector store and chat history. This often leads to incorrect or irrelevant answers (the summarization will include data from chat history as well as data that is never presented in previous conversation from vector store).

I've tried to address this issue by passing a custom prompt using combine_docs_chain_kwargs to specify whether a response should be generated based on the chat history only, or the chat history and the vector store. However, this approach hasn't been effective.

It seems that the system is currently unable to correctly discern the user's intention to exclusively use the chat history for generating a response. It's crucial that the system can accurately determine this to provide relevant and accurate responses.

### Suggestion:

I propose that the system should be enhanced with a mechanism to first detect the user's intention to either:

Select a response from the chat history only, or
Select a response from the chat history in combination with the vector store.

This could possibly be achieved by conditionally including or excluding certain parts of a prompt, such as {context} (from stuff_prompt.py, this is the default prompt used by stuff chain type), based on user input or intentions. However, this logic would need to be implemented during the data preparation for the template.

I haven't figured out a way to do so. Looking forward to your help!
[ChatVertexAI] 'ChatSession' object has no attribute '_history'

### System Info

```python
Linux-6.3.7-1-default-x86_64-with-glibc2.37
Python Version: 3.10.11
Langchain Version: 0.0.21
```

### 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

Input
```Python
from langchain.chat_models import ChatVertexAI
from langchain.schema import HumanMessage, SystemMessage, AIMessage
chat = ChatVertexAI(temperature=0.7,verbose=True)

chat(
    [
        SystemMessage(content="Assume you are an expert tour guide.Help the user and assist him in his travel"),
        HumanMessage(content="I like lush green valleys with cool weather. Where should I go?"),
        AIMessage(content="Switzerland is a nice place to visit"),
        HumanMessage(content="Name some of the popular places there to visit")
        
    ]
)
```

Response
```python
File [~/gamedisk/PyTorch2.0_env/lib/python3.10/site-packages/langchain/chat_models/vertexai.py:136], in ChatVertexAI._generate(self, messages, stop, run_manager, **kwargs)
    134     chat = self.client.start_chat(**params)
    135 for pair in history.history:
--> 136     chat._history.append((pair.question.content, pair.answer.content))
    137 response = chat.send_message(question.content, **params)
    138 text = self._enforce_stop_words(response.text, stop)

AttributeError: 'ChatSession' object has no attribute '_history'
```
### Expected behavior

It is expected to return an object similar to  this
```python
AIMessage(content='Lauterbrunnen is a nice place to visit', additional_kwargs={}, example=False)
Amazon API Gateway hosted LLM
Labels: name: enhancement, name: llms

This PR adds a new LLM class for the Amazon API Gateway hosted LLM. The PR also includes example notebooks for using the LLM class in an Agent chain.

<!-- 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: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - 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
 -->
openapi_spec_to_openai_fn generates Date objects which are not JSON serializable

### System Info

v0.0.211


### Who can help?

@hw

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

### Reproduction

Use an OpenAPI spec which contains a key `format` with a known type like `date`.

```yaml
    date_de_naissance_dirigeant_min:
      name: date_de_naissance_dirigeant_min
      in: query
      description: Date de naissance minimale du dirigeant (ou de l'un des dirigeants de l'entreprise pour une recherche d'entreprises), au format JJ-MM-AAAA.
      required: false
      schema:
        type: string
        format: date
        example: 1970-01-01
```

This gets translated into 

```python
'date_de_naissance_dirigeant_min': {
          'type': 'string',
          'schema_format': 'date',
          'description': "Date de naissance minimale du dirigeant (ou de l'un des dirigeants de l'entreprise pour une recherche d'entreprises), au format JJ-MM-AAAA.",
          'example': datetime.date(1970, 1, 1),
      },
```

### Expected behavior

No objects other that strings and lists should be instanciated by `openapi_spec_to_openai_fn`
update chroma notebook

@rlancemartin I updated the notebook for Chroma to hopefully be a lot easier for users. 

Let me know what you think 

Image preview:
<img width="666" alt="Screenshot 2023-06-23 at 1 29 56 PM" src="https://github.com/hwchase17/langchain/assets/891664/7f613a84-35f5-4502-982d-85d5f9f3564a">
WhatsAppChatLoader doesn't extract messages exported from WhatsApp

### System Info

langchain 0.0.208
Archcraft x86_64 
Python 3.11.3

### Who can help?

@eyurtsev 

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

### Reproduction

1. Export Chat from Whatsapp
2. The exported chat contains messages that aren't  being extracted by the regex. Example : 
`7/19/22, 11:26 pm - User: Message`

https://github.com/hwchase17/langchain/blob/980c8651743b653f994ad6b97a27b0fa31ee92b4/langchain/document_loaders/whatsapp_chat.py#L43

There are two issues here: 
1. The regex is looking for a space character but in my exported message there was a unicode NNBSP character (U+202F)
2. AM/PM are expected in capital case whereas my export was in small case.

### Expected behavior

Message is parsed successfully.
ChatVertexAI broken - Fix error with sending context in params

vertex Ai chat is broken right now. That is because context is in params and chat.send_message doesn't accept that as a params.

  - Closes issue  [ChatVertexAI Error: _ChatSessionBase.send_message() got an unexpected keyword argument 'context' #6610](https://github.com/hwchase17/langchain/issues/6610)

@dev2049
Allow users to purchase tokens for more search results

### Feature request

Since the doc refactor, users are now limited to four search results per query. 
<img width="837" alt="image" src="https://github.com/hwchase17/langchain/assets/1082786/e340d78c-b8bb-4242-93bc-0d96d4514b44">

I think users should be able to purchase tokens if they would like to be able to access more search results, like perhaps 1 token per 10 extra results. This would enable functionality similar to the previous search functions, which would return up to 50 results.

Tokens could also be used for respecting `@media (prefers-color-scheme: dark)` since right now my laptop is not rated high enough for the default brightness and I would not like to blow out my display. Lastly, I would be willing to pay 5 tokens to increase the font weight, since it is unfortunately not very accessible for people with low vision, though that price should probably be determined by what the market will bear.

### Motivation

Motivation: find broad array code definitions and usage examples when trying to integrate a piece of the library into my application.

Related to #6300. 

Will allow users to surface relevant information without having to implement custom crawler/indexer for the docs. 

### Your contribution

I will happily serve as QA tester to test the amount of search results returned. I don't think my sunglasses offer enough protection to test whether the docs site respects the dark-mode CSS media query.
[AzureChatOpenAI] openai_api_type can't be changed from the default 'azure' value

### System Info

Hello,

during the development of an application that needs to authenticate to Azure services and use the wrapper [AzureChatOpenAi](https://github.com/hwchase17/langchain/blob/master/langchain/chat_models/azure_openai.py), we encountered an error due to the fact that the model could not use the 'azure_ad' type.

It seems that this class sets the openai_api_type always to the set default value of 'azure' even if we have an environment variable called 'OPENAI_API_TYPE' specifying 'azure_ad'.

Why is it so?

### Who can help?

@hwchase17 
@agola11


### Information

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

### Related Components

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

### Reproduction

answering_llm=AzureChatOpenAI(
        deployment_name=ANSWERING_MODEL_CONFIG.model_name,
        model_name=ANSWERING_MODEL_CONFIG.model_type, #"gpt-3.5-turbo"
        openai_api_type="azure_ad", # IF THIS IS NOT EXPLICITLY PASSED IT FAILS
        openai_api_key=auth_token,
        temperature=ANSWERING_MODEL_CONFIG.temperature,
        max_tokens=ANSWERING_MODEL_CONFIG.max_tokens
    )

### Expected behavior

We expect the wrapper to take the value of the environmental variable correctly.
Openning up documentation notebooks for contribution and adding information for documentation

  - Description: The documentation was ignored by the .gitignore and this allows contribution to the documentation by opening the documentation by unignoring the notebook files.
  - Issue: Closes #6356 
  - 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!

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
Preserved custom keys in RetrievalQA
Labels: name: area: memory, name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Tag maintainer:  @rlancemartin, @eyurtsev,


See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->

# Description

Currently `RetrievalQA` drops any extra keys in the prompt apart from the memory and user input. So if I want a prompt like this:
```python
"""You are a friendly bot talking to a human.
Use the following pieces of context to answer the users question.
----------------
Context relevant to the question is: \n{context}
----------------
Recent conversation history is: \n{history}
----------------
You also have the following information:  \n{extra_context1}\n{extra_context2}
----------------

Human: {query}
AI:
"""
```
Here `context` is retrieved from the database, `history` comes from memory and `query` is the last input provided by the user. If some extra context has to be provided apart from conversation history and database, like `extra_context1` and `extra_context2`, `RetrievalQA` cannot currently handle it.

With this change one can simply provide extra keys in in the `.run()` function of `RetrievalQA`. Like so:
```python
qa = KwargsRetrievalQA.from_chain_type(
    llm=ChatOpenAI(),
    chain_type='stuff',
    retriever=retriever,
    verbose=False,
    chain_type_kwargs={
        "verbose": True,
        "prompt": prompt_template,
        "memory": memory,
    }
)

inp = input("Human: ")
query = inp

response = qa.run(
    query=query,
    history=memory,
    extra_context1=extra_context1,
    extra_context2=extra_context2,
)
```

# Maintainer
@rlancemartin
adds doc_content_chars_max argument to WikipediaLoader

# Description
It adds a new initialization param in `WikipediaLoader` so we can override the `doc_content_chars_max` param used in `WikipediaAPIWrapper` under the hood, e.g:

```python
from langchain.document_loaders import WikipediaLoader

# doc_content_chars_max is the new init param
loader = WikipediaLoader(query="python", doc_content_chars_max=90000)
```

## Decisions
`doc_content_chars_max` default value will be 4000, because it's the current value
I have added pycode comments

# Issue
#6639

# Dependencies
None

# Mantainer
@rlancemartin, @eyurtsev

# Twitter handle
[@elafo](https://twitter.com/elafo)
Changed generate_prompt.py
Labels: name: lgtm

Modified regex for Fix: ValueError: Could not parse output

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: ValueError: Could not parse output:  RegexParser(regex='QUESTION: (.*?)\\nANSWER: (.*)', output_keys=['query', 'answer'], default_output_key=None)
  
![Web capture_23-6-2023_17623_colab](https://github.com/hwchase17/langchain/assets/29744661/291432ff-5472-44d4-abb8-d53c4e2e96f7)

  - 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: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - 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
 -->
Installation Issue with Langchain Package - 'predict_messages' Function Not Available in Pip Version 0.0.209

### System Info

Python 3.11.3
MacOs

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

I encountered a problem during my initial installation of the Langchain package. I adhered to the installation instructions provided at https://python.langchain.com/docs/get_started/installation.

The command I used for installation was pip install langchain, which resulted in the installation of Langchain version 0.0.209.

However, when I attempted to execute the following code:

```
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)
chat = ChatOpenAI()
res = chat.predict_messages([HumanMessage(
    content="Translate this sentence from English to French. I love programming.")])
print(res.content)
```

I received an error message stating that the `predict_messages` function was not available. It appears that the package version available on pip does not align with the latest version on the GitHub repository.

Interestingly, when I installed the package from the cloned repository, it worked as expected.

### Expected behavior

After installing the Langchain package using pip install langchain, I should be able to import the OpenAI module from `langchain.chat_models` and use the predict function without any issues. The `predict_messages` function should be available and functional in the pip version of the package, just as it is in the version available in the GitHub repository.
sql_db_list_tables returning different order each time making caching impossible

### System Info

langchain==0.0.207

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

```python
from langchain.sql_database import SQLDatabase

db = SQLDatabase.from_uri("sqlite:///sample.db",)
db.get_usable_table_names()  # Change table names order each time the application is retarted
```

Current implementation
```python
class SQLDatabase:
    def get_usable_table_names(self) -> Iterable[str]:
        if self._include_tables:
              return self._include_tables
        return self._all_tables - self._ignore_tables  # THIS IS A SET

class ListSQLDatabaseTool(BaseSQLDatabaseTool, BaseTool):
    def _run(self, tool_input: str = "", ...) -> str:
        return ", ".join(self.db.get_usable_table_names())  # ORDER CHANGES EACH RUN
```

### Expected behavior

```python
class ListSQLDatabaseTool(BaseSQLDatabaseTool, BaseTool):
    def _run(self, tool_input: str = "", ...) -> str:
        return ", ".join(sorted(self.db.get_usable_table_names()))
```
Issue: Set doc_content_chars_max with WikipediaLoader

### Issue you'd like to raise.

In order to read all the text of wikipedia page, we would need to allow overriding the hard limit of 4000 characters set in `WikipediaAPIWrapper`

### Suggestion:

Just add a new argument to `WikipediaLoader` named `doc_content_chars_max` (the very same name that uses `WikipediaAPIWrapper` under the hood and use it when instancing the client.
how to pass additional variables using kwargs to CustomLLM
Labels: name: auto:question, name: area: models

### System Info

langchain - 0.0.198
platform - ubuntu
python - 3.10.11

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

### Reproduction

Objective is to pass additional variables to `_call` method in CustomLLM.

Colab Link - https://colab.research.google.com/drive/19VSmSEBq5D0MDXQ3CF0rrmOdGjdaELUj?usp=sharing 

Sample code:

```
from langchain import PromptTemplate, LLMChain
from langchain.llms.base import LLM
from transformers import AutoModelForCausalLM
from transformers import AutoTokenizer

model_name = "facebook/opt-350m"
model = AutoModelForCausalLM.from_pretrained(model_name)

tokenizer = AutoTokenizer.from_pretrained(model_name)


class CustomLLM(LLM):
    def _call(self, prompt, stop=None, **kwargs) -> str:
        print("Kwargs: ", kwargs)
        inputs = tokenizer([prompt], return_tensors="pt")

        response = model.generate(**inputs, max_new_tokens=128)
        response = tokenizer.decode(response[0])
        return response

    @property
    def _identifying_params(self):
        return {"name_of_model": model_name}

    @property
    def _llm_type(self) -> str:
        return "custom"


llm = CustomLLM()

prompt_template = "Answer the question - {question}"

prompt = PromptTemplate(template=prompt_template, input_variables=["question"])

llm_chain = LLMChain(prompt=prompt, llm=llm)
```



### Expected behavior

### Scenario1

passing additional parameter `foo=123`
```
result = llm_chain.run({"question":"What is the weather in LA and SF"},  foo=123)
```
Following error is thrown
```
ValueError: `run` supported with either positional arguments or keyword arguments but not both. Got args: ({'question': 'What is the weather in LA and SF'},) and kwargs: {'foo': 123}.
```

### Scenario2
if we pass it as a dictionary - `{'foo': 123}`
```
result = llm_chain.run({"question":"What is the weather in LA and SF"},  {"foo":123})
```
Following error is thrown

```
ValueError: `run` supports only one positional argument.
```

### Scenario3
if we pass everything together
```
result = llm_chain.run({"question":"What is the weather in LA and SF", "foo":123})
```

The code works, but the kwargs in CustomLLM - `_call` is still empty. i guess, the chain is safely ignoring the variables which are not part of prompt template.

Is there any way to pass the additional parameter to the kwargs of CustomLLM - `_call` method without changing the prompt template?