delayedkarma/langchain-issues huggingface dataset:
Fix typo in agent_structured.ipynb
Labels: name: area: agent, name: auto:documentation

therefor -> therefore

<!-- Thank you for contributing to LangChain!

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,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

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/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Use term keyword according to the official python doc glossary
Labels: name: lgtm, name: area: doc loader, name: auto:documentation

  - **Description:** use term keyword according to the official python doc glossary, see https://docs.python.org/3/glossary.html
  - **Issue:** not applicable
  - **Dependencies:** not applicable
  - **Tag maintainer:** @hwchase17
  - **Twitter handle:** vreyespue
OperationalError: (pyodbc.OperationalError) ('08001', '[08001] 
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

latest version of langchain. python=3.11.4

### Who can help?

@all 

### Information

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

### Related Components

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

### Reproduction

from langchain.agents import *
from langchain.llms import OpenAI
from langchain.sql_database import SQLDatabase

from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain.llms.openai import OpenAI
from langchain.agents import AgentExecutor

from langchain.chat_models import ChatOpenAI 

# from secret_key import openapi_key

openapi_key = "######"

os.environ['OPENAI_API_KEY'] = openapi_key

def chat(question):

    llm = OpenAI(temperature=0)
    tools = load_tools(["llm-math"], llm=llm)

    agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)


    driver = 'ODBC Driver 17 for SQL Server'  
    host = '####'
    database = 'chatgpt'
    user = 'rnd'
    password = '###'
    #db_uri = SQLDatabase.from_uri(f"mssql+pyodbc://{user}:{password}@{host}/{database}?driver={driver}")
    db = SQLDatabase.from_uri(f"mssql+pyodbc://{user}:{password}@{host}/{database}?driver=ODBC+Driver+17+for+SQL+Server")

    llm = ChatOpenAI(model_name="gpt-3.5-turbo",
                    temperature=0, 
                    max_tokens=1000)

    # toolkit = SQLDatabaseToolkit(db=db)
    toolkit = SQLDatabaseToolkit(db=db, llm=llm)
    agent_executor = create_sql_agent(
        llm=llm,
        toolkit=toolkit,
        verbose=True,
        reduce_k_below_max_tokens=True,
    )

    mrkl = initialize_agent(
        tools,
        ChatOpenAI(temperature=0),
        agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True,
        handle_parsing_errors=True,
    )

    return agent_executor.run(question)


### Expected behavior

i need to connect to test server, but i'm getting an error while connecting to it, but is working fine on local server , been getting 
"OperationalError: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].  (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)')
"
Add explanations to GoogleDriveLoader how to avoid errors
Labels: name: lgtm, name: area: doc loader, name: auto:documentation

  - **Description:** add a paragraph to the GoogleDriveLoader doc on how to bypass errors on authentication.

For some reason, specifying credential path via `credentials_path` constructor parameter when creating `GoogleDriveLoader` makes it so that the oAuth screen is never showing up when first using GoogleDriveLoader. Instead, the `RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})` error happens. Setting it via `os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = ...` solves the problem. Also, `token_path` constructor parameter is mandatory, otherwise another error happens when trying to `load()` for the first time.

These errors are tricky and time-consuming to figure out, so I believe it's good to mention them in the docs.
Async support for FAISS
Labels: name: lgtm, name: area: vector store, name: auto:improvement

Following this tutoral about using OpenAI Embeddings with FAISS

https://python.langchain.com/docs/integrations/vectorstores/faiss

```python
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.document_loaders import TextLoader
from langchain.document_loaders import TextLoader

loader = TextLoader("../../../extras/modules/state_of_the_union.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)

embeddings = OpenAIEmbeddings()
```

This works fine

```python
db = FAISS.from_documents(docs, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = db.similarity_search(query)
```

But the async version is not

```python
db = await FAISS.afrom_documents(docs, embeddings)  # NotImplementedError
query = "What did the president say about Ketanji Brown Jackson"

docs = await db.asimilarity_search(query) # this will use await asyncio.get_event_loop().run_in_executor under the hood and will not call OpenAIEmbeddings.aembed_query but call OpenAIEmbeddings.embed_query
```

