delayedkarma/langchain-issues huggingface dataset:
Clean queries prior to search
Labels: name: auto:improvement

With some search tools, we see no results returned if the query is formatted as a string following a number.

This works -
`query="1. What is the working mechanism of LLM Powered Autonomous Agents?"`
```
QUERY
1. What is the working mechanism of LLM Powered Autonomous Agents?
RESULT
[{'title': "LLM Powered Autonomous Agents | Lil'Log", 'link': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'snippet': "Jun 23, 2023 ... Fig. 1. Overview of a LLM-powered autonomous agent system. ... Then reflections are added into the agent's working memory, up to three,\xa0..."}]
[{'title': "LLM Powered Autonomous Agents | Lil'Log", 'link': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'snippet': "Jun 23, 2023 ... Fig. 1. Overview of a LLM-powered autonomous agent system. ... Then reflections are added into the agent's working memory, up to three,\xa0..."}]
```

This fails -
`query='1. "What is the working mechanism of LLM Powered Autonomous Agents?"'`
```
QUERY
1. "What is the working mechanism of LLM Powered Autonomous Agents?"
RESULT
[{'Result': 'No good Google Search Result was found'}]
[{'Result': 'No good Google Search Result was found'}]
```

Local testing w/ Streamlit:
![image](https://github.com/langchain-ai/langchain/assets/122662504/0a7e3dca-59e8-415e-8df6-bd9e4ea962ee)
ImportError: cannot import name 'ApifyWrapper' from 'langchain.utilities'
Labels: name: area: doc loader, name: auto:bug

### System Info

Hi All,
I tried to run Apify tutorial and I ran on the issue of ImportError: cannot import name 'ApifyWrapper' from 'langchain.utilities'. I checked the Utilities library under utilities/__init__.py and I couldn't find anything under the Generic integrations with third-party systems and packages.
Any thoughts or support?

### Who can help?

@hwchase17, @agola

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

### Reproduction

import os

openai.api_key = os.environ["OPEN_API_KEY"]
os.environ["APIFY_API_TOKEN"] = "apify_api_qNa00bcYGUYFwIZltWiOuhskmer7E61VE6GN"

apify = ApifyWrapper()

loader = apify.call_actor(
    actor_id="apify/website-content-crawler",
    run_input={"startUrls": [{"url": "https://python.langchain.com/en/latest/"}]},
    dataset_mapping_function=lambda item: Document(
        page_content=item["text"] or "", metadata={"source": item["url"]}
    ),
)
index = VectorstoreIndexCreator().from_loaders([loader])

query = "What is LangChain?"
result = index.query_with_sources(query)

print(result["answer"])
print(result["sources"])

### Expected behavior

LangChain is a standard interface through which you can interact with a variety of large language models (LLMs). It provides modules that can be used to build language model applications, and it also provides chains and agents with memory capabilities.
    
https://python.langchain.com/en/latest/modules/models/llms.html, https://python.langchain.com/en/latest/getting_started/getting_started.html
Make a return_direct of a tool's output under certain conditions
Labels: name: area: agent, name: auto:enhancement

### Feature request

Possibility to make a direct return of a tool's output on certain cases. 

### Motivation

Under specific circumstances, it would be extremely beneficial to be able to return a tool's output directly to the user. For instance, this feature would be helpful when using a search tool. If a search made no matches, a response can be directly sent to the user. Without being able to make a direct return, the tool's output is sent to the LLM, making the LLM prone to hallucinate the final answer.

### Your contribution

I am not sure how this could be implemented, but would gladly help working on any ideas.
VertexAI using `text-bison` returns no output
Labels: name: auto:bug

### System Info

Pop!_OS 22.04 LTS
Python 3.11.4
Langchain v0.0.242

### Who can help?

@hwchase17 
@agola11 

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

`code-bison` works fine, `text-bison` returns no output. I've got full `Vertex AI User` perms, and every other model, including the chat models work fine in my config.

```
>>> from langchain.llms.vertexai import VertexAI
>>> llm = VertexAI(model_name="code-bison")
>>> llm("say hello")
'Hello! How are you doing today?'
>>> llm = VertexAI(model_name="text-bison")
>>> llm("say hello")
''
>>>
```

### Expected behavior

`text-bison` should return content.
fix missing _identifying_params() in _VertexAICommon
Labels: name: needs test, name: auto:bug

Full set of params are missing from Vertex* LLMs when `dict()` method is called.

```
>>> from langchain.chat_models.vertexai import ChatVertexAI
>>> from langchain.llms.vertexai import VertexAI
>>> chat_llm = ChatVertexAI()
l>>> llm = VertexAI()
>>> chat_llm.dict()
{'_type': 'vertexai'}
>>> llm.dict()
{'_type': 'vertexai'}
```

This PR just uses the same mechanism used elsewhere to expose the full params.

Since `_identifying_params()` is on the `_VertexAICommon` class, it should cover the chat and non-chat cases.
Bug Fix: AzureChatOpenAI streaming with function calls
Labels: name: area: agent, name: auto:bug

 - Description: During streaming, the first chunk may only contain the name of an OpenAI function and not any arguments. In this case, the current code presumes there is a streaming response and tries to append to it, but gets a KeyError. This fixes that case by checking if the arguments key exists, and if not, creates a new entry instead of appending.
  - Issue: Related to #6462
  - Tag maintainer: @hwchase17, @baskaryan

Sample Code:
```python
llm = AzureChatOpenAI(
    deployment_name=deployment_name,
    model_name=model_name,
    streaming=True
)

tools = [PythonREPLTool()]
callbacks = [StreamingStdOutCallbackHandler()]

agent = initialize_agent(
    tools=tools,
    llm=llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    callbacks=callbacks
)

agent('Run some python code to test your interpreter')
```

Previous Result:
```
File ...langchain/chat_models/openai.py:344, in ChatOpenAI._generate(self, messages, stop, run_manager, **kwargs)
    342         function_call = _function_call
    343     else:
--> 344         function_call["arguments"] += _function_call["arguments"]
    345 if run_manager:
    346     run_manager.on_llm_new_token(token)

KeyError: 'arguments'
```

New Result:
```python
{'input': 'Run some python code to test your interpreter',
 'output': "The Python code `print('Hello, World!')` has been executed successfully, and the output `Hello, World!` has been printed."}
```
installing pip install langchain[all] installs the old version of langchain 0.0.39 
Labels: name: auto:bug

### System Info

When i install for the first time using this command
```
pip install 'langchain[all]'
```
It installs the older version `langchain 0.0.39` 

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

1. pip install 'langchain[all]'


### Expected behavior

It should install the latest version of langchain
Refactored `load`
Labels: name: area: doc loader, name: auto:refactor

Refactored `load`. The same as https://github.com/langchain-ai/langchain/pull/7961 #8098 #8099 
`load` is in the root code folder. This creates the `langchain.load: Load` group on the API Reference navigation ToC, on the same level as Chains and Agents which is incorrect.

Refactoring:

- copied `load/serializable.py`, `load/load.py`, `load/dump.py` files into `utils/`
- added the backwards compatibility ref in a new `langchain/load.py` 
- updated imports to `load` objects
- applied a standard comment, """DEPRECATED: Kept for backwards compatibility.""" to all "deprecated" files in root folder

@baskaryan
fix: ElasticVectorSearch.from_documents failed #8293
Labels: name: lgtm, name: area: vector store, name: auto:bug

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: fix ElasticVectorSearch.from_documents with elasticsearch_url param, 
  - Issue: ElasticVectorSearch.from_documents failed #8293 # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: @rlancemartin, @eyurtsev,
  - 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
 -->
Generic LLM wrapper to support chat model interface with configurable chat prompt format
Labels: name: lgtm, name: auto:enhancement

## Update 2023-09-08

This PR now supports further models in addition to Lllama-2 chat models. See [this comment](#issuecomment-1668988543) for further details. The title of this PR has been updated accordingly.

## Original PR description

This PR adds a generic `Llama2Chat` model, a wrapper for LLMs able to serve Llama-2 chat models (like `LlamaCPP`, `HuggingFaceTextGenInference`, ...). It implements `BaseChatModel`, converts a list of chat messages into the [required Llama-2 chat prompt format](https://huggingface.co/blog/llama2#how-to-prompt-llama-2) and forwards the formatted prompt as `str` to the wrapped `LLM`. Usage example:

```python
# uses a locally hosted Llama2 chat model
llm = HuggingFaceTextGenInference(
    inference_server_url="http://127.0.0.1:8080/",
    max_new_tokens=512,
    top_k=50,
    temperature=0.1,
    repetition_penalty=1.03,
)

# Wrap llm to support Llama2 chat prompt format.
# Resulting model is a chat model
model = Llama2Chat(llm=llm)

messages = [
    SystemMessage(content="You are a helpful assistant."),
    MessagesPlaceholder(variable_name="chat_history"),
    HumanMessagePromptTemplate.from_template("{text}"),
]

prompt = ChatPromptTemplate.from_messages(messages)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
chain = LLMChain(llm=model, prompt=prompt, memory=memory)

# use chat model in a conversation
# ...
```

Also part of this PR are tests and a demo notebook.

- Tag maintainer: @hwchase17
- Twitter handle: `@mrt1nz`
giving path to the copy command for *.toml files
Labels: name: auto:bug

Description: in the .devcontainer, docker-compose build is currently failing due to the src paths in the COPY command. This change adds the full path to the pyproject.toml and poetry.toml to allow the build to run.
Issue: 

You can see the issue if you try to build the dev docker image with:
```
cd .devcontainer
docker-compose build
```

Dependencies: none
Twitter handle: byronsalty
ElasticVectorSearch.from_documents failed
Labels: name: area: vector store, name: auto:bug

### System Info

python = 3.9
es = 8.9
langchain = 0.0.237

### 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
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```python
url = 'https://elastic:xxx@xxxx:8447'
docsearch = ElasticVectorSearch.from_documents(
    split_docs,
    embeddings,
    elasticsearch_url=url,
    index_name="my_index",
    ssl_verify={
        "verify_certs": True,
        "basic_auth": ("elastic", "xxx"),
        "ca_certs": "./data/xxxx"
    },
)
```
then get error:
`__init__() got multiple values for argument 'elasticsearch_url'`

![image](https://github.com/langchain-ai/langchain/assets/44490504/34adc275-aa2e-4d01-ae4e-d70888d07e0e)

in: https://github.com/langchain-ai/langchain/blob/5c6dcb1960b717aaf70413ed0b467bffc4fc0be8/libs/langchain/langchain/vectorstores/elastic_vector_search.py#L298

add this then work:
```
del kwargs['elasticsearch_url']
```



### Expected behavior

no error
DuckDuckGoSearch News Tool
Labels: name: lgtm, name: auto:improvement

Description: 
I wanted to use the DuckDuckGoSearch tool in an agent to let him get the latest news for a topic. DuckDuckGoSearch has already an implemented function for retrieving news articles. But there wasn't a tool to use it. I simply adapted the SearchResult class with an extra argument "backend". You can set it to "news" to only get news articles.

Furthermore, I added an example to the DuckDuckGo Notebook on how to further customize the results by using the DuckDuckGoSearchAPIWrapper.

Dependencies: no new dependencies

@hinthornw
cannot clear memory when token limit exceeded
Labels: name: area: memory, name: area: agent, name: auto:bug

### System Info

Langchain version - 0.0.208
openAI - 3.5-turbo

### Who can help?

_No response_

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

### Reproduction

i have a chat built on top of OpenAI , i have memory of 1 in the conversation.
the problem is that sometimes when the prompt is very long i hit the token limit from openAI .
i tried to clean the conversation memory to allow next question to succeed with :
agent.memory.clear()

but it doesnt seem to work, and all subsequent queries are failing on openai.error.InvalidRequestError 

this is my agent creation code :

chatgpt_chain = LLMChain(
        llm=ChatOpenAI(temperature=0, model_name=settings.model_name),  # type: ignore
        prompt=prompt,
        verbose=False,
        # memory=ConversationBufferWindowMemory(k=1),
    )

    tools = [PythonAstREPLTool()]

    custom_agent = LLMSingleActionAgent(
        llm_chain=chatgpt_chain,
        output_parser=my_output_parser,
        stop=["\nObservation:"],
    )

    agent_memory = ConversationBufferWindowMemory(k=1)

    return AgentExecutor.from_agent_and_tools(
        agent=custom_agent,
        tools=tools,
        verbose=True,
        memory=agent_memory,
    )

### Expected behavior

i expected the memory to be clear and continue to work with the agent
Fix for code snippet in documentation
Labels: name: lgtm, name: auto:bug

<!-- 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
 -->
- Description: I fixed an issue in the code snippet related to the variable name and the evaluation of its length. The original code used the variable "docs," but the correct variable name is "docs_svm" after using the SVMRetriever.
- maintainer: @baskaryan
- Twitter handle: @iamreechi_
fix: overwrite stream for ChatOpenAI in runtime
Labels: name: auto:bug

<!-- 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
 -->
@hwchase17, @baskaryan
Issue: Performance of Agents or Chains dropping when used as routers in an Agent.
Labels: name: area: agent, name: auto:bug, name: auto:question

### Issue you'd like to raise.

I have defined several Chains (LLM Chains, RetrievalQA and ConversationalRelationChain) and have used an agent to route between them after I created for each their respective Tool.
I realised that when each chain was defined outside of the agent, their performance was amazing. But once you add them up as routes in the agent, their performance drops significantly.
The exact same questions that they manage to answer to outside of the routing system (agent) are answered incorrectly when used as a route in the Agent.

Is anyone else facing this issue or is it only me? Is it fixable? 

### Suggestion:

_No response_
add test for embedding distance evaluation
Labels: name: lgtm, name: area: embeddings, name: auto:improvement

Add tests for embedding distance evaluation

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: Add tests for embedding distance evaluation
  - Issue: None
  - Dependencies: None
  - Tag maintainer: @baskaryan
  - Twitter handle: @MlopsJ

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
 -->
Avoid re-computation of embedding in weaviate similarity search
Labels: name: lgtm, name: area: vector store, 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
 -->
Upgrade the AwaDB from v0.3.7 to v0.3.9 and change the default embeddings
Labels: name: lgtm, name: area: vector store, name: auto:improvement

1. Upgrade the AwaDB from v0.3.7 to v0.3.9
2. Change the default embedding to AwaEmbedding

@rlancemartin, @eyurtsev Please review, thanks!