delayedkarma/langchain-issues huggingface dataset:
'google.generativeai' has no attribute 'GenerativeModel'
Labels: name: auto:bug, name: area: models

### System Info

Anaconda  23.7.2
Windows 11
Python 3.11.5


### Who can help?

@hwchase17 @agola11 


### 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
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Method 1
```
def generate_lecture(topic:str, context:str):
    
  template ="""
  As an accomplished university professor and expert in {topic}, your task is to develop an elaborate, exhaustive, and highly detailed lecture on the subject. 
  Remember to generate content ensuring both novice learners and advanced students can benefit from your expertise.
  while leveraging the provided context
  
  Context: {context} """

  
  prompt = ChatPromptTemplate.from_template(template)

  model = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=palm_api_key)

 
  response = model.invoke(template)
  return response.content
```

Method 2
```

def generate_lecture(topic:str, context:str):
    
  template ="""
  As an accomplished university professor and expert in {topic}, your task is to develop an elaborate, exhaustive, and highly detailed lecture on the subject. 
  Remember to generate content ensuring both novice learners and advanced students can benefit from your expertise.
  while leveraging the provided context
  
  Context: {context} """

  
  prompt = ChatPromptTemplate.from_template(template)

  model = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=palm_api_key)
  chain = prompt| model | StrOutputParser()
  
  response = chain.invoke({"topic":topic, "context":context})

  return response.
```

Result we receive on execttion of method 1 and method 2 is 
```

  File "C:\Users\ibokk\RobotForge\mvp\service\llm.py", line 80, in generate_lecture
    model = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=palm_api_key)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ibokk\anaconda3\envs\robotforge\Lib\site-packages\langchain_core\load\serializable.py", line 97, in __init__
    super().__init__(**kwargs)
  File "pydantic\main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic\main.py", line 1102, in pydantic.main.validate_model
  File "C:\Users\ibokk\anaconda3\envs\robotforge\Lib\site-packages\langchain_google_genai\chat_models.py", line 502, in validate_environment
    values["_generative_model"] = genai.GenerativeModel(model_name=model)
                                  ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel
```

### Expected behavior

A poor result will be  random text generated which is not relevant to the prompt provided. An excellent result will be text generated relevant to the template provided.
Make `doctran` synchronous
Labels: name: area: doc loader, name: auto:improvement, name: auto:documentation, name: size:L

### Description

