delayedkarma/langchain-issues huggingface dataset:
Issue with LangChain Misclassifying gpt-3.5-turbo-instruct as Chat Model
Labels: name: auto:bug, name: area: models

### Discussed in https://github.com/langchain-ai/langchain/discussions/15598

<div type='discussions-op-text'>

<sup>Originally posted by **MahdiJafari1** January  5, 2024</sup>
OpenAI deprecated its `text-davinci-003` completion model. I've updated the model to `gpt-3.5-turbo-instruct`. I am encountering an issue with the LangChain where it incorrectly classifies the `gpt-3.5-turbo-instruct` model as a chat model. This is causing initialization problems in my code.

**Environment:**
```
python = "^3.10"
langchain = "^0.0.130"
```
OS: Ubuntu


**Expected Behavior:**

The expected behavior is that the gpt-3.5-turbo-instruct model should be recognized as a completion model by LangChain and initialized appropriately without warnings or errors.


**Actual Behavior:**

When attempting to initialize the gpt-3.5-turbo-instruct model, I receive warnings suggesting that this model is being misclassified as a chat model. The specific warnings are:


```shell
/home/mahdi/.cache/pypoetry/virtualenvs/backend-bRqVKcMN-py3.11/lib/python3.11/site-packages/langchain/llms/openai.py:169: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`
/home/mahdi/.cache/pypoetry/virtualenvs/backend-bRqVKcMN-py3.11/lib/python3.11/site-packages/langchain/llms/openai.py:608: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`

```


**My simplified code:**


```python
from langchain import OpenAI


llm = OpenAI({
            "model_name": "gpt-3.5-turbo-instruct",
            "temperature": 0.0,
            "top_p": 1,
            "openai_api_key": "API_KEY",
        })
        
print(llm)

```

Output: 

```shell
OpenAIChat[Params: {'model_name': 'gpt-3.5-turbo-instruct', 'temperature': 0.0, 'top_p': 1}

```</div>
Issue with ConversationalRetrievalChain in LangChain - ValueError: Missing Input Keys
Labels: name: area: memory, name: auto:bug

### System Info

langchain 0.0.354, Windows 10,Python 3.11.5

### Who can help?

@hwchase17 @eyurtsev

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

### Reproduction

input_data = {
    "chat_history": chat_history,
    "question": question
}

chain = ConversationalRetrievalChain.from_llm(
    llm=ChatOpenAI(model=current_model),
    retriever=retriever,
    memory=memory,
    return_source_documents=True,
    get_chat_history=lambda h: h
)

result = chain(input_data)


### Expected behavior

I am writing to seek assistance with an issue I've encountered while working with the ConversationalRetrievalChain in LangChain. I have been developing a Discord bot using LangChain and have run into a consistent error that I'm struggling to resolve.

I am trying to use ConversationalRetrievalChain for a chatbot application. However, I keep encountering a ValueError related to input keys. The error message states: "ValueError: Missing some input keys: {'chat_history', 'question'}". This error occurs when I attempt to pass a dictionary containing 'chat_history' and 'question' as separate keys to the ConversationalRetrievalChain.

I have tried various approaches to format the input data correctly, including combining 'chat_history' and 'question' into a single string and passing them as separate keys. Despite these efforts, the error persists. I have also searched for solutions on platforms like Stack Overflow and GitHub but haven't found a resolution that addresses this specific issue.

Could you please provide guidance on how to correctly structure the input data for ConversationalRetrievalChain, or suggest any alternative approaches to resolve this issue? Any insights or recommendations would be greatly appreciated.

Thank you for your time and assistance. I look forward to your response.
Fix chain docs redirects
Labels: name: auto:documentation, name: size:XS

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes if applicable,
  - **Dependencies:** any dependencies required for this change,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Populate streamed_output for all runs handled by atransform_stream_with_config
Labels: name: auto:improvement, name: area: models, name: size:L

This means that users of astream_log() now get streamed output of virtually all requested runs, whereas before the only streamed output would be for the root run and raw llm runs

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes if applicable,
  - **Dependencies:** any dependencies required for this change,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
DOC: Lack of Documentation Versioning on Langchain Website
Labels: name: auto:documentation

