delayedkarma/langchain-issues huggingface dataset:
Input in GraphQAChain Prompt is Malformed When Only 1 Triplet Is Found
Labels: name: auto:bug

### System Info

Mac OS Ventura 13.3.1 (a)
Python 3.10.8
LangChain 0.0.224

### Who can help?

@hwchase17 
@hinthornw 

### Information

- [ ] The official example notebooks/scripts
- [x] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [X] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Reproduction Steps:
1. Run the following
```
    from langchain.llms import OpenAI
    from langchain.indexes import GraphIndexCreator
    from langchain.chains import GraphQAChain
    from langchain.prompts import PromptTemplate

    text = "Apple announced the Vision Pro in 2023."

    index_creator = GraphIndexCreator(llm=OpenAI(openai_api_key='{OPEN_AI_KEY_HERE}', temperature=0))
    graph = index_creator.from_text(text)
    chain = GraphQAChain.from_llm(
        OpenAI(temperature=0, openai_api_key='{OPEN_AI_KEY_HERE}'),
        graph=graph, 
        verbose=True
    )
    chain.run("When did Apple announce the Vision Pro?")
```
2. Observe the "Full Context" output in your terminal and notice that the two triplets are concatenated onto a single line with no spacing in between them.

I believe the issue is in the code [here](https://github.com/hwchase17/langchain/blob/681f2678a357268c435c18f19323ccb50cac079c/langchain/chains/graph_qa/base.py#L80). When only 1 triplet is found in an iteration, `.join` does not add any `\n` characters, resulting in a context string with no separation between triplets.

### Expected behavior

Expected: A multi-line string with each triplet text on its own line (delimited by `"\n"`)

In the above repro steps, I would expect
```
Full Context:
Apple announced Vision Pro
Vision Pro was announced in 2023
```
DOC: Search functionality: `Verified Sources:` fields unreadable
Labels: name: auto:bug, name: auto:documentation

### Issue with current documentation:

If we run a `Search` on the python.langchain.com/docs/ we got the result as several clickable fields. Those fields are the URLs of the found results. But the fields are too short to show the URLs. We cannot see what LangChain doc pages were found. We see just the start of the URL string, like `1. python.langchain.com/docs/module...` All found fields shows the same above text, which is useless.
![image](https://github.com/hwchase17/langchain/assets/2256422/c976d55a-e931-432d-b8fe-0b74dbf986ce)


### Idea or request for content:

Several ideas on how to fix it:
1. make the result fields longer and place them one after another in the list.
2. show the last part of the URL string not the start of the URL string.
Clarifai LangChain improvements and embeddings
Labels: name: lgtm, name: auto:enhancement, name: auto:documentation

This PR improves upon the Clarifai LangChain integration with improved docs, errors, args and the addition of embedding model support in LancChain for Clarifai's embedding models and an overview of the various ways you can integrate with Clarifai added to the docs.

@hwchase17 please take a look.

Twitter: @clarifai
Can't use human_prefix and ai_prefix with agent
Labels: name: auto:bug

### System Info

Langchain 0.0.223
Linux
Python 3.11

### Who can help?

@hwchase17
@agola11


### 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
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

something like this
```python
chat_history = PostgresChatMessageHistory(  # Just a slight mod of the postgres class for sorting the results by date
    connection_string=config('SUPABASE_POSTGRES_CONNECT_STRING'),
    session_id="58964243-23cd-41fe-ad05-ecbfd2a73202",  # str(uuid.uuid4()),
    table_name="chat_history"
)

memory = ConversationBufferMemory( 
    memory_key="chat_history",
    chat_memory=chat_history,
    return_messages=True,
    human_prefix="USER",  # This doesn't work.
    ai_prefix="ASSISTANT",)  # This doesn't work.
    
agent = ChatAgent(
        name="Chat Assistant",
        tools=_tools,
        agent_type=AgentType.OPENAI_MULTI_FUNCTIONS,
        llm=openai
    )
```

If I look at what was prompted and in postgres, it always shows "Human" and "AI"

### Expected behavior

I expect USER and ASSISTANT to be used everywhere after I set it. I see this as especially important when using openai's chat endpoint since their models were trained using these tokens.

I also think it would be better to load the memory/chat history as the openai API provides parameters for (As a list of messages) instead of in the SYSTEM message, but perhaps that's for another issue.
anthropic_version = packaging.version.parse(version("anthropic")) AttributeError: module 'packaging' has no attribute 'version'
Labels: name: auto:bug

### System Info

When I initialise ChatAnthropic(), it got the error:

anthropic_version = packaging.version.parse(version("anthropic"))
AttributeError: module 'packaging' has no attribute 'version'

### Who can help?

@hwchase17 @agola11

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

from langchain.chat_models import ChatOpenAI, ChatAnthropic
llm = ChatAnthropic()

### Expected behavior

As shown above.
MathpixPDFLoader doesn't work. 
Labels: name: auto:bug

### System Info

Getting ''' ValueError: Unable to send PDF to Mathpix'''  while using MathpixPDFLoader. 

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

math_pix_loaded = MathpixPDFLoader(file_path)
load_list_mathpix = math_pix_loaded.load()

### Expected behavior

A list of pages to be returned.
Callback for VertexAI to monitor cost and token consumption
Labels: name: auto:enhancement, name: stale

### Feature request

It would be nice to have a similar function as `get_openai_callback()` for VertexAI. This actually gives the input tokens, output tokens and cost of using OpenAI models:

```python
with get_openai_callback() as cb:
    llm = OpenAI(temperature=0)
    chat = ChatOpenAI(temperature=0)
    emb = OpenAIEmbeddings()

    output_llm = llm("As I was saying,")
    print(output_llm)

    # System message + Human Message
    messages = [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="Translate this sentence from English to French. I love programming.")
    ]
    output_chat = chat(messages)
    print(output_chat)

    print(cb)
```

I would like to have:

```python
with get_vertexai_callback() as cb:
    llm = VertexAI(temperature=0)
    chat = ChatVertexAI(temperature=0)
    emb = VertexAIEmbeddings()

    print(llm("As I was saying,"))

    # System message + Human Message
    messages = [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="Translate this sentence from English to French. I love programming.")
    ]
    print(chat(messages))
```



### Motivation

I would like to monitor my usage of VertexAI models

### Your contribution

I already read quite a bit the openai version of the callback but if anyone has already thought about how to do it with vertex I would be really curious :). If someone else also planned to do it we could merge efforts!
Small updates to run_evaluator after adding dataset.data_type
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!

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
 -->
Add new chain qa_with_references_and_verbatim
Labels: name: auto:enhancement


# Description:
This chain returns the selected documents used for the response. Then, it's possible to extract all meta-data 
for these documents, to generate a markdown link or other stuff.

It's not easy to manage the links of sources. Langchain proposed a qa_with_source, but this chain returns only a
list of URL. It's not possible to extract other informations about the metadata, like the filename or others stuff.

I propose a solution to this problem: return the Documents, and let development do what it wants with it.

This pull-request proposes a new implementation of the original chain `qa_with_source`.
Now, the implementation `qa_with_reference` returns the list of documents used for the response.
Then, it's possible to use all meta-data for these documents, to generate a Markdown link (with filename/title and URL) or what you want.

To do that, I inject a UUID in the meta-data, and ask to return a list of UUID in the response. Then, it's easy to find the corresponding document.

In another [branch](https://github.com/pprados/langchain/tree/pprados/qa_with_references_rewrite_qa_with_sources), 
I have reimplemented the origin `qa_with_source` to extend the `qa_with_reference`.

# Tag maintainer:
- @baskaryan

# Dependencies:
- no

# Twitter handle: 
- @pprados
Allow filter to be passed in ElasticKnnSearch knn_search and knn_hybrid_search
Labels: name: auto:improvement

You can pass filter to an kNN in elasticsearch.
This is currently implemented in the langchain wrapper in the exact KNN search.
But is not yet implemented in the approximate KNN search.

Add filter param to [_default_knn_query](https://github.com/jeffvestal/langchain/blob/10f34bf62e2d53f0b1a7b15ba21c2328b64862cd/langchain/vectorstores/elastic_vector_search.py#L398), [knn_search](https://github.com/jeffvestal/langchain/blob/10f34bf62e2d53f0b1a7b15ba21c2328b64862cd/langchain/vectorstores/elastic_vector_search.py#L432), [knn_hybrid_search](https://github.com/jeffvestal/langchain/blob/10f34bf62e2d53f0b1a7b15ba21c2328b64862cd/langchain/vectorstores/elastic_vector_search.py#L488).

cc: @jeffvestal, @derickson







### Suggestion:

_No response_
Fix `make docs_build` and related scripts
Labels: name: auto:bug, name: auto:improvement, name: auto:documentation

**Description: a description of the change**

Fixed `make docs_build` and related scripts which caused errors. There are several changes.

First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`.

It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in.

`docs/api_reference/api_reference.rst` is removed,  because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore.

Finally, the description of CONTRIBUTING.md was modified.

**Issue: the issue # it fixes (if applicable)**

https://github.com/hwchase17/langchain/issues/6413

**Dependencies: any dependencies required for this change**

`nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review.

**Tag maintainer**
- General / Misc / if you don't know who to tag: @baskaryan

If this PR needs any additional changes, I'll be happy to make them!
fix pydantic parser: JSONDecodeError
Labels: name: needs test, name: auto:bug

## Problem

The  **double quatations (")** which cannot use  `parser.parse()` correctly.
For example, completion from chain response as following:

```python
text = """
Answer: {
  "product_name": "Control4® T3 Series 7\" Tabletop Touch Screen",
  "manufactured_date": "2015-10-09",
  "size_inch": "7.0\" × 5.1\" × 0.75\"",
  "resolution": "1280 × 800",
  "contrast": "",
  "operation_temperature": "32 ~ 104˚F (0˚ ~ 40˚C)",
  "power_supply": "PoE (IEEE802.3af) 100VAC ~ 240VAC, 50-60 Hz International power supply adapters included",
  "sunlight_readable": false,
  "antiglare": false,
  "low_power_consumption": false,
  "high_brightness": false,
  "wide_temperature": false,
  "fast_response": true,
  "screen_features": ["Capacitive touch", "Camera: 720p", "HD camera", "Speakers and microphone", "Video intercom integration", "Audio intercom integration"]
}
"""

# Just take the parse function :)
try:
    # Greedy search for 1st json candidate.
    match = re.search(
        r"\{.*\}", text.strip(), re.MULTILINE | re.IGNORECASE | re.DOTALL
    )
    json_str = ""
    if match:
        json_str = match.group()
    json_object = json.loads(json_str, strict=False)

except Exception as e:
    print(e)
```

##  Wrong Result

```
Expecting ',' delimiter: line 2 column 43 (char 44)
```


## Solution

Let's add a `remove_illegal_quatations` function which will:

1. **Remove the illegal quatations** which not display in `first, second, third, last time`
2. Remeber there will `List` value, we should'nt remove here. ex: `["Capacitive touch", "Camera: 720p", ..."]`
3. Remeber there will `true/false` which will not have `""`. ex: ` "sunlight_readable": false`
[FEATURE] SOLR Based Vector Store
Labels: name: auto:enhancement

### Feature request

This adds support for Apache SOLRs vector search capabilities
(https://solr.apache.org/guide/solr/latest/query-guide/dense-vector-search.html)

### Motivation

As SOLR is a commonly used search index and now offers this feature, it is important to allow SOLR users to be able to integrate seamlessly with LangChain (and the associated benefits).

### Your contribution

I can try submitting a PR
'Qdrant.from_documents' Memory overflow
Labels: name: auto:bug

### Issue you'd like to raise.

```
def handle_embeddings(payload):
     loader = UnstructuredPDFLoader(payload["filepath"])
     documents = loader.load()

    text_splitter = SpacyTextSplitter(pipeline=payload["language"], chunk_size=1536, chunk_overlap=0)
    docs = text_splitter.split_documents(documents)
    
    embeddings = OpenAIEmbeddings(**payload)
    qdrant = Qdrant.from_documents(
        docs, embeddings,
        path=path,
        collection_name=collection_name,
    )
    
import dramatiq
from dramatiq.brokers.redis import RedisBroker
from tasks import handle_embeddings

redis_broker = RedisBroker(url='redis://redis.helloreader.docker/10')
dramatiq.set_broker(redis_broker)

@dramatiq.actor(max_retries = 0)
def handle_embeddings_task(payload):
    result = handle_embeddings(payload)
    return result
```

Due to the time-consuming nature of embeddings and storing them in a vector database, I opted for asynchronous queue tasks to handle them. However, I noticed that when processing documents of size 30 MB, the memory usage of the queue task kept increasing until it eventually crashed due to overflow. At this point, I investigated and found that the memory overflow occurred even before the embeddings interface was called, indicating that the issue was with the `Qdrant.from_documents` method. I have been searching for the root cause for a while but haven't found it yet.

### Suggestion:

I hope someone who is familiar with the `Qdrant.from_documents` method or has knowledge of other possible causes can help me resolve this issue. 
The document size of approximately 30 MB corresponds to approximately 560,000 tokens.
During the process, I tried using Dramatiq, Celery, and RQ, and encountered the same issue with all of them. Therefore, we can exclude the possibility of the issue being specific to these queue tools.
Added number_of_head_rows to pandas agent parameters
Labels: name: auto:improvement

Description: Added number_of_head_rows as a parameter to pandas agent. number_of_head_rows allows the user to select the number of rows to pass with the prompt when include_df_in_prompt is True. This gives the ability to control the token length and can be helpful in dealing with large dataframe.

Tag maintainer: @hinthornw @baskaryan

Twitter handle: @activenikhilg
Langchain Tools and Agents
Labels: name: auto:question, name: auto:improvement

### Issue you'd like to raise.

I am using Tools and Agents to query on different vectorstores. But when I am asking question which is not from the vectorstore.It responds i dont know. So is there any approach i can try where if the answer is not from the vectorstore i can carry out the conversation like chatgpt. If Yes? Can you Please let me know how we can integrate this 

### Suggestion:

_No response_
langchain + gpt4all 执行异常，总提示参数问题
Labels: name: auto:bug

### System Info

LangChain v0.0.225, Windows10, 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
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

一个来自langchain的事例代码如下：
from langchain import PromptTemplate, LLMChain
from langchain.llms import GPT4All
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

local_path = (
    "ggml-gpt4all-j-v1.3-groovy.bin"  # replace with your desired local file path
)

callbacks = [StreamingStdOutCallbackHandler()]
llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)

llm_chain = LLMChain(prompt=prompt, llm=llm)

question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"

llm_chain.run(question)

执行的结果如下：
TypeError: GPT4All.generate() got an unexpected keyword argument 'n_ctx'

当我加上参数 max_tokens=200 时：llm = GPT4All(model=local_path, max_tokens=200, callbacks=callbacks, verbose=True)
出现如下结果：
ValidationError: 1 validation error for GPT4All
max_tokens
  extra fields not permitted (type=value_error.extra)

### Expected behavior

callbacks = [StreamingStdOutCallbackHandler()]
llm = GPT4All(model=local_path, max_tokens=200, callbacks=callbacks, verbose=True)
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"

llm_chain.run(question)

#可以输出正确结果
refactor BedrockEmbeddings class
Labels: name: lgtm, name: auto:refactor

#### Description
refactor BedrockEmbeddings class to clean code as below:

1. inline content type and accept
2. rewrite input_body as a dictionary literal
3. no need to declare embeddings variable, so remove it

#### Tag maintainer
  - General / Misc / if you don't know who to tag: @baskaryan
Remove whitespace in filename
Labels: name: lgtm, name: auto:nit

Rename `langchain/tools/office365/__init__ .py` to `langchain/tools/office365/__init__.py`

@baskaryan

<!-- 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!

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 inconsistent behavior of `CharacterTextSplitter` when changing `keep_separator`
Labels: name: auto:bug


- Description:
  - When `keep_separator` is `True` the `_split_text_with_regex()` method in `text_splitter` uses regex to split, but when `keep_separator` is `False` it uses `str.split()`. This causes problems when the separator is a special regex character like `.` or `*`. This PR fixes that by using `re.split()` in both cases.
- Issue: #7262 
- Tag maintainer: @baskaryan