So this PR add async/await supports for FAISS
In ProgressBarCallback update the progress counter also when runs fin…
Labels: name: auto:bug

…ish with an error

<!-- Thank you for contributing to LangChain!

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,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

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/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Issue: Documents embeddings with many and similar numbers don't return good results
Labels: name: area: embeddings, name: area: vector store, name: auto:bug, name: auto:question

### Issue you'd like to raise.

Hi! I am trying to create a question answering chatbot with PDFs. There is something different in these documents. I have different articles with their number, example: article 1.2.2.1.3, article 1.2.3.4.5, article 2.3.4.1.3, etc.

When I ask for a specific article, it can't find the answer and return "the article x.x.x.x.x is not in the context". I have tried with some embeddings techniques and vector store, but it does not work.

Any ideas?

PD: The PDF documents are around 450 pages

### Suggestion:

_No response_
Add client_name="langchain" to Cohere usage
Labels: name: lgtm, name: area: embeddings, name: auto:improvement

Hey, we're looking to invest more in adding cohere integrations to langchain so would love to get more of an idea for how it's used. Hopefully this pr is acceptable. This week I'm also going to be looking into adding our new [retrieval augmented generation product](https://txt.cohere.com/chat-with-rag/) to langchain.
Issue: LLMChain arun running with Llama7B encounter NotImplementError
Labels: name: auto:bug, name: area: models

### Issue you'd like to raise.

