delayedkarma/langchain-issues huggingface dataset:
Add Runnable.bind method to attach kwargs to a Runnable that will be passed to all invoke/stream/batch calls when it is run
Labels: name: auto:improvement

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

### System Info

**RecursiveUrlLoader** is not working. Please refer to the below code.  "docs" size is always 0. 

https://python.langchain.com/docs/integrations/document_loaders/recursive_url_loader

from langchain.document_loaders.recursive_url_loader import RecursiveUrlLoader
url = "https://js.langchain.com/docs/modules/memory/examples/"
loader = RecursiveUrlLoader(url=url)
docs = loader.load()
print(len(docs))

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

### Reproduction

from langchain.document_loaders.recursive_url_loader import RecursiveUrlLoader
url = "https://js.langchain.com/docs/modules/memory/examples/"
loader = RecursiveUrlLoader(url=url)
docs = loader.load()
print(len(docs))

Here Length is displaying as zero.

### Expected behavior

All the urls should be scraped
OpenSearch bulk ingest with deterministic _id if available
Labels: name: area: vector store, name: auto:improvement

### Feature request

The `_id` field should be populated with these in order:

1. `ids: Optional[List[str]] = None,` -- already in place
2. Document metadata (filename + start_index) -- new feature
3. Leave `_id` empty (instead of uuid) -- new feature

https://github.com/langchain-ai/langchain/blob/cf608f876b0ada9ac965fe5b25b5ca6e5e47feeb/libs/langchain/langchain/vectorstores/opensearch_vector_search.py#L125

### Motivation

Deterministic _id is very important to keep a robust data pipeline. Duplicate load will thus result in version increment instead of creating new document with the same content.

### Your contribution

I can do a PR if the idea is approved.
Arbitrary code execution in LLMMathChain
Labels: name: auto:bug

### System Info

Langchain version: 0.0.244
Numexpr version: 2.8.4
Python version: 3.10.11


### Who can help?

@hwchase17 @vowelparrot 

### Information

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

### Related Components

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

### Reproduction

Numexpr's evaluate function that Langchain uses [here](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/llm_math/base.py#L80) in the LLMMathChain is susceptible to arbitrary code execution with eval in the latest released version. See this [issue](https://github.com/pydata/numexpr/issues/442) where PoC for numexpr's evaluate is also provided.

This vulnerability allows an arbitrary code execution, that is to run code and commands on target machine, via LLMMathChain's run method with the right prompt. I'd like to ask the Langchain's maintainers to confirm if they want a full PoC with Langchain posted here publicly.

### Expected behavior

Numerical expressions should be evaluated securely so as to not allow code execution.
DOC: Contribution guidelines not working
Labels: name: auto:bug, name: auto:documentation

### Issue with current documentation:

Following this:https://github.com/levalencia/langchainLuisValencia/blob/master/.github/CONTRIBUTING.md#-common-tasks
On Windows.

Forked the repo, cloned it locally, created a conda environment, (Poetry was already installed), then installed all dependencies.

Error received:```

  • Installing xmltodict (0.13.0)
  • Installing zstandard (0.21.0)

  ChefBuildError

  Backend subprocess exited when trying to invoke get_requires_for_build_wheel

  Traceback (most recent call last):
    File "C:\Users\xx\AppData\Roaming\pypoetry\venv\Lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "C:\Users\xx\AppData\Roaming\pypoetry\venv\Lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Users\xx\AppData\Roaming\pypoetry\venv\Lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
      return hook(config_settings)
    File "C:\Users\LUISVA~1\AppData\Local\Temp\tmpn9w63h_u\.venv\lib\site-packages\setuptools\build_meta.py", line 341, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "C:\Users\LUISVA~1\AppData\Local\Temp\tmpn9w63h_u\.venv\lib\site-packages\setuptools\build_meta.py", line 323, in _get_build_requires
      self.run_setup()
    File "C:\Users\LUISVA~1\AppData\Local\Temp\tmpn9w63h_u\.venv\lib\site-packages\setuptools\build_meta.py", line 487, in run_setup
      super(_BuildMetaLegacyBackend,
    File "C:\Users\LUISVA~1\AppData\Local\Temp\tmpn9w63h_u\.venv\lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
      exec(code, locals())
    File "<string>", line 8, in <module>
  RuntimeError: uvloop does not support Windows at the moment


  at ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\chef.py:147 in _prepare
      143│ 
      144│                 error = ChefBuildError("\n\n".join(message_parts))
      145│
      146│             if error is not None:
    → 147│                 raise error from None
      148│
      149│             return path
      150│
      151│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with uvloop (0.17.0) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "uvloop (==0.17.0)"'.
```
How can I fix this?