### Issue with current documentation:

There is no way to view the old documentation on [the official site](https://python.langchain.com/). This makes it extremely difficult to develop. It seems as though every week there is another feature that is deleted, thus another page being deleted. 

How is this acceptable? It is becoming almost unusable in the Enterprise world due to the constant changes and lack of documentation. 



### Idea or request for content:

Implement a selector that lets you choose which langchain version you're on so that you can view the documentation for that specific version.
Allow system message add to history
Labels: name: auto:improvement, name: size:S

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes if applicable,
  - **Dependencies:** any dependencies required for this change,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
## Description
This is a follow-up PR to https://github.com/langchain-ai/langchain/pull/14967 that added support for `AIMessage` and `HumanMessage` to `BaseChatMessageHistory.add_user_message` and `BaseChatMessageHistory.add_ai_message`. This extends that to include a `BaseChatMessageHistory.add_system_message` method with the same functionality. It also clarifies the docstrings of the other two methods.

## Dependencies
None

## Tag Maintainers
@hinthornw 
@eyurtsev 
@butlfrazp

## Note
I ran `make lint` and `make format` but `make test` results in `make: *** No rule to make target 'test'.  Stop.`.
community: Fixing a performance issue with AzureSearch to perform batch embedding
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: size:M


  - **Description:** Azure Cognitive Search vector DB store performs slow embedding as it does not utilize the batch embedding functionality. This PR provide a fix to improve the performance of Azure Search class when adding documents to the vector search, 
  - **Issue:** #11313 ,
  - **Dependencies:** any dependencies required for this change,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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. It lives in `docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
docs top menu 
Labels: name: auto:documentation, name: size:S

![image (2)](https://github.com/langchain-ai/langchain/assets/2256422/7d39063c-a477-4241-a8a0-797cfd790f5e)
![image (1)](https://github.com/langchain-ai/langchain/assets/2256422/1d5246f1-402f-4fa9-9f43-2510f8f49fd2)
Enhance Flexibility in VectorStoreRetriever by Allowing Dynamic search args in invoke Method
Labels: name: area: vector store, name: auto:improvement

### Feature request

It would be really great to enhance the VectorStoreRetriever class, by allowing additional (optional) search kwargs to be passed directly to the invoke method. Right now the input type of the invoke method is str, it would be interesting to be able to receive a custom object with "query" and "filters". 
Ideally one would be able to do:
```python
chain = (
    vector_store.as_retriever() 
    | parse_documents_to_str
    | llm
) 
chain.invoke({'query': some_question, 'filter': filter_expression})
```

### Motivation

This change would enable dynamic querying capabilities, such as metadata filtering, which are not currently possible due to the requirement of defining search_kwargs at the constructor level or altering them in the instantiated object. I know I can work this out using a custom retriever class and override some methods, but metadata filtering is a very powerful option to enhance search, and it would be really helpful for developers to have this built in as a default behaviour. 

### Your contribution

I can submit a PR if someone confirms this makes sense
community: Add LiteLLM Router Integration
Labels: name: lgtm, name: auto:enhancement, name: area: models, name: size:XL

community:

  - **Description:**
    - Add new ChatLiteLLMRouter class that allows a client to use a LiteLLM Router as a LangChain chat model.
    - Note: The existing ChatLiteLLM integration did not cover the LiteLLM Router class.
    - Add tests and Jupyter notebook.
  - **Issue:** None
  - **Dependencies:** Relies on existing ChatLiteLLM integration
  - **Twitter handle:** @bburgin_0
RAG chain response often includes "\n AI:" in front of actual response
Labels: name: auto:bug

### System Info

google-cloud-aiplatform==1.35.0,
langchain-0.0.354

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

```python
template = """
        **Role:**
        You are a helpful assistant.

        **Context:**
        You have to only use a reference stored document to generate a response.
        CONTEXT: {context}

        **Task:**
        1. task 1
            - some important requirements for task 1
        2. task 2
            - some important requirements for task 2  
        3. task 3 
            - some important requirements for task 3
            
        Question: {question}
        Helpful Answer:

        **Resource:** [reference source name]
    """
    
    qa_prompt = ChatPromptTemplate.from_messages(
    [
        ("system", template),
        MessagesPlaceholder(variable_name="chat_history"),
        ("user", "{question}"),
    ]
    )
    
    rag_chain = (
        RunnablePassthrough.assign(
            context=contextualized_question | retriever | format_docs
        )
        | qa_prompt
        | llm
    )

    response = rag_chain.invoke({"question": message, "chat_history": memory.get_history()})
    
    print(response)
```

### Expected behavior

I expect to get the response which is composed of only a proper response sentence. Sometimes, it does well as I expected.
But frequently, it returns "\n AI:" in front of the actual response which is not suppose to do so.

For example,
```
"\n AI: The reference document says blah blah.", 
```
Chroma as_retriever function with kwargs leads to unexpected keyword argument 
Labels: name: area: vector store, name: auto:bug, name: integration: chroma

### System Info

langchain = 0.0.354
This problem appears since commit 62d32bd 


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

Comit 62d32bd allowed to pass kwarg to ChromaDb. This is really nice but I my case it leads to an error ...
I don't know if it is relevant or a workaround exists so I raise the issue

Here is how to reproduce

``` python
from langchain.vectorstores import Chroma

# load a simple Chroma DB
vectordb = Chroma(persist_directory=my_chroma_db_directory,
              embedding_function=my_embedding)

# init a retriever function
retriever = vectordb.as_retriever(search_kwargs={"k": retriever_output_number, "fetch_k": retriever_documents_used, "lambda_mult": retriever_diversity})

# call the retriever in a qa
qa_chain = RetrievalQA.from_chain_type(llm=llm,
                                          chain_type="stuff",
                                          retriever=retriever,
                                          return_source_documents=False,
                                          verbose=True)

# ask something
answer = qa_chain.run("find something in doc ...")
```



### Expected behavior

kwargs are needed by the `as_retriever` function, in the example above the argument `fetch_k` is mandatory

https://github.com/langchain-ai/langchain/blob/fd5fbb507dd3b1c189aa1e4b601b8669217b0f78/libs/core/langchain_core/vectorstores.py#L553

Since commit 62d32bd kwargs are passed up to Chroma `function similarity_search_with_score` which calls `__query_collection` leading to the error

https://github.com/langchain-ai/langchain/blob/fd5fbb507dd3b1c189aa1e4b601b8669217b0f78/libs/community/langchain_community/vectorstores/chroma.py#L408

TypeError: Collection.query() got an unexpected keyword argument 'fetch_k'

Is there a way to avoid that ?
Issue: ipykernel kernel crashes when using llama-2-13b model
Labels: name: auto:bug, name: area: models

Hi,
I am using langchain and llama-cpp-python to do some QA on a text file. When using the llama-2-13b-chat quantized model from [HuggingFace](https://huggingface.co/TheBloke/Llama-2-13B-chat-GGUF/blob/main/llama-2-13b-chat.Q5_K_M.gguf). I am able to create a RetrievalQA chain passing the vectorstore and prompt, but when I use the chain.run(query), it crashes the anaconda kernel. 
I tried using the [7b variant](https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/blob/main/llama-2-7b-chat.Q5_K_M.gguf) and this works fine without any issue.
### Package Version
langchain==0.0.350
langchain-community==0.0.3
langchain-core==0.1.1
langsmith==0.0.70
llama_cpp_python==0.2.19

### Code Snippet
from langchain.text_splitter import RecursiveCharacterTextSplitter,SentenceTransformersTokenTextSplitter
from langchain.embeddings import HuggingFaceEmbeddings, OpenAIEmbeddings, SentenceTransformerEmbeddings
from langchain.vectorstores import FAISS
from langchain.llms import LlamaCpp
from langchain import PromptTemplate
from langchain.chains import RetrievalQA

model_path="Model Path/llama-2-13b-chat.Q5_K_M.gguf"
llm = LlamaCpp(
    model_path = model_path,
    max_tokens=700,f16_kv=True,model_kwargs={'context_length':4000,'temparature':0.3}
    )

embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2', model_kwargs={'device':'cpu'})
vectorstore = FAISS.load_local(f'Text File', embeddings=embeddings)

template="""
    Answer the question using only the context provided to you. 
    Context: {context}
    Question:{question}
    """
qa_prompt=PromptTemplate(template=template, input_variables=["context","question"])
chain = RetrievalQA.from_chain_type(llm=llm,
                                    chain_type='stuff',
                                    retriever=vectorstore.as_retriever(),
                                    return_source_documents=False,
                                    chain_type_kwargs={'prompt': qa_prompt})
chain.run("Who are the people in the conversation?")


### Suggestion:

_No response_
community: Chat Huggingface and HuggingFace TGI llms
Labels: name: auto:improvement, name: area: models, name: size:M

community: 


  - **Description:** 
   - [x] The method `_resolve_model_id()` is only called when `model_id` is not explicitly defined, in order to avoid calling `list_inference_endpoints` when connecting `HuggingFaceTextGenInference` to a self-hosted TGI server.
  - [x]  For  `HuggingFaceTextGenInference` clients that send request to a HuggingFace-deployed Inference Endpoints, a Bearer Token is needed for authorization.
  - [x] More integrations tests is added for `HuggingFaceTextGenInference` 
  - **Issue:** Referring to this current [issue](https://github.com/huggingface/text-generation-inference/issues/747) in HuggingFace TGI repo
  - **Dependencies:** No dependencies for this change
  - **Twitter handle:**  @MinhN2804
metadata is not properly processed when the field does not exists
Labels: name: area: vector store, name: auto:bug

### System Info

In the langchain_community/vectorstores/azuresearch.py on line 656  the filed name is used explicitly, which leads to an error if the index does not have the mentioned filed. The suggestion is to replace 
`json.loads(result["metadata").get("key"), ""),`
with `json.loads(result[FIELDS_METADATA]).get("key"), "") if FIELDS_METADATA in result else "",`

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

1. Configure Azure Search index without metadata field. 
2. execute the following code `docs = vector_store.semantic_hybrid_search_with_score_and_rerank(
    query=query, k=3
)`

### Expected behavior

successful execution of the above mentioned code
Cannot import name 'URL' from 'sqlalchemy' 
Labels: name: area: vector store, name: auto:bug

### Discussed in https://github.com/langchain-ai/langchain/discussions/5701

<div type='discussions-op-text'>

<sup>Originally posted by **rdhillbb** June  5, 2023</sup>

Newbie here.
I found an issue while importing 'VectorstoreIndexCreator'

ImportError: cannot import name 'URL' from 'sqlalchemy' (/Users/tst/anaconda3/lib/python3.10/site-packages/sqlalchemy/__init__.py)

Error Log:
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[88], line 2
      1 from langchain.docstore.document import Document
----> 2 from langchain.indexes import VectorstoreIndexCreator
      3 from langchain_community.utilities import ApifyWrapper
      5 apify = ApifyWrapper()

File ~/anaconda3/lib/python3.10/site-packages/langchain/indexes/__init__.py:17
      1 """Code to support various indexing workflows.
      2 
      3 Provides code to:
   (...)
     14 documents that were derived from parent documents by chunking.)
     15 """
     16 from langchain.indexes._api import IndexingResult, aindex, index
---> 17 from langchain.indexes._sql_record_manager import SQLRecordManager
     18 from langchain.indexes.graph import GraphIndexCreator
     19 from langchain.indexes.vectorstore import VectorstoreIndexCreator

File ~/anaconda3/lib/python3.10/site-packages/langchain/indexes/_sql_record_manager.py:21
     18 import uuid
     19 from typing import Any, AsyncGenerator, Dict, Generator, List, Optional, Sequence, Union
---> 21 from sqlalchemy import (
     22     URL,
     23     Column,
     24     Engine,
     25     Float,
     26     Index,
     27     String,
     28     UniqueConstraint,
     29     and_,
     30     create_engine,
     31     delete,
     32     select,
     33     text,
     34 )
     35 from sqlalchemy.ext.asyncio import (
     36     AsyncEngine,
     37     AsyncSession,
     38     async_sessionmaker,
     39     create_async_engine,
     40 )
     41 from sqlalchemy.ext.declarative import declarative_base

Thank You
 Vj