delayedkarma/langchain-issues huggingface dataset:
[fix] ollama astream
Labels: name: auto:bug, name: area: models, name: size:XS

Update ollama.py

<!-- 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.
 -->
Created a RAG with history it's working but not following the prompt instructions properly
Labels: name: auto:bug, name: area: models

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

```bash
qa_system_prompt = """Note\
            Make sure to address the user's queries politely.\
            Compose a comprehensive reply to the query using the search results given.\
            1.Respond to the questions based on the given context. \
            2.please refrain from inventing responses.\
            3.Use as much detail when as possible when responding. Answer step-by-step.\
            4.Locate the answer within the given context.\
            5.Keep the response within 3000 tokens.\
            6. If a user asks the questions like please summarise the above, then you should summarize the previous answer you provided which can be fetched from the history\
            7. If the user queries based on its previous questions please surround your answers based on the history of previous questions\
        
        
        IMPORTANT NOTE: Don't answer question outside of provided context and kindly respond with "I apologize, but that falls outside of my current scope of knowledge."\
        
        
        Use the following context to answer the question:\
                ------
                
                CONTEXT:
                {context}

                """
```


### Description

Using this prompt, this was working fine in v0.0.336 but after i started using this new v0.1.0 code the no matter how i write the prompt it's not following the instruction mentioned below: 

IMPORTANT NOTE: Don't answer question outside of provided context and kindly respond with "I apologize, but that falls outside of my current scope of knowledge.

It's working for few questions and not working for others.

### System Info

%pip install --upgrade langchain langchain-community langchainhub langchain-openai chromadb bs4
python 3.9
model: gpt-3.5-turbo-16k
### 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
how to save plots/graphs when using PythonREPLTool in langchain experimental
Labels: name: area: agent, name: auto:question

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True, return_direct=True)
    
    tools = [PythonREPLTool()]
    
    description = (
    "Useful for when you need to answer questions about employess. "
    "You must not input SQL. Use this more than the Python tool if the question "
    "is about employee data, like 'how many employees are there?' or 'count the number of department'"
    )

    repl_tool = Tool(
        name="Data",  # We'll just call it 'Data'
        func=db_chain.run,
        description=description,
    )

    tools.append(repl_tool)
    
    prefix = "Fulfill the following request as best you can. You have access to the following tools:"

# Remind the agent of the Data tool, and what types of input it expects
    suffix = (
        "Begin! When looking for data, do not write a SQL query. "
        "Pass the relevant portion of the request directly to the Data tool in its entirety."
        "\n\n"
        "Request: {input}\n"
        "{agent_scratchpad}"
    )

    # The agent's prompt is built with the list of tools, prefix, suffix, and input variables
    prompt = ZeroShotAgent.create_prompt(
        tools, prefix=prefix, suffix=suffix, input_variables=["input", "agent_scratchpad"]
    )

    # Set up the llm_chain
    llm_chain = LLMChain(llm=llm, prompt=prompt)

    # Specify the tools the agent may use
    tool_names = [tool.name for tool in tools]
    agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)

    # Create the AgentExecutor
    agent_executor = AgentExecutor.from_agent_and_tools(
        agent=agent, tools=tools, verbose=True, handle_parsing_errors=True
    )
    
    answer = agent_executor.run(question)

    print(answer)

### Description

using langchain experimental, i'm trying to interact with sql db, where i should also be able to plot the graph using natural language. im using the following above method using python repl tool, its displaying the graph but how to save the graph, like in create_pandas_dataframe_agent in langchain agent where we have a save_chatrs=True function.

and also, python repl tool in python or pandas ai which one is the best method to generate graphs/plots in natural language 

### System Info

python: 3.11
langchain: latest version

### 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
- [X] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async
multiple prompt in a single RAG chain
Labels: name: auto:question, name: area: models

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

```python
llm = VertexAI(model_name='gemini-pro', max_output_tokens=512, temperature=0.2)
data = loader.load()
embeddings = VertexAIEmbeddings(model_name='textembedding-gecko@003')
vectorstore = Chroma.from_documents(data, embeddings)
retriever = vectorstore.as_retriever()

template = """
Use the following pieces of context to answer the question at the end.
- If you think you need more information to find proper answer, ask user to clarify.
- If you cannot find a proper answer from the reference, just say we don't have a data from the reference.
Use three sentences maximum and keep the answer as concise as possible.

Context: {context}
Question: {question}
Helpful Answer:

**Resource:** [reference source name]
"""

template2 = """
If the user query lacks of below data, please ask user to get additional data.
- data1
- data2

If the user query has enough data, response with the context directly.
Context: {context}
Question: {question}
Answer: 
"""    

rag_prompt_custom = ChatPromptTemplate.from_template(template)
multi_turn_prompt_custom = ChatPromptTemplate.from_template(template2)  
rag_chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | rag_prompt_custom
    | llm
    | StrOutputParser()
)

response = rag_chain.invoke(message)
    
print(response)
```