### Idea or request for content:

Poetry Version 1.5.1

What do I need to do to be able to test locally? Before I start to contribute?
LLM output parsing error for answers including code sections.
Labels: name: auto:bug

### System Info

LangChain version v0.0.5, Python 3.9.13


### Who can help?

@hwchase17 

### Information

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

### Related Components

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

### Reproduction

Issue was reported before, see [issue 5428](https://github.com/langchain-ai/langchain/issues/5428)
It is still not solved.

The problem is the regular expression used in libs/langchain/langchain/output_parsers/json.py
```python
match = re.search(r"```(json)?(.*?)```", json_string, re.DOTALL)
```
`.*?` does non-greedy matching, so the parsing does not stop at the final triple backticks, but 
at the first occurrence of triple backticks which can be the start of a code section like ```python

Which leads errors like:
`Error while running agent: Could not parse LLM output: json { "action": "Final Answer", "action_input": "Here is a simple Python script that includes a main function and prints 'Hello':\n\npython\ndef say_hello():\n print('Hello')\n\ndef main():\n say_hello()\n\nif name == 'main':\n main()\n```\nThis script defines a function say_hello that prints the string 'Hello'. The main function calls say_hello. The final lines check if this script is being run directly (as opposed to being imported as a module), and if so, calls the main function." }`

 


### Expected behavior

Correct LLM output parsing for answers including code sections.
See [issue 5428](https://github.com/langchain-ai/langchain/issues/5428)
fix(petals) allows to run models that aren't Bloom (Support for LLama and newer models)
Labels: name: lgtm, name: auto:improvement

In this PR:

- Removed restricted model loading logic for Petals-Bloom
  - Removed petals imports (DistributedBloomForCausalLM, BloomTokenizerFast)
  - Instead imported more generalized versions of loader (AutoDistributedModelForCausalLM, AutoTokenizer)
  - Updated the Petals example notebook to allow for a successful installation of Petals in Apple Silicon Macs

- Tag maintainer: @hwchase17, @baskaryan
Chat History Issue 
Labels: name: area: agent, name: auto:question

### Issue you'd like to raise.

if we are passing chathistory as a input in agent 

  template = """You are a chatbot having a conversation with a human.
            {chat_history}
            {human_input}

            Chatbot:"""

  prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
  suffix = """Begin!"

  {chat_history}
  Question: {input}
  {agent_scratchpad}

  """


SO will it exceed the max token limit of the agent ??

If Yes what alternatives can be used for this 


### Suggestion:

_No response_
Update sql database agent example
Labels: name: lgtm, name: area: doc loader, name: auto:documentation

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

  - Description: Adds AwaEmbeddings class for embeddings, which provides users with a convenient way to do fine-tuning, as well as the potential need for multimodality

  - Tag maintainer: @baskaryan

Create `Awa.ipynb`: an example notebook for AwaEmbeddings class
Modify `embeddings/__init__.py`: Import the class
Create `embeddings/awa.py`: The embedding class
Create `embeddings/test_awa.py`: The test file.
Loading vectorstore from disk still calls to OpenAI's embeddings API
Labels: name: area: embeddings, name: area: vector store, name: auto:bug, name: auto:question

### System Info

I'm trying to achieve the least calls to openAI-s API, So I've tried to save my vectorstorage to the disk and then reload it (like its in the "if" part). But if I use OpenAIEmbeddings() as embedding_funcion it still calls to openai's embeddings API. (Maybe it should be a feature request) Is this a bug? Am I doing something wrong?

import os
from langchain.document_loaders import TextLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain.vectorstores import Chroma

loaders = [TextLoader("text1.txt"), TextLoader("text2.txt")]
indexes = []

for loader in loaders:
    path = os.path.splitext(loader.file_path)[0]
    if os.path.exists(path):
        indexes.append(VectorStoreIndexWrapper(
            vectorstore=Chroma(
                persist_directory=f"./{path}", embedding_function=OpenAIEmbeddings())))
    else:
        indexes.append(VectorstoreIndexCreator(
            vectorstore_kwargs={"persist_directory": f"./{path}"}).from_loaders([loader]))



### Who can help?

_No response_

### Information

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

### Related Components

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

The code I provided above creates folders when there are text1.txt and text2.txt in the same folder. (something should be in these files, like a poem or an article or something). 

### Expected behavior

After the script ran the folders ("text1" and "text2") should be created with a {guid} folder and a chroma.sqlite3 file in them.


I checked my request usage on https://platform.openai.com/account/usage, and there were 2 requests to text-embedding-ada-002-v2 since there are 2 text files
fix(openapi): openapi chain will work without/empty description/summa…
Labels: name: lgtm, name: auto:bug

Description: 

This PR will enable the Open API chain to work with valid Open API specifications missing `description` and `summary` properties for path and operation nodes in open api specs.

Since both `description` and `summary` property are declared optional we cannot be sure they are defined. This PR resolves this problem by providing an empty (`''`) description as fallback. 

The previous behavior of the Open API chain was that the underlying LLM (OpenAI) throw ed an exception since `None` is not of type string: 

```
openai.error.InvalidRequestError: None is not of type 'string' - 'functions.0.description'
```

Using this PR the Open API chain will succeed also using Open API specs lacking `description` and `summary` properties for path and operation nodes.

Thanks for your amazing work !

Tag maintainer: @baskaryan
No function message compatability in PostgresChatMessageHistory
Labels: name: area: memory, name: auto:bug

### System Info

LangChain 0.0.235

### 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
- [X] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```python
from langchain.schema import FunctionMessage
from langchain.memory import PostgresChatMessageHistory

history = PostgresChatMessageHistory(
    connection_string="postgresql://postgres:mypassword@localhost/chat_history", # needs configuring
    session_id="test_session_id",
)

function_message = FunctionMessage(
    content='A Message for passing the result of executing a function back to a model',
    name='name of function'
)

history.add_message(function_message)

history.messages
```

### Expected behavior

Output:
FunctionMessage(content='A Message for passing the result of executing a function back to a model', additional_kwargs={}, name='name of function')
Custom tool return_direct except when a ToolException occurs.
Labels: name: auto:improvement

### Feature request

Some kind of possibility to make a custom tool with return direct not do so when faced with a error such as a ToolException.

### Motivation

Currently, when a tool with return_direct faces a handled error, it returns the error directly. I would want a tool to return an output directly but only if there are no errors, since the errors aren't useful to be directly returned.

### Your contribution

I am not sure how this could be implemented, but would gladly help working on any ideas. Found this issue which would also enable this https://github.com/langchain-ai/langchain/issues/8306
Playwright Browser Tools: add screenshot feature
Labels: name: auto:enhancement

### Feature request

The Playwright toolkit is awesome. But it would be great to be able to see what the agent is doing. We could add a feature that takes screenshoots of the current state of the web page

### Motivation

It feels strange to use the toolkit but being blind, we cannot see what the agent is doing. The original idea is that by taking screenshoot we could use agents to perform UI testing.

### Your contribution

I could help writing a PR, but I’ll need help from the Playwright community. I also want to know what the community thinks of this feature.
BabyAGI implementation with tools with multiple inputs (requiring Structured Tool Chat Agent)
Labels: name: area: agent, name: auto:bug, name: auto:question

### Discussed in https://github.com/langchain-ai/langchain/discussions/5410

<div type='discussions-op-text'>

<sup>Originally posted by **luca-git** May 29, 2023</sup>
My goal is to extend the tools used by baby AGI, more specifically to use at least the basic   WriteFileTool() and ReadFileTool(). They use two inputs though, so I cannot stick with the vanilla ZeroShotAgent. So i resorted to using: AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION and replace it in the original code in the link below. Agent initialization is the only modification I've made. Can anyone kindly help me understand what I'm missing in the code in order to be able to leverage multiple input tools or provide guidance/resources? 

https://python.langchain.com/en/latest/use_cases/agents/baby_agi_with_agent.html?highlight=babyagi%20with%20tools 


```python 

from langchain.agents import AgentType 

from langchain.agents import initialize_agent 

    @classmethod 

    def from_llm( 

        cls, llm: BaseLLM, vectorstore: VectorStore, verbose: bool = False, **kwargs 

    ) -> "BabyAGI": 

        """Initialize the BabyAGI Controller.""" 

        task_creation_chain = TaskCreationChain.from_llm(llm, verbose=verbose) 

        task_prioritization_chain = TaskPrioritizationChain.from_llm( 

            llm, verbose=verbose 

        ) 

        llm_chain = LLMChain(llm=llm, prompt=prompt) 

        tool_names = [tool.name for tool in tools] 

        agent = initialize_agent(agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,llm=llm_chain, tools=tool_names) 

        agent_executor = AgentExecutor.from_agent_and_tools( 

            agent=agent, tools=tools, verbose=True 

        ) 

        return cls( 

            task_creation_chain=task_creation_chain, 

            task_prioritization_chain=task_prioritization_chain, 

            execution_chain=agent_executor, 

            vectorstore=vectorstore, 

            **kwargs, 

        ) 

``` 

I get the error 

```python 

 File ~\anaconda3\envs\aagi\lib\site-packages\langchain\agents\structured_chat\base.py:83 in create_prompt  args_schema = re.sub("}", "}}}}", re.sub("{", "{{{{", str(tool.args))) 
AttributeError: 'str' object has no attribute 'args' 
``` 

</div>
Fix broken `make` targets `format_diff` and `lint_diff`
Labels: name: lgtm, name: auto:bug

Since the refactoring into sub-projects `libs/langchain` and `libs/experimental`, the `make` targets `format_diff` and `lint_diff` do not work anymore when running `make` from these subdirectories. Reason is that 

```
PYTHON_FILES=$(shell git diff --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
```

generates paths from the project's root directory instead of the corresponding subdirectories. This PR fixes this by adding a `--relative` command line option.

- Tag maintainer: @baskaryan
GPTCache is getting created multiple times for the same llm_string
Labels: name: auto:bug

### System Info

gptcache==0.1.37
langchain==0.0.240

python 3.8

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

```python
from gptcache import Cache
from gptcache.adapter.api import init_similar_cache
from langchain.cache import GPTCache

# Every time llm updates the cache, it is creating a new cache object for the existing llm_string

def init_gptcache(cache_obj: Cache, llm_str: str):
    init_similar_cache(cache_obj=cache_obj, data_dir=f"similar_cache_{llm_str}")

langchain.llm_cache = GPTCache(init_gptcache)
llm = OpenAI(model_name="text-davinci-002", temperature=0.2)
llm.predict("tell me a joke")
```


### Expected behavior

It should not recreate new GPTCache object for the same llm_string.