delayedkarma/langchain-issues huggingface dataset:
Fixing issue with MSSQL connection
Labels: name: lgtm, name: auto:bug

My team recently faced an issue while using MSSQL and passing a schema name.

We noticed that "SET search_path TO {self.schema}" is being called for us, which is not a valid ms-sql query, and is specific to postgresql dialect.

We were able to run it locally after this fix.

<!-- 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
 -->
Provides access to a Document page_content formatter in the AmazonKendraRetriever
Labels: name: auto:improvement

- Description: 
    - Provides a new attribute in the AmazonKendraRetriever which processes a ResultItem and returns a string that will be used as page_content;
    - The excerpt metadata should not be changed, it will be kept as was retrieved. But it is cleaned when composing the page_content;
    - Refactors the AmazonKendraRetriever to improve code reusability;
- Issue: #7787 
- Tag maintainer: @3coins @baskaryan
- Twitter handle: wilsonleao

**Why?**

Some use cases need to adjust the page_content by dynamically combining the ResultItem attributes depending on the context of the item.
Update mongodb_atlas.py docstrings
Labels: name: lgtm, name: area: vector store, name: auto:documentation

Hi all, I just added the "index_name" parameter to the docstrings for mongodb_atlas.py (it is missing in the [public doc page](https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html#langchain-vectorstores-mongodb-atlas-mongodbatlasvectorsearch).

@rlancemartin 

Thanks
Streaming support for Oobabooga API?
Labels: name: auto:improvement

### Feature request

Update `TextGen` to include `streaming` support for Oobabooga.

### Motivation

Oobabooga provides a streaming API that will be very helpful. [TextGen](https://github.com/hwchase17/langchain/pull/5997) already supports the regular API.

### Your contribution

:)
Retriever that can re-phase user inputs 
Labels: name: lgtm, name: auto:enhancement

Simple retriever that applies an LLM between the user input and the query pass the to retriever.

It can be used to pre-process the user input in any way.

The default prompt:

```
DEFAULT_QUERY_PROMPT = PromptTemplate(
    input_variables=["question"],
    template="""You are an assistant tasked with taking a natural languge query from a user
    and converting it into a query for a vectorstore. In this process, you strip out
    information that is not relevant for the retrieval task. Here is the user query: {question} """
)
```
fix: create schema description from URIs and str w/out rdflib warnings
Labels: name: area: memory, name: auto:bug

- Description: fix to avoid rdflib warnings when concatenating URIs and strings to create the text snippet for the knowledge graph's schema. @marioscrock pointed this out in a comment related to #7165
- Issue: None, but the problem was mentioned as a comment in #7165
- Dependencies: None
- Tag maintainer: Related to memory -> @hwchase17, maybe @baskaryan as it is a fix
Agents and agent executor are 2 different concepts and shouldn't be placed in the same bucket
Labels: name: area: agent, name: auto:enhancement, name: auto:refactor

### Feature request

This probably needs more refinement but how but there are a lot of components floating around that overlaps with one another.

As per my understanding, the broader categorization should be:
Chains: Simple scenarios - steps are hardcoded
Agent Executors: Complex scenarios - steps are determined on runtime

Agent Executor internally uses an agent to plan the next step. In that sense, the agents can probably be renamed to just planners, and agent executors can then be simply called agents(?)

Both the chains and agents can use tools (or toolkits) to execute steps in their chain.

This simplifies the overall architecture and makes the components intuitive.

### Motivation

As a beginner, I'm struggling with all the components floating around, and reducing the overall components in the core architecture reduces the learning curve of devs.

### Your contribution

Yes, I can to work on the PR if this change gets approval.
Add a str representation for the Message
Labels: name: auto:improvement

### Feature request

E.g., it would be great if 
```
m = AIMessage(content="Hi!")
print(m)
```
returned something like "AI: Hi!"


### Motivation

It would make representation of message history (e.g., for debugging or serialization into a json) a little bit easier.

### Your contribution

yes, I'm happy to do it.
Extract Final Thoughts from Agent as part of Final Answer.
Labels: name: area: agent, name: auto:question

### Issue you'd like to raise.

How do you extract the last thought process from an agent?

The final answer from the agent is too summarized for my liking. However the 'Final Thought' process is great with all the details. I am having some difficulties extracting that information event with `return_immediate_steps=True`. 

Is there anyway I can get that final thought information as part of the Final Answer?

### Suggestion:

_No response_
fix: catch pydantic validation errors
Labels: name: area: agent, name: auto:bug

This PR proposes a fix to catch `pydantic` `ValidationErrors` and request a fix of the arguments to the LLM, instead of the error stopping the execution. 

The change is implemented within the `_take_next_step` and `_atake_next_step` methods of the `AgentExecutor`, where the `tool.run` is now within a `try` block. If during the execution of `tool.run` a `ValidationError` is raised, an except block now catches said error and turns the observation into a request for the LLM to fix the arguments for the requested action.

This proposed fix improves the reliability of the `AgentExecutor`.

 - Maintainer: @hinthornw 
 - Twitter handle: @aledelunap
FLARE Implementation with Local Fine-Tuned Models
Labels: name: auto:enhancement

### Feature request

I am writing to request an enhancement for the FLARE chain in Langchain. I'm wondering how I can change the class to accept local (fine-tuned) models rather then use OpenAi API. Since FLARE uses a retriever, a question generator, and a response generator, it would be interesting to leverage the strength of newer models, or even custom fine-tuned ones.

### Motivation

By doing so, it would give more flexibility to experiment with different models, and not rely on OpenAi, hence making it more open-source.

### Your contribution

I would envision the future syntax to look something like this:
```
from langchain.chains import FlareChain


flare_chain = FlareChain(
    question_generator_chain=question_generator,  
    response_chain=response_generator,  
    output_parser=None,  # Replace with the output parser if available
    retriever=retriever, 
    min_prob=0.2,
    min_token_gap=5,
    num_pad_tokens=2,
    max_iter=10,
    start_with_retrieval=True,
)

```
The models will be imported like so:
```
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from langchain.chains import RetrievalQA


tokenizer = AutoTokenizer.from_pretrained(model_id)
response_generator = AutoModelForCausalLM.from_pretrained(model_id, device_map='auto')

tokenizer = AutoTokenizer.from_pretrained("model_id_1")
question_generator = AutoModelForSeq2SeqLM.from_pretrained("model_id_1")

retriever= RetrievalQA.from_chain_type(llm=model, chain_type="stuff", retriever=docsearch.as_retriever())
```
Update Modal.com integration docs
Labels: name: lgtm, name: auto:documentation

Hey, I'm a Modal Labs engineer and I'm making this docs update after getting a user question in [our beta Slack space](https://join.slack.com/t/modalbetatesters/shared_invite/zt-1xl9gbob8-1QDgUY7_PRPg6dQ49hqEeQ) about the Langchain integration docs.

🔗  [Modal beta-testers link to docs discussion thread](https://modalbetatesters.slack.com/archives/C031Z7DBQFL/p1689777700594819?thread_ts=1689775859.855849&cid=C031Z7DBQFL)

@baskaryan (no one is specifically listed as docs person)
What is the difference between OpenAI Function and OpenAI Multi Functions Agent
Labels: name: area: agent, name: auto:question, name: auto:documentation

### Issue you'd like to raise.

I was looking up the documentation as well. However, from the documentation it seems as if both types of agents are doing the same thing. Even when I looked at the backend code, both agent codes seemed almost identical. I am not so sure what I am missing in terms of my understanding. Any leads would be appreciated. 

### Suggestion:

Documentation between the two types can be made more clear.
Error in OpenAI Functions Agent 
Labels: name: area: agent, name: auto:bug, name: auto:documentation

### Issue with current documentation:

Hello every one! 

I am following the tutorial of the use of agents. Specifically, now I am exploring the type [OpenAIFunctions. ](https://python.langchain.com/docs/modules/agents/agent_types/openai_functions_agent).

I am following the exact same tutorial and I get some error when I want to use the agent to solve some math problems or connect to my SQL Data base which are tools that the agents have available. The error that I have is the following: 

```python
ValidationError: 1 validation error for AIMessage
content
  none is not an allowed value (type=type_error.none.not_allowed)
```


Does any one know what is causing this error? 

Best regards, 
Orlando
Bagatur/apify
Labels: name: lgtm

<!-- 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
 -->
Support multiple filters for ElasticVectorStore
Labels: name: area: vector store, name: auto:improvement

This PR will
- Enable the ElasticVectorStore to support multiple filters (combine all the filters using `AND` operator)
- Put the query in a filter context ensuring that the scores of the retrieved documents are not affected by the number of filters.  (For reference on the difference between query context and filter context see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html#filter-context)
- add support for arbitrary elasticsearch query as filter using the `filter_is_es_query` toggle

 
@rlancemartin, @eyurtsev
Issue: Using "llama-2-70b-chat/ggml-model-q4_0.bin" with LlamaCpp()
Labels: name: auto:bug, name: auto:question

### Issue you'd like to raise.

Hi Everyone, 

I am trying to use `llama-2-70b-chat` with the LlamaCpp() as described here : https://python.langchain.com/docs/modules/model_io/models/llms/integrations/llamacpp#metal

My system specs are
MacBook Pro, M1 Chip, 16GB, 500GB SSD

Here is my code using LlamaCpp:

```
DEFAULT_CHAT_MODEL_LLAMA = '/Volumes/Gargantua/LLAA2/llama-2-70b-chat/ggml-model-q4_0.bin'
class HelpprBaseLLAMAV2(LlamaCpp):
    
    model_path = DEFAULT_CHAT_MODEL_LLAMA
    callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
    verbose = True
    input = {"temperature": 0.75, "top_p": 1, "max_length": 2048}
    n_gpu_layers = 1
    n_batch = 512
    f16_kv = True
```

Whenever I call `llm = HelpprBaseLLAMAV2()`  via the following: 

```
(venv) tapanjain@MacBook-Pro-2 helppr % python main.py
```

I get the following error: 

```
zsh: illegal hardware instruction  python main.py
```

Can anyone help me what exactly is the reason here? Is langchain right now not supported for llama 2?


### Suggestion:

_No response_
Difference between  ConversationBufferMemory and chat_history parameter
Labels: name: area: memory, name: auto:question

### Issue you'd like to raise.

I came to know that there are two methods to keep memory in **ConversationalRetrievalChain**

1. Method -1
Using **ConversationBufferMemory**
```
from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory(
    memory_key="chat_history",
    return_messages=True
)

qa= ConversationalRetrievalChain.from_llm(
    llm,
    retriever=retriever),
    memory=memory
)
```

3. Method -2
Using **chat_history** parameter
```
from langchain.chains import ConversationalRetrievalChain
qa= ConversationalRetrievalChain.from_llm(
    llm,
    retriever=retriever)
)
chat_history = []
result = qa({"question": question, "chat_history": chat_history})

```

What is the exact difference between the above two methods?  When should use one over another and why?

### Suggestion:

_No response_
APIfy dataset loader does not provide the attribute "page_content" in the loaded documents
Labels: name: area: doc loader, name: area: vector store, name: auto:bug

### System Info

Langchain Version== 0.0.237
Platform == Google Colaboratory





### Who can help?

@eyurtsev 


### Information

- [X] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [X] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Step 1: Import packages

Step 2: Use APIfy dataset loader

loader = ApifyDatasetLoader(
    dataset_id="KCoOphOr1tQmmUhsS",
    dataset_mapping_function=lambda item: Document(
        page_content=item["description"] or "name", metadata={"id": item["id"]}
    ),
)

Step 3: Attempt to create a vector store index

from langchain.indexes import VectorstoreIndexCreator

index = VectorstoreIndexCreator().from_loaders([loader])



### Expected behavior

It should create the index from the data loader provided, but the loader does not produce the attribute "page content" when loading APIfy datasets.

<img width="919" alt="Screenshot 2023-07-19 at 12 24 02" src="https://github.com/hwchase17/langchain/assets/63857960/11aee742-c513-4cc6-863e-56c5e10a43db">
Issue: <Combining LLMChain and ConversationalRelationChain in an agent's routes>
Labels: name: area: agent, name: auto:question, name: auto:improvement

### Issue you'd like to raise.

I've been stuck on a task that I was working on, not knowing how to exactly proceed with it. Where I need to combine different type of chain in the routes of an Agent.

So I have managed to build the following pipeline using an Agent. I receive a query and according to the context of the query it gets routed either to any of the different LLM Chains defined (answering Greetings, Goodbyes, Unrelated Questions) or it gets routed to a RetrievalQA that searches for the answer in a VectorStore when the input query is related to the context in question.

Now what I noticed, and have been trying to fix was that sometimes, despite adding memory to my agent, I can receive a follow-up question that will not be routed to the VectorStore as it would labeled as "Unrelated". Example: Supposedly the first question was : "Am I allowed to work remotely on Fridays?". This is related for exampled and the model will reply with no from the VectorStore. Now, if I follow it up with: "How about Mondays?" the model will identify the input query as unrelated as it is not tackling the subject of "Work". Ideally, I would want it to reformulate the question to: "How about working remotely on Monday?" and to route it accordingly to the VectorStore as it is tackling the subject of "work".

I made my research and found that CoversationalRetrievalChains should be part of my solution, but I do not know how to put it exactly in my architecture. The main issue is that LLM Chains expect a certain type of input ('input':x) while ConversationalRelationChain expect another ('question':x, 'chat_history':y).

I tried using LOTR (Lord of all Retrievers) but apparently it hasn't been working as well. I only have 1 retriever (1 VectorStore) and the rest are simple LLMChains. Yet even when I tried LOTR with CoversationalRetrievalChains in order to combine retrievers I am getting the following error: "NotImplementedError: Saving not supported for this chain type."

In short I want to be able to pass the same input, regardless of the route in my Agent, whether it's a LLM Chain or a CoversationalRetrievalChains. I'm a bit lost and would love some help on the subject.

### Suggestion:

_No response_
I don't have access to the short-term memory using Agent with gpt-3.5-turbo
Labels: name: area: memory, name: area: agent, name: auto:bug

### System Info

langchain==0.0.230
MacOS

### 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
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I do not know how exactly to reproduce this, but I would like to know if someone had the same error using GPT-3.5-turbo with this agent, tool, and prompts:

Agent: LLMSingleActionAgent
Tool and prompt:

```
        template_hello = """You are a chatbot, answer to this
        {input}

        Previous conversation history:
        {history}
        """

        prompt_hello = PromptTemplate(input_variables=["input", "history"], template=template_hello)

        hello_chain = LLMChain(
            llm=ChatOpenAI(model='gpt-3.5-turbo',
            prompt=prompt_hello,
            verbose=True,
            memory=self.memory
        )
```
Memory:
```
from langchain.memory import ConversationTokenBufferMemory
self.memory = ConversationTokenBufferMemory(llm=ChatOpenAI(temperature=0, 
                                                                   max_tokens=500, 
                                                                   model='gpt-3.5-turbo'), 
                                                    memory_key="history",
                                                    max_token_limit=500)
```
When I run the agent with gpt-4 it can access to the memory, if I change the agent model to gtp-3.5-turbo I have this error: 

> I don't have access to the short-term memory

### Expected behavior

Answer based on the memory
Can't connect to Qdrant since 0.0.234
Labels: name: area: vector store, name: auto:bug

### System Info

python 3.9 
langchain 0.0.234
qdrant-client   1.1.7

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

`client = qdrant_client.QdrantClient(self.qdrant_url, port=6333)`
`qdrant = Qdrant(
            client=client, collection_name=self.collection_name, 
            embeddings=embeddings,
        )`

### Expected behavior

I'm getting this error since i upgrade my langchain to 0.0.234 from 0.0.233
<AioRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:6334: Failed to connect to remote host: Connection refused"
	debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:6334: Failed to connect to remote host: Connection refused {grpc_status:14, created_time:"2023-07-20T18:17:20.830536+08:00"}"

I didn't change any code in my project.
Is there any setting change?
it seems that it connect to 6334 port of Qdrant