### Description

I would like to have two prompt based chat in a single RAG chain.
Below is what I am thinking about.
1. based on query and context information from the document, fine the proper answer.
2. with the generated (found) answer and the user's prompt, consider if the user's prompt lacks of data. If it lacks of data, ask user to get addiitonal data. And if there is enough data to generate and find the answer from the document, response found answer directly.

I have no idea how to make it merged.

### System Info

langchain==0.0.352

### 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
doc bug fix
Labels: name: auto:documentation, name: area: models, name: size:M


  - **Description:** I found some problems in the doc of retry parser:

1. A redundant prompt template
2. The `bad_response` before modification will not raise an `OutputParserException` but a `ValidationError`. Since `OutputFixingParser` and `RetryWithErrorOutputParser` will pass in error by catching `OutputParserException`, if we add double quotes to the content of `bad_response`, it will raise  an `OutputParserException`, then we could run the rest of code.
3. Add "Do not forget to use double quotes" to the prompt to improve the success rate of model correction.
  - **Issue:** N/A
  - **Dependencies:** N/A
inconsistent performance of langchain rag
Labels: name: auto:question, name: area: models

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

```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)
```

### Description

I tried to make the rag chain with the prompt.
In here, I found that the tasks mentioned in the prompt are sometimes followed, but sometimes not.
I would like to make the chain consistent for the user queries.
Is there way to do this?

### System Info

langchain==0.0.352

### Related Components

- [X] LLMs/Chat Models
- [X] 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
community[patch]: add vector param to index query for pinecone vec store
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: integration: pinecone, name: size:XS

 - **Description:** added `vector=` as it will become a required parameter from `pinecone-client 3.0.0.dev10` onwards, 
  - **Issue:** did not raise issue,
  - **Dependencies:** N/A,
  - **Twitter handle:** @jamescalam
community: add the ability to load existing transcripts from AssemblyAI by their id.
Labels: name: area: doc loader, name: auto:improvement, name: size:L

  - **Description:** the existing AssemblyAI API allows to pass a path or an url to transcribe an audio file and turn in into Langchain Documents, this PR allows to get existing transcript by their transcript id and turn them into Documents.
  - **Issue:** not related to an existing issue
  - **Dependencies:** requests
In RunnableSequence Action input / tool_input incorrectly set, ultimately causing incorrect answers, results
Labels: name: auto:bug

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

```
# No code provided
# LangSmith trace link in Description
```

### Description