I found that the methods in [the doctran library](https://github.com/psychic-api/doctran) have been restructured into [synchronized versions](https://github.com/psychic-api/doctran/commit/14944a59f7513b51e629a850e0de5ae276eabed9), 

And [the example ipynb](https://github.com/psychic-api/doctran/blob/main/examples.ipynb) also shows that the code is synchronized, but the README has not been updated yet.

so we need to modify the code and update the documentation.

### Issue

https://github.com/langchain-ai/langchain/issues/14645
Issue: what are all dependencies need to install for fetching confluence attachments
Labels: name: area: doc loader, name: auto:question

### Issue you'd like to raise.


below is my dependencies installed till now 
django==4.0
django-rest-framework
langchain==0.0.349
pdf2image
chromadb
unstructured
openai
pypdf
tiktoken
django-cors-headers
django-environ
pytesseract==0.3.10
beautifulsoup4==4.12.2
atlassian-python-api==3.38.0
tiktoken==0.4.0
lxml==4.9.2
what else dependencies need to install for fetching confluence attachments.

### Suggestion:

_No response_
Splitting the document based on headers using Recursive Character Text Splitter
Labels: name: area: doc loader, name: auto:question

Hi @dossubot.
I have a document where it contains 3 different titles of a single document, i want to create chunk size based on every header, so below is my existing code, pls modify that. and send me accordingly.
def load_docs_only(directory_path):
    docs, _, _, _ = load_documents(directory_path)
    return docs

def text_splitter_by_char():
    splitter = RecursiveCharacterTextSplitter(
        chunk_size=1000,
        chunk_overlap=100,
        length_function = len,
    return splitter

# Load the content
docs = load_docs_only(cfg.directory_path)

# Split the content
splitter = text_splitter_by_char()
chunks = splitter.split_documents(docs)
chunks
Issue: Rephrased question in included in the on_llm_new_token method while streaming the response from the LLM
Labels: name: auto:bug, name: area: models

### Issue you'd like to raise.

Hi, I am  trying to stream the response from the llm  back to the client by using a callback with a custom StreamHandler, but the on_llm_new_token also includes the output from the rephrase_question step. while the final response does not include the rephrased answer. I don't want the rephrased question to be present in the response  that is streaming.
the StreamHandler class is given below

`class StreamHandler(BaseCallbackHandler):
    def __init__(self):
        self.text = ""

    def on_llm_new_token(self, token: str, **kwargs):
        old_text = self.text
        self.text += token

        # Calculate the new content since the last emission
        new_content = self.text[len(old_text) :]
        socketio.emit("update_response", {"response": new_content})`

The qa-chain is defined as below:

qa_chain = ConversationalRetrievalChain.from_llm(
        llm=chat,
        retriever=MyVectorStoreRetriever(
            vectorstore=vectordb,
            search_type="similarity_score_threshold",
            search_kwargs={"score_threshold": SIMILARITY_THRESHOLD, "k": 1},
        ),
        return_source_documents=True,
        rephrase_question=False)
 response = qa_chain(
        {
            "question": user_input,
            "chat_history":chat_history,
           
        },callbacks=[stream_handler] )

### Suggestion:

_No response_
Issue: How to set the Chain with valid/empty input
Labels: name: auto:question, name: area: models

### Issue you'd like to raise.

my code:

only_recall_inputs = RunnableParallel({
            "question": itemgetter('question'),
            "history": ????????,
            "docs": itemgetter('question') | retriever,
        })

just a simple chain
I want the  "history" part to be [] or ''
how to do this?


### Suggestion:

_No response_
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Labels: name: area: vector store, name: auto:bug, name: integration: elasticsearch

### System Info

python  3.10
langchain version：0.0.350


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

when use  elasticsearchStore   add_doccuments     The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

langchain  0.0.317  is ok

upgrade  langchain  0.0.350   exist  error 

### Expected behavior

fix it
Gemini not support SystemMessage and raise an error
Labels: name: auto:bug, name: area: models

### System Info

LangChain: 0.0.348
langchain-google-genai: 0.0.3
python: 3.11
os: macOS11.6


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

### Reproduction

langchain_google_genai.chat_models.ChatGoogleGenerativeAIError: Message of 'system' type not supported by Gemini. Please only provide it with Human or AI (user/assistant) messages.

### Expected behavior

no error
TypeError: get_model() got an unexpected keyword argument 'ocr_languages'
Labels: name: area: doc loader, name: auto:bug, name: area: models

### System Info


**Environment Details**
**Langchain version 0.0.336
Python 3.9.2rc1**

**Error encountered while executing the sample code mentioned in the "Semi_structured_multi_modal_RAG_LLaMA2.ipynb" notebook from the cookbook.**

File [c:\Users\PLNAYAK\Documents\Local_LLM_Inference\llms\lib\site-packages\unstructured\file_utils\filetype.py:551](file:///C:/Users/PLNAYAK/Documents/Local_LLM_Inference/llms/lib/site-packages/unstructured/file_utils/filetype.py:551), in add_metadata_with_filetype.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    [549](file:///C:/Users/PLNAYAK/Documents/Local_LLM_Inference/llms/lib/site-packages/unstructured/file_utils/filetype.py:549) @functools.wraps(func)
...
--> [482](file:///C:/Users/PLNAYAK/Documents/Local_LLM_Inference/llms/lib/site-packages/unstructured_inference/inference/layout.py:482)     model = get_model(model_name, **kwargs)
    [483](file:///C:/Users/PLNAYAK/Documents/Local_LLM_Inference/llms/lib/site-packages/unstructured_inference/inference/layout.py:483)     if isinstance(model, UnstructuredObjectDetectionModel):
    [484](file:///C:/Users/PLNAYAK/Documents/Local_LLM_Inference/llms/lib/site-packages/unstructured_inference/inference/layout.py:484)         detection_model = model

**TypeError: get_model() got an unexpected keyword argument 'ocr_languages'**

I would appreciate any assistance in resolving this issue. Thank you.

### Who can help?

@eyurtsev

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

### Reproduction

from typing import Any

from pydantic import BaseModel
from unstructured.partition.pdf import partition_pdf

# Get elements
raw_pdf_elements = partition_pdf(
    filename=path + "Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf",# Unstructured first finds embedded image blocks
    infer_table_structure=True,
    # Post processing to aggregate text once we have the title
    max_characters=4000,
    new_after_n_chars=3800,
    combine_text_under_n_chars=2000,
    image_output_dir_path=path,
    languages=['eng'],
)

### Expected behavior

The notebook should run without any issues and produce the expected output as documented in the cookbook
PYTHON ISSUE : Fallback does not catch exception in custom function using LCEL
Labels: name: area: vector store, name: auto:bug

### System Info

### **SYSTEM INFO**
LangChain version : 0.0.345
Python version : 3.9.6

### **ISSUE**
I create this custom function which will throw an error if the vectorestore cannot retrieve any relevant document

```
def check_threshold(inp, vecs):
    query = inp['question']
    threshold = inp['threshold']
    
    d = [doc for doc,score in vecs.similarity_search_with_relevance_scores(query) if score >= threshold]
    if len(d) < 1:
        raise Exception("Not found!")
    return "\n\n".join([x.page_content for x in d])
```

I want to use another chain if the main chain fails by using `with_fallbacks` function in the main chain

```
main_chain = ({
        "context" : lambda x: check_threshold(x, vecs), "question" : lambda x: x['question']
    } | prompt | llm | StrOutputParser()
).with_fallbacks([fallback_chain])
```

In the above code, the fallback_chain never gets triggered.

**PS : The above code is just an example, the original code uses more complicated calculations with many exceptions raise in several custom functions. Therefore, It is not feasible to use built-in Python try-except error handler**


### 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
- [X] Chains
- [X] Callbacks/Tracing
- [ ] Async

### Reproduction

```
def check_threshold(inp, vecs):
    query = inp['question']
    threshold = inp['threshold']
    
    d = [doc for doc,score in vecs.similarity_search_with_relevance_scores(query) if score >= threshold]
    if len(d) < 1:
        raise Exception("Not found!")
    return "\n\n".join([x.page_content for x in d])

main_chain = ({
        "context" : lambda x: check_threshold(x, vecs), "question" : lambda x: x['question']
    } | prompt | llm | StrOutputParser()
).with_fallbacks([fallback_chain])

main_chain.invoke({"question":"Hello, good morning"})
```

### Expected behavior

fallback_chain get triggered whenever the main_chain raise an exception
Issue: Use python namespace capabilities to manage standalone packages
Labels: name: auto:improvement

### Issue you'd like to raise.

Recently, langchain released the google gemini independent package to connect the google gemini LLM capabilities.

This is also the first independent package released by langchain, which is a very big progress and change.

But I noticed that the name of this package is langchain-google-genai, which may not be very systematic.

Perhaps, we can use python's namespace feature to manage all langchain-related packages.

Documentation about namespace package:
- https://packaging.python.org/guides/packaging-namespace-packages/
- https://www.python.org/dev/peps/pep-0420/

### Suggestion:

Use the namespace capability to manage and publish all independent packages of langchain. The specific directory structure is as follows：

docs: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/

```
pyproject.toml # AND/OR setup.py, setup.cfg
src/
    langchain/ # namespace package
        # No __init__.py here.
        google-genai/
            # Regular import packages have an __init__.py.
            __init__.py
            module.py
```

and then, you can use like:

```python
import langchain.google-genai

from langchain import google-genai

# ... code
```
Feat add volcano embedding
Labels: name: lgtm, name: area: embeddings, name: auto:enhancement, name: size:L

Description: Volcano Ark is an enterprise-grade large-model service platform for developers, providing a full range of functions and services such as model training, inference, evaluation, fine-tuning. You can visit its homepage at https://www.volcengine.com/docs/82379/1099455 for details. This change could help developers use the platform for embedding.
Issue: None
Dependencies: volcengine
Tag maintainer: @baskaryan
Twitter handle: @hinnnnnnnnnnnns
python-lint
Labels: name: area: agent, name: lgtm, name: auto:enhancement, name: template, name: size:L

# Description: _python-lint_

This agent writes Python code that is formatted and linted using `black`, `ruff`, and `mypy`, but does not execute the code. It writes the code to a temporary file and then runs the linters. Once these checks pass, the code is returned.

# Dependencies

- black
- ruff
- mypy

# Demo

The functionality can be seen here: https://huggingface.co/spaces/joshuasundance/langchain-streamlit-demo
Enhancement on feature/yaml output parser
Labels: name: lgtm, name: auto:improvement, name: auto:documentation, name: area: models, name: size:L

Adding to my previously, already merged PR I made some further improvements:

* Added documentation to the existing Pydantic Parser notebook, with an example using LCEL and `with_retry()` on `OutputParserException`.
* Added an additional output example to the prompt
* More lenient parser in terms of LLM output format
* Amended unit test

FYI @hwchase17
Google Gemini
Labels: name: auto:enhancement, name: area: models

### Feature request

With Gemini Pro going GA today (Dec. 13th).
When can users of LangChain expect an update to use the new LLM?

### Motivation

This will allow users of LangChain to use the latest LLM that Google is providing along with their safety settings.

### Your contribution

I can try and help. Happy to contribute where needed
Fix for Issue #14663
Labels: name: auto:bug, name: area: models, name: size:XS

 - **Description:** Update to tools.py to allow aliased tool inputs to be included in the _parse_input function output
  - **Issue:** This fixes [Issue #14663](https://github.com/langchain-ai/langchain/issues/14663)
  - **Twitter handle:** [@consultchrisq ](https://twitter.com/consultchrisq?lang=en)
Include scores in MongoDB Atlas QA chain results
Labels: name: area: vector store, name: auto:improvement, name: size:S

Adds the ability to return similarity scores when using `RetrievalQA.from_chain_type` with `MongoDBAtlasVectorSearch`.  Requires that  `return_source_documents=True` is set.

Example use:

```
vector_search = MongoDBAtlasVectorSearch.from_documents(...)

qa = RetrievalQA.from_chain_type(
	llm=OpenAI(), 
	chain_type="stuff", 
	retriever=vector_search.as_retriever(search_kwargs={"additional": ["similarity_score"]}),
	return_source_documents=True
)

...

docs = qa({"query": "..."})

docs["source_documents"][0].metadata["score"] # score will be here
```

I've tested this feature locally, using a MongoDB Atlas Cluster with a vector search index.
Fixing the Issue with DashScopeEmbeddings Handling More than 25 Rows of Data
Labels: name: lgtm, name: area: embeddings, name: auto:bug, name: size:M

<!-- 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.
 -->
 
This change addresses the issue where DashScopeEmbeddingAPI limits requests to 25 lines of data, and DashScopeEmbeddings did not handle cases with more than 25 lines, leading to errors. I have implemented a fix to manage data exceeding this limit efficiently.
SQLDatabaseChain with LlamaCpp Llama2 "Chain Run Errored With Error: ArgumentError: <class 'TypeError'>: wrong type" 
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

LangChain version 0.0.348
Python version 3.10
Operating System MacOS Monterey version 12.6
SQLAlchemy version 2.0.23

### Who can help?

@hwchase17 
@agola11


### 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
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```# Connect to db
# Create an SQLAlchemy engine
engine = create_engine("mysql+mysqlconnector://user:pass@host/database")

# Test the database connection
try:
    # Connect and execute a simple query
    with engine.connect() as connection:
        query = text("SELECT 1")
        result = connection.execute(query)
        for row in result:
            print("Connection successful, got row:", row)
except Exception as e:
    print("Error connecting to database:", e)

# Create an instance of SQLDatabase
db = SQLDatabase(engine)

# using Llama2 
llm = LlamaCpp(
    model_path="/path_to/llama-2-7b.Q4_K_M.gguf", 
    verbose=True, 
    n_ctx=2048)

# using Default and Suffix prompt template
PROMPT = PromptTemplate(
    input_variables=["input", "table_info", "dialect", "top_k"],
    template=_DEFAULT_TEMPLATE + PROMPT_SUFFIX,
)

db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True, return_sql=True, 
                                     prompt=PROMPT)

langchain.debug = True

response = db_chain.run(formatted_prompt)
print(response


### Expected behavior

Expected Behavior: Expected to generate SQL queries without errors.

Actual Behavior: Received TypeError: wrong type and context window exceedance errors.

File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_cpp/llama.py", line 1325, in _create_completion
    f"Requested tokens ({len(prompt_tokens)}) exceed context window of {llama_cpp.llama_n_ctx(self._ctx)}"
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_cpp/llama_cpp.py", line 612, in llama_n_ctx
    return _lib.llama_n_ctx(ctx)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type```