delayedkarma/langchain-issues huggingface dataset:
DOC: Inexistent API documentation about SQLRecordManager
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:

There is no documentation about the `SQLRecordManager` in the [langchain.indexes.base.RecordManager](https://api.python.langchain.com/en/latest/indexes/langchain.indexes.base.RecordManager.html#langchain.indexes.base.RecordManager) documentation, although is used in an indexing example [here](https://python.langchain.com/docs/modules/data_connection/indexing#quickstart).

### Idea or request for content:

Please include the documentation for `SQLRecordManager`, as well as other supported databases that may be currently available to use as a Record Manager.
Support `ensure_trailing_slash` and `headers` options in RecursiveUrlLoader
Labels: name: area: doc loader, name: auto:improvement

This commit adds the following support:

- `ensure_trailing_slash` ... Ensure a trailing slash when requesting to the given url or a child link.
  - This option is necessary when the site doesn't support trailing slash e.g. `https://wiki.supercombo.gg/w/Street_Fighter_6` works but `https://wiki.supercombo.gg/w/Street_Fighter_6/` doesn't work.
- `headers` ... Headers when requesting to the url. 
  - This option is necessary when the site requires specific header to respond e.g. `https://www.streetfighter.com/6/character` requires `user-agent` header.

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Indexing deletion modes not working
Labels: name: area: vector store, name: auto:bug

### System Info

LangChain version: 0.0.276
Python version: 3.11.2
Platform: x86_64 Debian 12.2.0-14
Weaviate as vectorstore
SQLite for document index

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

### Reproduction

Followed the provided [Indexing directions](https://python.langchain.com/docs/modules/data_connection/indexing) of LangChain's documentation.

```
import os, time, json, weaviate, openai
from langchain.vectorstores import Weaviate
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.indexes import SQLRecordManager, index
from langchain.text_splitter import CharacterTextSplitter
from langchain.schema import Document
from datetime import datetime

VECTORS_INDEX_NAME = 'LaborIA_vectors_TEST'
COLLECTION_NAME = 'LaborIA_docs_TEST'
NAMESPACE = f"weaviate/{COLLECTION_NAME}"

record_manager = SQLRecordManager(NAMESPACE, db_url="sqlite:///record_manager_cache.sql")

record_manager.create_schema()

def _clear():
    """Hacky helper method to clear content. See the `full` mode section to to understand why it works."""
    index([], record_manager, weaviate_vectorstore, cleanup="full", source_id_key="source")

_clear()
```

Results in the following error:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[60], line 1
----> 1 _clear()

Cell In[59], line 3, in _clear()
      1 def _clear():
      2     """Hacky helper method to clear content. See the `full` mode section to to understand why it works."""
----> 3     index([], record_manager, weaviate_vectorstore, cleanup="full", source_id_key="source")

TypeError: index() got an unexpected keyword argument 'cleanup'
```
Declaring the `_clear()` function with either `cleanup="incremental"` or `cleanup=None` deletion modes results in the same `TypeError`. It shows no errors if the `cleanup` parameter is completely removed.

Will `index` execute in deletion mode `None` (as specified [here](https://python.langchain.com/docs/modules/data_connection/indexing#none-deletion-mode) if the  `cleanup` parameter is not present?

### Expected behavior

No errors when the `cleanup` mode parameter is set when `index` is called.
Cannot have models with BaseLanguageModel in pydantic 2: TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given
Labels: name: auto:bug, name: area: models

### System Info

```sh
pydantic==2.3.0
langchain==0.0.279
```

### Who can help?

@agola11 , @hwchase17: Having trouble learning how to have LLMs as attributes in pydantic2. I keep getting this confusing error which I cannot troubleshoot. 

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

```py
import os
os.environ['OPENAI_API_KEY'] = 'foo'
from pydantic import BaseModel
from langchain.base_language import BaseLanguageModel
from langchain.llms import OpenAI


class Foo(BaseModel):
    llm: BaseLanguageModel = OpenAI()
llm = OpenAI()
# Works
Foo()
# Fails
Foo(llm=llm)
```

Error:
```sh
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 14
     12 Foo()
     13 # Fails
---> 14 Foo(llm=llm)

File ~/miniconda3/envs/chain/lib/python3.11/site-packages/pydantic/main.py:165, in BaseModel.__init__(__pydantic_self__, **data)
    163 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    164 __tracebackhide__ = True
--> 165 __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)

TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given
```

### Expected behavior

Be able to set the field without validation errors
Bug-fix CSV Agent - Parsing Tool Inputs
Labels: name: area: agent, name: auto:bug

Issue & Description:
Suggested changes are due to encountering constant constant errors when using the Pandas DataFrame Agent due to parsing the python code that comes in the responses from the LLMs.
To address the issue I propose json serialization of the arguments of the function call at the OpenAIFunctionsAgent, as well as a more detailed ArgSchema for the PythonAstREPLTool, and finally an addition to the input query sanitize function, since i've noticed that more often than not, OpenAI's GPT-3.5-turbo make function calls but instead of sending the "query" param as a plan python code string, it tries to serialize it into some sort of "{'query': 'python code snippet'}" string, which is just not what we want.
Bagatur/fix multiquery
Labels: name: auto:bug

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Automaton Variant 2
Labels: name: area: agent, name: auto:enhancement

Possible reformulation of agents

## Key Changes

1. Agents work with a [sequence of messages](https://github.com/langchain-ai/langchain/blob/29ddf63abb6a9aa67c589e2b127f7b890787f1f4/libs/langchain/langchain/automaton/typedefs.py#L79-L79) (or interface that allows fetching sequence of messages)
2. The definition of messages is expanded to include the following [internal message](https://github.com/langchain-ai/langchain/blob/29ddf63abb6a9aa67c589e2b127f7b890787f1f4/libs/langchain/langchain/automaton/typedefs.py#L39-L39) types:
   * FunctionCall: name, arguments
   * FunctionResult: name, result, error 
     * This is distinct from OpenAI function message due to encoding of result
   * AgentFinish (Maybe call Yield?)
   * (Existing BaseMessage)
   * PrimingMessage (?) Perhaps allow user to define custom internal messages?
3. Agent implementation leverages a [generic single step chain](https://github.com/langchain-ai/langchain/blob/29ddf63abb6a9aa67c589e2b127f7b890787f1f4/libs/langchain/langchain/automaton/runnables.py#L47-L47) (aka LLMChain but memory is an input and uses a prompt generator)
4. [A Prompt Generator](https://github.com/langchain-ai/langchain/blob/29ddf63abb6a9aa67c589e2b127f7b890787f1f4/libs/langchain/langchain/automaton/runnables.py#L49-L49) is used to bridge between generalized messages and llm prompt.

## Goals

* Agents should be able to access history (e.g., chat messages)
* Agent should not take a lot of code to implement, but should be possible to fully customize
* Ideally reduce amount of code a developer needs to understand (not fully featured to not fair comparison)

## Examples

* Implementation of [Think Act](https://github.com/langchain-ai/langchain/blob/29ddf63abb6a9aa67c589e2b127f7b890787f1f4/libs/langchain/langchain/automaton/think_act_agent.py#L202) includes *priming* with a string based LLM.
* Structured chat using any [chat based LLM (Claude)](https://github.com/langchain-ai/langchain/blob/486d772184bcaffaaf92b5e2489a3985611c9bd4/libs/langchain/langchain/automaton/notebooks/chat_agent.ipynb)
* See other notebooks

## Things to note: 

[ChatAgent](https://github.com/langchain-ai/langchain/pull/10105/files#diff-701c2a1ff9f13203db7396c939e9f6a15e4aa0da4f5976cdbb5e8317170a13e8R95) and [OpenAIAgent](https://github.com/langchain-ai/langchain/pull/10105/files#diff-17bae31e03cb6f1b943fe8e4df906671f2223195e88fc4275dce8b0533de7746R60) only differ in the prompt, the prompt generator and the parser
Comprehend Moderation ver 0.1
Labels: name: auto:enhancement, name: area: models

This PR streamlines the #9665 configuration object and logic to enable chain moderation via the Amazon Comprehend service, allowing you to detect and redact PII, Toxic, and Intent information in the LLM prompt or answer.
This implementation simplifies the configuration and types it to specific class/model.

### Usage sample

```python


from langchain_experimental.comprehend_moderation import (BaseModerationConfig, 
                                 ModerationIntentConfig, 
                                 ModerationPiiConfig, 
                                 ModerationToxicityConfig
)

pii_config = ModerationPiiConfig(
    labels=["SSN"],
    redact=True,
    mask_character="X"
)

toxicity_config = ModerationToxicityConfig(
    threshold=0.5
)

intent_config = ModerationIntentConfig(
    threshold=0.5
)

moderation_config = BaseModerationConfig(
    filters=[pii_config, toxicity_config, intent_config]
)

comp_moderation_with_config = AmazonComprehendModerationChain(
    moderation_config=moderation_config, #specify the configuration
    client=comprehend_client,            #optionally pass the Boto3 Client
    verbose=True
)

template = """Question: {question}

Answer:"""

prompt = PromptTemplate(template=template, input_variables=["question"])

responses = [
    "Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.", 
    "Final Answer: This is a really shitty way of constructing a birdhouse. This is fucking insane to think that any birds would actually create their motherfucking nests here."
]
llm = FakeListLLM(responses=responses)

llm_chain = LLMChain(prompt=prompt, llm=llm)

chain = ( 
    prompt 
    | comp_moderation_with_config 
    | {llm_chain.input_keys[0]: lambda x: x['output'] }  
    | llm_chain 
    | { "input": lambda x: x['text'] } 
    | comp_moderation_with_config 
)

try:
    response = chain.invoke({"question": "A sample SSN number looks like this 123-456-7890. Can you give me some more samples?"})
except Exception as e:
    print(str(e))
else:
    print(response['output'])

```

### Output

```python

> Entering new AmazonComprehendModerationChain chain...
Running AmazonComprehendModerationChain...
Running pii Validation...
Running toxicity Validation...
Running intent Validation...

> Finished chain.


> Entering new AmazonComprehendModerationChain chain...
Running AmazonComprehendModerationChain...
Running pii Validation...
Running toxicity Validation...
Running intent Validation...

> Finished chain.
Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like XXXXXXXXXXXX John Doe's phone number is (999)253-9876.
```
Bagatur/eden type 2
Labels: name: auto:documentation

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Issue: ConversationalChatAgent reduces the user question question to single word action_input when parsing
Labels: name: area: agent, name: auto:bug

### Issue you'd like to raise.

I have created an agent using ConversationalChatAgent which uses custom tools (CoversationRetrievalQA based) to answer users questions. When determining which tool to use the agent is sometimes stripping the question to single word. For example question  like `What is XYZ?` is reduced to 

```
{
action: tool_name,
action_input: XYZ
}
```

How can I change the behavior to include full question in this scenario? 

expected behavior 

```
{
action: tool_name,
action_input: What is XYZ? or Define XYZ?
}
```


### Suggestion:

_No response_
Parsing intermediate steps: Object of type AgentAction is not JSON serializable
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

python 3.9 langchain 0.0.250

### 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
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction


Follow the steps in [Access Intermediate Steps](https://github.com/langchain-ai/langchain/blob/master/docs/extras/modules/agents/how_to/intermediate_steps.ipynb) within the Agent "How To".

When converting the steps to json:
print(json.dumps(response["intermediate_steps"], indent=2))

This raises the error:
TypeError: Object of type AgentAction is not JSON serializable


### Expected behavior


This issue is similar to the one raised in #8815. 
However the bot answer is not satisfying as using 
```
from langchain.load.dump import dumps

print(dumps(response["intermediate_steps"], pretty=True))
```
will not serialize the `AgentAction`

I can propose a `__json__()` function to correct this the lib json-fix or either inherit the class from dict
Created an interface for user friendly usage of HuggingFaceInferenceA…
Labels: name: area: embeddings, name: auto:enhancement

…PI to run models over API rather than locally loading it. The interface uses ChromaDB implementation

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: Created an interface for user friendly usage of HuggingFaceInferenceAPI to run models over API rather than locally loading it. The interface uses ChromaDB implementation, 
  - Dependencies: Embeddings from ChromaDB namely HuggingFaceEmbeddings,
feat: Hugging Face Pipeline as a new Chat Model
Labels: name: auto:enhancement, name: area: models

 ## Description:

This Pull Request adds **Hugging Face Pipeline** as a new LangChain Chat Model. 

It effectively allows the user to use any instruction tuned model with LangChain's Chat interface with a newly added Chat Templates [link](https://huggingface.co/blog/chat-templates) [link](https://huggingface.co/docs/transformers/main/chat_templating)

For example, it is now possible to define the HF Pipeline with the `meta-llama/Llama-2-7b-chat-hf` model and [arbitrary QLoRA configuration](https://huggingface.co/blog/4bit-transformers-bitsandbytes) (as shown in the [example](https://github.com/deepsense-ai/langchain/blob/llama2-chat/docs/extras/integrations/chat/huggingface_llama2.ipynb)) and run it locally with LangChain on a GPU with less than 6GB of VRAM. 

@deepsense_ai
Data deanonymization
Labels: name: auto:enhancement

### Description

The feature for pseudonymizing data with ability to retrieve original text (deanonymization) has been implemented. In order to protect private data, such as when querying external APIs (OpenAI), it is worth pseudonymizing sensitive data to maintain full privacy. But then, after the model response, it would be good to have the data in the original form.

I implemented the `PresidioReversibleAnonymizer`, which consists of two parts:

1. anonymization - it works the same way as `PresidioAnonymizer`, plus the object itself stores a mapping of made-up values to original ones, for example:
```
    {
        "PERSON": {
            "<anonymized>": "<original>",
            "John Doe": "Slim Shady"
        },
        "PHONE_NUMBER": {
            "111-111-1111": "555-555-5555"
        }
        ...
    }
```

2. deanonymization - using the mapping described above, it matches fake data with original data and then substitutes it.

Between anonymization and deanonymization user can perform different operations, for example, passing the output to LLM.

### Future works

- **instance anonymization** - at this point, each occurrence of PII is treated as a separate entity and separately anonymized. Therefore, two occurrences of the name John Doe in the text will be changed to two different names. It is therefore worth introducing support for full instance detection, so that repeated occurrences are treated as a single object.
- **better matching and substitution of fake values for real ones** - currently the strategy is based on matching full strings and then substituting them. Due to the indeterminism of language models, it may happen that the value in the answer is slightly changed (e.g. *John Doe* -> *John* or *Main St, New York* -> *New York*) and such a substitution is then no longer possible. Therefore, it is worth adjusting the matching for your needs.
- **Q&A with anonymization** - when I'm done writing all the functionality, I thought it would be a cool resource in documentation to write a notebook about retrieval from documents using anonymization. An iterative process, adding new recognizers to fit the data, lessons learned and what to look out for

### Twitter handle
@deepsense_ai / @MaksOpp
HuggingGPT string inplace
Labels: name: auto:bug, name: area: models

Description: This bug is found when using HuggingGPT in LangChain. I found that if there are dependencies between tasks, the execution results will become very bad. I debugged the code and found that it is because the filename of the generated file is not updated to the args of the following task, mainly due to the "replace()" function in string operation (it is not an in-place operation). You should assign the replace result with the string to save the change.

Issue: N/A

Dependencies: N/A
Takeoff baseurl support
Labels: name: lgtm, name: auto:improvement, name: area: models

## Description
This PR introduces a minor change to the TitanTakeoff integration. 
Instead of specifying a port on localhost, this PR will allow users to specify a baseURL instead. This will allow users to use the integration if they have TitanTakeoff deployed externally (not on localhost). This removes the hardcoded reference to localhost "http://localhost:{port}".

### Info about Titan Takeoff
Titan Takeoff is an inference server created by [TitanML](https://www.titanml.co/) that allows you to deploy large language models locally on your hardware in a single command. Most generative model architectures are included, such as Falcon, Llama 2, GPT2, T5 and many more.

Read more about Titan Takeoff here:
- [Blog](https://medium.com/@TitanML/introducing-titan-takeoff-6c30e55a8e1e)
- [Docs](https://docs.titanml.co/docs/titan-takeoff/getting-started)

### Dependencies
No new dependencies are introduced. However, users will need to install the titan-iris package in their local environment and start the Titan Takeoff inferencing server in order to use the Titan Takeoff integration.

Thanks for your help and please let me know if you have any questions.
cc: @hwchase17 @baskaryan
Update output_parser.py
Labels: name: area: agent, name: auto:bug

I created a customLLM base on a llama2_70b online API service, used it for a text_to_sql mission.
I  used the "create_sql_agent", it didn't work well. A piece of the logfile looks like this:

Action: sql_db_schema
Action Input: 'customers'
Observation: Error: table_names {"'customers'"} not found in database

It seemed like the llama2_70b is more likely to use single quotes, probably some other llms too.
I find out that the output_parser  in "langchain\agents\mrkl\output_parser.py" strip the " " but not "'", strip them both should be a solution once for all. And it works for me.