I test a sample code of CrewAI, which is based on Langchain and I found, again :( that tool_input is incorrectly set, which causes incorrect answers.
I track it in LangSmith and here is the RunnableSequence's input:
```
input: Investigate which AI / LLM assisted IDE assistant can assist coding related questions not only related to the selected code or the opened file, but all the project code files, the console and terminal messages. Check also the most recent IDEs, not only the most popular ones. Your final answer MUST be a full analysis report
tool_names: Google Search
tools: "Google Search: Search Google for recent results."
chat_history: ""
intermediate_steps: []
```
and output:
```
output:
  tool: Google Search
  tool_input: AI / LLM assisted IDE assistant for coding related questions
  log: |-
    
    Thought: Do I need to use a tool? Yes
    Action: Google Search
    Action Input: "AI / LLM assisted IDE assistant for coding related questions"
  type: AgentAction
```
so we can see the original task of:
_**"Investigate which AI / LLM assisted IDE assistant can assist coding related questions not only related to the selected code or the opened file, but all the project code files, the console and terminal messages. Check also the most recent IDEs, not only the most popular ones. Your final answer MUST be a full analysis report"**_
was transformed to a Google search for:
_**"AI / LLM assisted IDE assistant for coding related questions"**_
which obviously doesn't provide the search results relevant to original task!

The trace with Zephyr-7B via Hugging Face: https://smith.langchain.com/public/d4076fff-78d7-48ab-bdfe-d463bd1ffcb3/r
The same with gpt-4: https://smith.langchain.com/public/1fa8da61-6cc9-448c-8aa3-fd75d930e623/r


**So what and where should we finetune, modify to keep search term or any other tool_input correct, without huge distortion?**

### System Info

Windows 10
Python 3.11.6
langchain-core: 0.1.10
langchain-community: 0.0.12
crewai: 0.1.32

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async
add demo website mention
Labels: name: area: vector store, name: auto:enhancement, name: template, name: size:XXL

<!-- 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.
 -->
community: add new gpt-3.5-turbo-1106 finetuned for cost calculation
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:XS

**Description:** Added the new gpt-3.5-turbo-1106 for **finetuned** cost calculation, 
**Issue:** no issue found open

By the information in OpenAI the pricing is the same as the older model (0613)
langchain 0.0.27 should NOT be installed on python 3.6.5
Labels: name: auto:bug

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

This is a minor issue with metadata for pip. I opened a ticket against pip. 
https://github.com/pypa/pip/issues/12476
But I was told that I should report the issue to this project. 

[langchain_0.0.27.log](https://github.com/langchain-ai/langchain/files/13940154/langchain_0.0.27.log)

If there existed a langchain version which doesn't use future feature annotations, install it.
Otherwise, prompt the user that no suitable version.

### Description

I installed langchain 0.0.27 on python 3.6.5 on my Windows 10 successfully. But I run into an issue when I tried import the library.

from langchain.llms import Ollama
SyntaxError: future feature annotations is not defined
[PEP-563](https://www.python.org/dev/peps/pep-0563/#enabling-the-future-behavior-in-python-3-7)future annotations are introduced in Python 3.7. That means langchain 0.0.27 which depends on future feature annotations should NOT be installed on Python 3.6.5.


### System Info

pip 21.3.1
python 3.6.5/Windows 10



### Related Components

- [ ] 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
community: Ollama - Parameter structure to follow official documentation
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:L

## Feature
- Follow parameter structure as per official documentation 
  - top level parameters (e.g. model, system, template) will be passed as top level parameters
  - other parameters will be sent in options unless options is provided
![image](https://github.com/langchain-ai/langchain/assets/17451563/d14715d9-9701-4ee3-b44b-89fffea62389)

## Tests
- Test if top level parameters handled properly
- Test if parameters that are not top level parameters are handled as options
- Test if options is provided, it will be passed as is
AttributeError: 'list' object has no attribute 'embed_query'
Labels: name: area: embeddings, name: auto:bug

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.

### Example Code

``` Python
# Chunking the sentence with fixed size
from langchain.text_splitter import RecursiveCharacterTextSplitter

text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=20)
all_splits = text_splitter.split_documents(documents)
```

``` Python
from langchain_community.embeddings import HuggingFaceBgeEmbeddings

model_name = "BAAI/bge-base-en"
model_kwargs = {"device": "cpu"}
encode_kwargs = {"normalize_embeddings": True}
embeddings = HuggingFaceBgeEmbeddings(
    model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs
)
```

``` Python
# Creating New Index:
!CREATE VECTOR INDEX KG_QuestionAnswering IF NOT EXISTS FOR (n:LabelName) ON (n.propertyName) OPTIONS {dimension: 1024};
```

``` Python
index_name="KG_QuestionAnswering"
# Instantiate Neo4j vector from documents
store = Neo4jVector.from_existing_index(
    documents,
    HuggingFaceBgeEmbeddings(),
    url=os.environ["NEO4J_URI"],
    username=os.environ["NEO4J_USERNAME"],
    password=os.environ["NEO4J_PASSWORD"]
)
```


### Description

``` 
AttributeError                            Traceback (most recent call last)
[<ipython-input-24-4e3c558558b3>](https://localhost:8080/#) in <cell line: 3>()
      1 index_name="KG_QuestionAnswering"
      2 # Instantiate Neo4j vector from documents
----> 3 store = Neo4jVector.from_existing_index(
      4     documents,
      5     HuggingFaceBgeEmbeddings(),

1 frames
[/usr/local/lib/python3.10/dist-packages/langchain_community/vectorstores/neo4j_vector.py](https://localhost:8080/#) in __init__(self, embedding, search_type, username, password, url, keyword_index_name, database, index_name, node_label, embedding_node_property, text_node_property, distance_strategy, logger, pre_delete_collection, retrieval_query, relevance_score_fn)
    236         self.search_type = search_type
    237         # Calculate embedding dimension
--> 238         self.embedding_dimension = len(embedding.embed_query("foo"))
    239 
    240         # Delete existing data if flagged

AttributeError: 'list' object has no attribute 'embed_query'
```

### System Info

``` YAML
Windows: 11
pip == 23.3.1
python == 3.10.10
langchain == 0.1.0
transformers == 4.36.2
sentence_transformers == 2.2.2
Neo4j == 5
```

### Related Components

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