delayedkarma/langchain-issues huggingface dataset:
Get the code applied by the pandas agent
Labels: name: area: agent, name: auto:bug

### System Info

I am using the below code to make an agent that decides, upon the question, whether to use semantic search or pandas agent
to answer the question about a dataset of employees


### Who can help?

_No response_

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

### Reproduction

```
semantic_retrieval_chain = RetrievalQA.from_llm(
    OpenAI(temperature=0),
    retriever=vectorstore.as_retriever(),
    return_source_documents=True,
    # memory=memory
)


agg_df = pd.read_csv(TMP_FILE_PATH, index_col=0).iloc[:, :-1]


aggregation_agent = create_pandas_dataframe_agent(
    OpenAI(temperature=0),
    agg_df,
    verbose=True,
    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    include_df_in_prompt=True,
    # handle_parse_errors=True,
    # suffix="Assistant also handles parsing errors.",
)

tools = [
    Tool(
        name = "Semantic Search",
        func=semantic_retrieval_chain,
        description="""useful for retrieving employees similar to a given query specifications and answering questions not involving aggregations and operations over more than one employee"""
    ),
    Tool(
        name = "Aggregation Agent",
        func=aggregation_agent.run,
        description="useful for answering questions involving aggregations and descriptive statistics over more than one employee"
    ),
]

llm=OpenAI(temperature=0)

agent_chain = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    return_intermediate_steps=True,
    # memory=memory
)
```
I was able to successfully get the documents retrieved by the semantic search tool, but when I set the return_intermediate_step to True for the aggregation agent, I had the following error:
**NotImplementedError: Saving not supported for this chain type.**


### Expected behavior

I want to get the code for the pandas agent (aggregation_agent above) whenever it is invoked. I am extremely in need for this feature to be able to display the rows (if any) from the appropriate dataframe. Thanks in advance for any help.
ChatLangChain requesting _default_relevance_score_fn' on <module 'langchain.vectorstores.faiss> on init
Labels: name: area: vector store, name: auto:bug

### System Info

Langchain 0.0.237.
Python 3.11
Mac OS X M1

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

make start. 
INFO:     Uvicorn running on http://127.0.0.1:9002 (Press CTRL+C to quit)
INFO:     Started reloader process [80851] using StatReload
INFO:     Started server process [80855]
INFO:     Waiting for application startup.
in startup_event
AttributeError: Can't get attribute '_default_relevance_score_fn'

### Expected behavior

Load the chat.
Note: the faiss wrapper seems updated back in May to from _default_relevance_score_fn to relevance_score_fn
OutputFixingParser is not async
Labels: name: area: agent, name: auto:bug

### System Info

LangChain Python v0.0.237

Based on this code snippet it appears that OutputFixingParser doesn't support async flows.
https://github.com/hwchase17/langchain/blob/df84e1bb64d96377f909651f696f310c43c2f2c5/langchain/output_parsers/fix.py#L46-L52

It's calling the run function and not arun

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

### Reproduction

1. Define async callback handler
2. Make LLM return output that is unparsable (invalid JSON or 2 code blocks)
3. OutputFixingParser will fail parsing the output and throw an exception, which will call the LLM via the run function which doesn't await on coroutines. Python will give the following error:
```
RuntimeWarning: coroutine 'AsyncCallbackHandler.on_chat_model_start' was never awaited
```

### Expected behavior

1. Should work with coroutines as expected
Fix key errors in weaviate hybrid retriever init
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
 -->
Redis does not use the parameters passed in by Redis.as_retriever()
Labels: name: area: vector store, name: auto:bug

### System Info

langchain==0.0.237
python==3.8.16

### Who can help?

@hwchase17 @agola11 

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

same issue as https://github.com/hwchase17/langchain/issues/6984 but for Redis, but the proposed fix does not work

llm = OpenAI(temperature=0.1)
question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT)
doc_chain = load_qa_with_sources_chain(llm, chain_type="stuff")
retriever = db.as_retriever(search_kwargs={"k": 10})

chain = ConversationalRetrievalChain(
    retriever=retriever, #redis retriever
    question_generator=question_generator,
    combine_docs_chain=doc_chain,
    return_source_documents=True,
)

### Expected behavior

query = "who slayed Karna in the battle?"
result = chain({"question": query})

print(len(result['source_documents'])) #ouput: 4 but should be 10
Allow user to modify the GPU and language settings when using NLP Cloud
Labels: name: lgtm, name: area: embeddings, name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: allow user to modify the GPU and language settings when using NLP Cloud, 
  - Tag maintainer: @rlancemartin ,
  - Twitter handle: @cloud_nlp

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
 -->
Fix incorrect field name in MLflow AI Gateway config example
Labels: 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
 -->
TypeError: create_extraction_chain() got an unexpected keyword argument 'verbose'
Labels: name: area: doc loader, name: auto:improvement

### Feature request