Yeah, so I've been attempting to load Llama2 and utilize Langchain to create a condensed model for my documents. I managed to accomplish the task successfully, as Llama2 generated the results quite effectively. However, when I tried to speed up the process by referencing Langchain's [LLMChain ](https://api.python.langchain.com/en/latest/chains/langchain.chains.llm.LLMChain.html?highlight=llmchain#langchain.chains.llm.LLMChain)and one of its function -- arun, I kept encountering an error that said "Not Implement Error". It didn't matter which function I tried to use, whether it was acall, arun, or apredict, they all failed.

So here are my codes:
``` 
# load LLama from local drive
tokenizer=AutoTokenizer.from_pretrained("/content/drive/MyDrive/CoLab/LLama7b")
model=LlamaForCausalLM.from_pretrained("/content/drive/MyDrive/CoLab/LLama7b",quantization_config=quant_config,device_map="auto",)
    
# define output parameters
prefix_llm=transformers.pipeline(
        model=model, tokenizer=tokenizer,
        return_full_text=True,
        task="text-generation",# temperature=0,
        top_p=0.15, top_k=15,
        max_new_tokens=1060, repetition_penalty=1.2, 
        do_sample=True
)
    
# wrap up with Langchain HuggingfaceLLm class
llm=HuggingFacePipeline(pipeline=prefix_llm, cache=False)
    
# Combine with LLMChain
prompt: PromptTemplate, input_variables="words"
llm_chain = LLMChain(prompt=prompt, llm=llm)
    
# calling arun
input: list[str]
llm_chain.run(input[num]) || llm_chain.run(words=input[num]) # run smoothly
llm_chain.arun(input) || llm_chain.arun(words=input) # Raise error NotImplementError
```

```
error comes from langchain/llms/base.py in _agenerate(self, prompts, stop, run_manager, **kwargs)
        479     ) -> LLMResult:
        480         """Run the LLM on the given prompts."""
    --> 481         raise NotImplementedError()
        482 
        483     def _stream(
    
NotImplementedError: 

# in this last function, "run_manager" should be None, "stop" too.
```
As far as I explored, this process will call 10 frames. Start on
```
langchian/chains/base.py -> def acall() to   
langchian/chains/base.py -> def agenerate()   
then jump to   
langchian/chains/llm.py -> def _acall() to   
langchian/chains/llm.py -> def agenerate()   
in the last it stopped at   
langchian/llms/base.py -> def agenerate() to   
langchian/llms/base.py -> def agenerate_prompt(),    
langchian/llms/base.py -> def agenerate_helper()   
langchian/llms/base.py -> def _agenerate() 
```
I don't know what "thing" I should implement or Langchian didn't implement. the calling code is 100% refer to the [Langchain example](https://python.langchain.com/docs/modules/chains/how_to/async_chain). I suspect maybe it's because Langchain didn't fully support Llama? Since it runs smoothly on OpenAI API.

### Suggestion:

_No response_
Pass kwargs in runnable retry
Labels: name: auto:improvement

<!-- Thank you for contributing to LangChain!

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,
  - **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 your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

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/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Azure Cognitive Search vector DB store performs slow embedding as it does not utilize the batch embedding functionality
Labels: name: area: embeddings, name: area: vector store, name: auto:improvement

### System Info

- Langchain Version: 0.0.306
- Python Version: 3.10.11
- Azure Cognitive Seach (any sku)
- Embedding that has batch functionality


### Who can help?

_No response_

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

### Reproduction

Steps to reproduce:

1. Get a document (or set of documents) that will produce a few hundred chunks
2. Run the sample code provided by Langchain to index those documents into the Azure Search vector store (sample code below)
3. Run steps 1 and 2 on another vector store that supports batch embedding (milvus implementation supports batch embeddings)
4. Analyze the delta between the two vectorization speeds (Azure Search should be noticeably slower)

Sample code:

```python
import openai
import os
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores.azuresearch import AzureSearch

vector_store_address: str = "YOUR_AZURE_SEARCH_ENDPOINT"
vector_store_password: str = "YOUR_AZURE_SEARCH_ADMIN_KEY"

embeddings: OpenAIEmbeddings = OpenAIEmbeddings(deployment=model, chunk_size=1)
index_name: str = "langchain-vector-demo"
vector_store: AzureSearch = AzureSearch(
    azure_search_endpoint=vector_store_address,
    azure_search_key=vector_store_password,
    index_name=index_name,
    embedding_function=embeddings.embed_query,
)

from langchain.document_loaders import TextLoader
from langchain.text_splitter import CharacterTextSplitter

loader = TextLoader("../../../state_of_the_union.txt", encoding="utf-8")

documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)

vector_store.add_documents(documents=docs)
```

### Expected behavior

The expected behavior for the Azure search implementation to also support batch embedding if the implementation of the embedding class supports batch embedding. This should result in significant speed improvements when comparing the single embedding approach vs the batch embedding approach.
Deprecate direct access to globals like `debug` and `verbose`.
Labels: name: auto:refactor

Instead of accessing `langchain.debug`, `langchain.verbose`, or `langchain.llm_cache`, please use the new getter/setter functions in `langchain.globals`:
- `langchain.globals.set_debug()` and `langchain.globals.get_debug()`
- `langchain.globals.set_verbose()` and `langchain.globals.get_verbose()`
- `langchain.globals.set_llm_cache()` and `langchain.globals.get_llm_cache()`

Using the old globals directly will now raise a warning.
Added custom retry decorator support in ChatOpenAI
Labels: name: auto:improvement, name: area: models

Description: 
This PR adds the ability for users to provide a custom retry decorator when creating an instance of the ChatOpenAI class. The custom decorator will be used in the acompletion_with_retry and completion_with_retry methods to handle retries for the API calls. If a custom decorator is not provided, the default retry decorator will be used. This feature provides users the flexibility to handle specific use cases and errors in specific ways.

Issue: https://github.com/langchain-ai/langchain/issues/3109

Dependencies: No new dependencies are required for this change.
Upgrade to v :0.0.306 - AttributeError: Could not find: llms
Labels: name: auto:bug, name: area: models

### System Info

v: 0.0306
python version: Python 3.11.4

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Recently upgraded to version 0.0.306 of langchainversion. (from 0.0.259)

I see to run into the below error
```
2023-10-02T19:42:20.279102248Z   File "/home/appuser/.local/lib/python3.11/site-packages/langchain/__init__.py", line 322, in __getattr__
2023-10-02T19:42:20.279258947Z     raise AttributeError(f"Could not find: {name}")
2023-10-02T19:42:20.279296147Z AttributeError: Could not find: llms
```

I have no idea as to what is causing this and from where the call is being made.  I know that the error is coming from the below file (line 328)
https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/__init__.py

I am not able find any attribute called "llms" that is being set in any of our code base - hence more confused about the Attribute error. 

### Expected behavior

- Perhaps a stack trace that shows the flow of calls
- Documentation that shows the possibilities of the error
add youdotcom retriever skeleton
Labels: name: auto:enhancement

Replace this entire comment with:
  - **Description:** Add you.com retriever to langchain, 
  - **Issue:** N/A,
  - **Dependencies:** N/A,
  - **Tag maintainer:** @hwchase17 ,
  - **Twitter handle:** TBD!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

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/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
Issue: Abstract Class Implementation problem in Retrievers
Labels: name: auto:question, name: area: models

### Issue you'd like to raise.

Hi everyone,

I've encountered an issue while trying to instantiate the ConversationalRetrievalChain in the Langchain library. It seems to be related to the abstract class BaseRetriever and the required method _get_relevant_documents.

Here's my base code:

```
import os
from langchain.vectorstores import FAISS
from langchain.chat_models import ChatOpenAI
from langchain.chains.question_answering import load_qa_chain
from langchain.embeddings.openai import OpenAIEmbeddings
from dotenv import load_dotenv
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationalRetrievalChain

# Load environment variables
load_dotenv("info.env")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

# Initialize the FAISS vector database
embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)
index_filenames = ["index1", "index2"]
dbs = {f"category{i+1}": FAISS.load_local(filename, embeddings) for i, filename in enumerate(index_filenames)}

# Load chat model and question answering chain
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0, openai_api_key=OPENAI_API_KEY)
chain = load_qa_chain(llm, chain_type="map_reduce")

# Initialize conversation memory
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)

# Set the role of the AI
role = "Assistant"

# Write the role of the AI
memory.save_context({"input": f"AI: As an {role}, I can help you with your questions based on the retrievers and my own data."}, {"output": ""})

# Initialize the ConversationalRetrievalChain with memory and custom retrievers
qa = ConversationalRetrievalChain.from_llm(llm, retriever=dbs, memory=memory)

# Pass in chat history using the memory
while True:
    user_input = input("User: ")

    # Add user input to the conversation history
    memory.save_context({"input": f"User: {user_input}"}, {"output": ""})

    # Check if the user wants to exit
    if user_input == "!exit":
        break

    # Run the chain on the user's query
    response = qa.run(user_input)

    # Print the response with a one-line space and role indication
    print("\n" + f"{role}:\n{response}" + "\n")
```

And here's the error message I received:

```
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ConversationalRetrievalChain
retriever
  Can't instantiate abstract class BaseRetriever with abstract method _get_relevant_documents (type=type_error)
```

It appears that the retriever I provided doesn't fully implement the required methods. Could someone provide guidance on how to properly implement a retriever for ConversationalRetrievalChain and help update the code based on that? 

Any help would be greatly appreciated. Thank you!




### Suggestion:

_No response_
Anthropic system message fix
Labels: name: auto:bug, name: area: models

Bedrock anthropic api enforces that Human and Assistant messages must be interleaved (cannot have same type twice in a row). We current treat System Messages as human messages when converting messages -> string prompt. Our validation when using Bedrock/BedrockChat raises an error when this happens. For ChatAnthropic we don't validate this so no error is raised, but perhaps the behavior is still suboptimal.

Would love input from folks more familiar with Anthropic intended usage and Bedrock API.
Add Python 3.12 to CI testing matrix.
Labels: name: auto:improvement

Python 3.12 came out a few hours ago, so in this PR:
- We make linting use 3.12 instead of 3.11, since that's the max version we support. (We also lint on 3.8, the min version we support.)
- We add 3.12 to the test matrices for all other CI runs.

Fixes #11479.