Almost all the chains offered in langchain framework support Verbose option which helps the developers understand what prompt is being applied under the hood and plan their work accordingly. It immensely help while debugging. create_extraction_chain is a very helpful one and I found this is not accepting verbose attribute.

### Motivation

For many developers who are just following the langchain official documentation and not looking at the code used under the hood, this error will sound odd. Supporting this attribute will help in keeping things consistent and improve debugging feature of this chain

### Your contribution

I can raise the PR for this
![Screenshot 2023-07-20 at 12 34 55 PM](https://github.com/hwchase17/langchain/assets/8801972/18b248df-1a7c-49cf-a9b1-3101e6928631)
Agent does not use max_tokens parameter from ChatOpenAI
Labels: name: area: agent, name: auto:question

### Issue you'd like to raise.

How do you increase the max_tokens for the agent? I am using gpt35turbo16k. I notice that the model is only using ~4096 tokens. Is there a way to override this?

The reason I am asking is I am ingesting large text in the prompt and the final answer I am getting is so short that does not have any meeting.

Thanks!

### Suggestion:

_No response_
Issue: How to pass in database name parameter into Milvus
Labels: name: area: vector store, name: auto:question

### Issue you'd like to raise.

![image](https://github.com/hwchase17/langchain/assets/49942750/e6cf4a3a-da28-4133-9f3e-9b9998d0adb2)

In Milvus, we are able to create databases and create collections within the database itself. Hence i will be able to create a collection with the same name in different databases. How can we specify the specific database and collection to use, currently the parameters only accept collection_name and not db_name like in pymilvus.



### Suggestion:

_No response_
Issue: integrate local LLM (from huggingface) into load_qa_chain
Labels: name: area: embeddings, name: auto:question, name: auto:enhancement

### Issue you'd like to raise.

Hi, I'm trying to use some LLM model from huggingface, for example "model_name=lmsys/vicuna-13b-v1.3", in the chain `load_qa_chain`. The LLM model could be fetched through AutoModelForCausalLM.from_pretrained, e.g.

```
model = AutoModelForCausalLM.from_pretrained(
        model_name,
        torch_dtype=torch.bfloat16,
        device_map={"": 0},
    )
```

What's the best way (memory efficient) to wrap the model for integration with load_qa_chain?

### Suggestion:

_No response_
Serpapi API key not working with Langchain 
Labels: name: auto:bug

### Issue you'd like to raise.

I have a valid serpapi API key that I can use in the serpapi playground and with direct calls using python requests, but when I use it with Langchain I get an error saying that the key is invalid. I have my key set as environment variable, but I continue to get this error:

ValueError: Got error from SerpAPI: Invalid API key. Your API key should be here: https://serpapi.com/manage-api-key

I have even got a new API key with the same results. I have tried Pydroid3 for Android, Ubuntu in Termux for Android (64 bit), and Ubuntu in AWS ec2, with the same result.

### Suggestion:

_No response_
Argument 'string' has incorrect type (expected str, got lxml.etree._ElementUnicodeResult)
Labels: name: area: doc loader, name: auto:bug

### System Info

LangChain version is the latest one - 0.0.237

### Who can help?

_No response_

### Information

- [ ] 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

```python
def text_split(documents):
    text_splitter = SpacyTextSplitter(chunk_size=1000, chunk_overlap=10, separator='\n')
    texts = []
    for document in documents:
        texts.extend(text_splitter.split_documents(document.load()))
    return texts
```
Using this simple code, I get this error:
```
  Traceback (most recent call last):
 ...
    File "/opt/project/main/genie.py", line 41, in text_split
      texts.extend(text_splitter.split_documents(document.load()))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 131, in split_documents
      return self.create_documents(texts, metadatas=metadatas)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 116, in create_documents
      for chunk in self.split_text(text):
                   ^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 1047, in split_text
      splits = (s.text for s in self._tokenizer(text).sents)
                                ^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1030, in __call__
      doc = self._ensure_doc(text)
            ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1121, in _ensure_doc
      return self.make_doc(doc_like)
             ^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1113, in make_doc
      return self.tokenizer(text)
             ^^^^^^^^^^^^^^^^^^^^
  TypeError: Argument 'string' has incorrect type (expected str, got lxml.etree._ElementUnicodeResult)
```
I've also tried approach with alternative `split_text` method, but still getting the same error.

### Expected behavior

If I put a breakpoint at [langchain/text_splitter.py:116](https://github.com/hwchase17/langchain/blob/master/langchain/text_splitter.py#L116) and execute `text = str(text)` and resume the process, only then it works.
Doc metadata can get passed into prompt unexpectedly 
Labels: name: auto:bug

### System Info

Mac M2 Max 32GB

### Who can help?

@rlancemartin 

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

We pass docs into a prompt, and pass prompt to an LLM chain:
```
# Prompt
prompt = PromptTemplate.from_template(
    "Human: Summarize the main themes in these retrieved docs: {docs} Assistant: "
)

# Chain
llm_chain = LLMChain(llm=llm, prompt=prompt)

# Run
question = "What are the approaches to Task Decomposition?"
docs = vectorstore.similarity_search(question)
result = llm_chain(docs)
```

The doc metadata gets formatted w/ prompt and passed to LLM.

This can cause hallucination (relative to intended doc page_content) if metadata contain irrelevant information.

It also chews up tokens potentially with redundant information.

See good example here:
https://smith.langchain.com/public/9af32e5b-2ca9-41d9-a5a6-8243b218208a/r

### Expected behavior

Only pass `page_content` from retrieved documents into the prompt.
Issue: [Azure] Summary chain with chat 3.5 turbo - Not being parallelized
Labels: name: auto:question

### Issue you'd like to raise.

Hi,

Not sure if someone is facting this "issue" or is something wrong I'm doing.
So far .. I read, GPT 3.5 turbo and later should be used with "chat_models" instead of "models". While testing the "summary" chaing (map_reduce). I noticed that using "model" llm it does indeed run in parallel, but using chat_model does run in sequence.

From the src in langchain .. I saw:

[langchain][chains][combine_documents] map_reduce.py
> map_results = await self.llm_chain.aapply(
            # FYI - this is parallelized and so it is fast.
            [{**{self.document_variable_name: d.page_content}, **kwargs} for d in docs],
            callbacks=callbacks,
        )

And tracing the execution down 
**AzureOpenAI chat_model**: it will execute a for loop and wait for the response. Multiple API calls to the endpoint

> results.append(
                    self._generate_with_cache(
                        m,
                        stop=stop,
                        run_manager=run_managers[i] if run_managers else None,
                        **kwargs,
                    )
                )

**AzureOpenAI model**: (aka completion) ... it generates a single call with all the prompts.
> response = completion_with_retry(self, prompt=_prompts, **params)

And here are my outcomes:
- Using ChatModel (azure) ... it works as expected, following the prompt and creating the expected output, but in a sequential execution.
- Using LLM Model (azure - aka completion) ... it runs in parallel, but the "summaries" are not correct, it "creates ramdon content" not related to the topic (I have set the temperature to 0 and top_p 0.9) ... but still does not "creates" summaries of provided text.

So my question/concerns are:

1. Is summarization chain expected to run in parallel mode with chatModel LLMs? If so ... can anyone provide a sample .. can't make it to work in parallel.
2. Is "completion llms" (aka normal llm model) only good for "generating content" but not for "summaries"? Using gpt 3.5 turbo?

Thanks for your help in advace.

### Suggestion:

_No response_
Refactored `math_utils`
Labels: name: auto:refactor

`math_utils.py` is in the root code folder. This creates the `langchain.math_utils: Math Utils` group on the API Reference navigation ToC, on the same level with `Chains` and `Agents` which is not correct.

Refactoring:
- created the `utils/` folder
- moved `math_utils.py` to `utils/math.py`
- moved `utils.py` to `utils/utils.py`
- split `utils.py` into `utils.py, env.py, strings.py`
- added module description

@baskaryan
AgentType.OPENAI_MULTI_FUNCTIONS with FAISS VectorStore results with "ToolException('Too many arguments to single-input" error 
Labels: name: area: agent, name: area: vector store, name: auto:bug

### System Info

langchain 0.0.237
python 3.10

### Who can help?

_No response_

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

### Reproduction

i have an agent of type AgentType.OPENAI_MULTI_FUNCTIONS and AzureChatOpenAI LLM. I'm trying to use the FAISS embedding capabilities with a VectorStore, 
as shown in this example https://techcommunity.microsoft.com/t5/startups-at-microsoft/build-a-chatbot-to-query-your-documentation-using-langchain-and/ba-p/3833134

combine with the instructions here on how to work with agents and vector store
https://python.langchain.com/docs/modules/agents/how_to/agent_vectorstore

while the chain seems to be calling the desired function in order to do a similiarity search

` "generations": [
    [
      {
        "text": "",
        "generation_info": {
          "finish_reason": "function_call"
        },
        "message": {
          "lc": 1,
          "type": "constructor",
          "id": [
            "langchain",
            "schema",
            "messages",
            "AIMessage"
          ],
          "kwargs": {
            "content": "",
            "additional_kwargs": {
              "function_call": {
                "name": "tool_selection",
                "arguments": "{\n  \"actions\": [\n    {\n      \"action_name\": \"<<MY_FUNCTION_NAME>>\",\n      \"action\": {}\n    }\n  ]\n}"
              }
            }
          }
        }
      }
    ]
  ]`

the function call to qa Tool fails with the error "ToolException('Too many arguments to single-input tool <<MY_FUNCTION_NAME>>. Args: []')"

any idea what may cause this error ?



### Expected behavior

similarity search works as expected (same as here https://python.langchain.com/docs/modules/agents/how_to/agent_vectorstore ) even when using AgentType.OPENAI_MULTI_FUNCTIONS agent