delayedkarma/langchain-issues huggingface dataset:
STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION finishes chain BEFORE using a tool
Labels: name: area: agent, name: auto:bug

### System Info

I've recently changed to use this agent since I started getting errors with `chat-conversational-react-description` (about it not being able to use multi-input tools). I've noticed that it often finishes a chain telling the user that it'll make a search/use a tool but it never does (because the chain is already finished).

### Who can help?

@hwchase17 @agola11 

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

### Reproduction

This is how the agent is set up
```python
from langchain.chat_models import ChatOpenAI
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from langchain.agents import AgentType, initialize_agent
from agent_tools.comparables_tool import ComparablesTool
# from agent_tools.duck_search_tool import duck_search
from langchain.prompts import SystemMessagePromptTemplate, PromptTemplate
from agent_tools.python_repl_tool import PythonREPL
from token_counter import get_token_count
from langchain.prompts import MessagesPlaceholder
from langchain.memory import ConversationBufferMemory


tools = [PythonREPL(), ComparablesTool()]

chat_history = MessagesPlaceholder(variable_name="chat_history")
memory = ConversationBufferMemory(
    memory_key="chat_history", return_messages=True)

gpt = ChatOpenAI(
    temperature=0.2,
    model_name='gpt-3.5-turbo-16k',
    verbose=True
)

conversational_agent = initialize_agent(
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    tools=tools,
    llm=gpt,
    verbose=True,
    max_iterations=10,
    memory=memory,
    agent_kwargs={
        "memory_prompts": [chat_history],
        "input_variables": ["input", "agent_scratchpad", "chat_history"]
    }
)

async def get_response(user_message: str) -> str:

    return await conversational_agent.arun(user_message)
```

And this is what's on the terminal:
```python
FerAtTheFringe#1080 said: "Hey I need to find apartments in madrid with at least 3 rooms" (general)
←[1m> Entering new  chain...←[0m
←[32;1m←[1;3mSure! I can help you find apartments in Madrid with at least 3 rooms. Let me search for some options for you.←[0m
←[1m> Finished chain.←[0m
```

### Expected behavior

```python
FerAtTheFringe#1080 said: "Hey I need to find apartments in madrid with at least 3 rooms" (general)
←[1m> Entering new  chain...←[0m
←[32;1m←[1;3m  "action": "get_comparables",
  "action_input": {
    "latitude": "38.9921979",
    "longitude": "-1.878099",
    "rooms": "5",
    "nresults": "10"
  }
```
'ConversationSummaryMemory' has no attribute 'from_messages'

### System Info

Ubuntu 20.04
Python 3.10
langchain 0.0.166

### Who can help?

@hwchase17 @agola11

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

### Reproduction

This code is retrieved from the official website
https://python.langchain.com/docs/modules/memory/how_to/summary#initializing-with-messages

```python

from langchain.memory import ConversationSummaryMemory, ChatMessageHistory
from langchain.llms import OpenAI
from dotenv import load_dotenv

load_dotenv()

history = ChatMessageHistory()
history.add_user_message("hi")
history.add_ai_message("hi there!")
memory = ConversationSummaryMemory.from_messages(llm=OpenAI(temperature=0), chat_memory=history, return_messages=True)
```

The above code will throw out an exception
```
AttributeError: type object 'ConversationSummaryMemory' has no attribute 'from_messages'
```

I guess the class method has been deprecated?

### Expected behavior

It passes.
ValidationError: 1 validation error for ConversationalRetrievalChain chain_type_kwargs extra fields not permitted (type=value_error.extra)

### System Info

langchain               0.0.206
python 3.11.3

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [ ] 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
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Code 
```

tfretriever = TFIDFRetriever.from_texts(
            ["My name is Luis Valencia",
            "I am 70 years old",
            "I like gardening, baking and hockey"])
        
        template = """
            Use the following context (delimited by <ctx></ctx>) and the chat history (delimited by <hs></hs>) to answer the question:
            ------
            <ctx>
            {context}
            </ctx>
            ------
            <hs>
            {chat_history}
            </hs>
            ------
            {question}
            Answer:
            """
        
        prompt = PromptTemplate(
            input_variables=["chat_history", "context", "question"],
            template=template,
            )
        
        st.session_state['chain'] = chain = ConversationalRetrievalChain.from_llm(llm, 
                                                                                vectordb.as_retriever(),
                                                                                memory=memory,
                                                                                  chain_type_kwargs={
                                                                                    "verbose": True,
                                                                                    "prompt": prompt,
                                                                                    "memory": ConversationBufferMemory(
                                                                                        memory_key="chat_history",
                                                                                        input_key="question"),
                                                                                })

```

Error:

ValidationError: 1 validation error for ConversationalRetrievalChain chain_type_kwargs extra fields not permitted (type=value_error.extra)

### Expected behavior

I should be able to provide custom context to my conversational retrieval chain, without custom prompt it works and gets good answers from vector db, but I cant use custom prompts
PowerBI: catch outdated token

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
This adds just a small tweak to catch the error that says the token is expired rather then retrying.
Can't use arun acall, no return and can't stop

### System Info

langchain-0.0.209

### Who can help?

@hwchase17 

### Information

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

### Related Components

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

### Reproduction

`import asyncio
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain



async def async_generate(chain):
    resp = await chain.arun(product="toothpaste")
    print(resp)


async def generate_concurrently():
    llm = OpenAI(temperature=0.9)
    prompt = PromptTemplate(
        input_variables=["product"],
        template="What is a good name for a company that makes {product}?",
    )
    chain = LLMChain(llm=llm, prompt=prompt)
    tasks = [async_generate(chain) for _ in range(3)]
    await asyncio.gather(*tasks)

asyncio.run(generate_concurrently())`

no error and no answer until timeout
Retrying langchain.llms.openai.acompletion_with_retry.<locals>._completion_with_retry in 4.0 seconds...
I know this message mean it is working  but no  retrun  and can't stop

and   the same problem in  Jupyter, code like this
my code in Jupyter
`import asyncio

from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain



async def async_generate(chain):
    resp = await chain.arun(product="toothpaste")
    print(resp)


async def generate_concurrently():
    llm = OpenAI(temperature=0.9)
    prompt = PromptTemplate(
        input_variables=["product"],
        template="What is a good name for a company that makes {product}?",
    )
    chain = LLMChain(llm=llm, prompt=prompt)
    tasks = [async_generate(chain) for _ in range(3)]
    await asyncio.gather(*tasks)

await generate_concurrently()`


### Expected behavior

no error and no answer until timeout
Retrying langchain.llms.openai.acompletion_with_retry.<locals>._completion_with_retry in 4.0 seconds...
I know this message mean it is working  but no  retrun  and can't stop

and   the same problem in  Jupyter
Issue: How to print the complete prompt that chain used
Labels: name: auto:question, name: area: models

### Issue you'd like to raise.

qa = ConversationalRetrievalChain.from_llm(AzureChatOpenAI(deployment_name="gpt-35-turbo"), db.as_retriever(), memory=memory)
print(qa.combine_docs_chain.llm_chain.prompt)

ChatPromptTemplate(input_variables=['question', 'context'], output_parser=None, partial_variables={}, messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context'], output_parser=None, partial_variables={}, template="Use the following pieces of context to answer the users question. \nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\n{context}", template_format='f-string', validate_template=True), additional_kwargs={}), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='{question}', template_format='f-string', validate_template=True), additional_kwargs={})])

How can I get the complete prompt includes questions and context?



### Suggestion:

_No response_
Fix the markdown rendering issue with a code block inside a markdown code block

### Description

- Fix the markdown rendering issue with a code block inside a markdown, using a different number of backticks for the delimiters.

Current doc site: <https://python.langchain.com/docs/modules/data_connection/document_transformers/text_splitters/code_splitter#markdown>

After fix:
<img width="480" alt="image" src="https://github.com/hwchase17/langchain/assets/3115235/d9921d59-64e6-4a34-9c62-79743667f528">


### Who can review

PTAL @dev2049 

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Merge pull request #1 from hwchase17/master

test

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
fix(docs): broken link for OpenLLM

This link for the notebook of OpenLLM is not migrated to the new format

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change,
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Variable or Conditional Toolbox

### Feature request

How can I make a toolset be dependent on some situation?
In the examples I have seen so far and from what I have been able to piece together from reading code, awhile ago (you guys work fast)... is there a way to make it so that I can only make certain tools available to an Agent at certain times beyond changing the actual tools stack myself in the Agent?


### Motivation

The idea is to keep the agent prompt template as lean as possible.  The goal is to be able to do something like leading an agent through a process with varying toolboxes given the step that it is on.  I have seen that it is possible using function calling, but is it just possible in any type of Agent? 

### Your contribution

This is a feature request.  I can make a contribution of looking at the code and adding this, but I am not sure if it is already possible or planned seeing as you move fast!
How can I implement a custom LangChain class wrapper (LLM model/Agent) for replit-code-v1-3b model?

### Issue you'd like to raise.

Is it possible to integrate [replit-code-v1-3b](https://replicate.com/replit/replit-code-v1-3b) as an [LLM Model](https://python.langchain.com/en/latest/modules/models.html) or an [Agent](https://python.langchain.com/en/latest/modules/agents.html) with [LangChain](https://github.com/hwchase17/langchain), and [chain](https://python.langchain.com/en/latest/modules/chains.html) it in a complex usecase?


### Suggestion:

Any help / hints on the same would be appreciated!
Truncate HF pipeline response

For models like -> "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v2" the generated output doesn't contain the prompt. So it is wrong to filter the first characters of the response.

https://github.com/hwchase17/langchain/blob/9d42621fa4385e519f702b7005d475781033188c/langchain/llms/huggingface_pipeline.py#L172C13-L172C64

https://huggingface.co/h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v2/blob/main/h2oai_pipeline.py
How can I integrate SerpAPI with custom ChatGLM model

### Issue you'd like to raise.

Hello, Team

How can I integrate SerpAPI with custom ChatGLM model. It looks like my code is not correct and I can't find useful information from internet. Hope post here can help me to resolve this issue. Thanks in advcance.
```
import time
import logging
import requests
from typing import Optional, List, Dict, Mapping, Any

import langchain
from langchain.llms.base import LLM
# from langchain.cache import InMemoryCache

#------------------------------
import os
os.environ["SERPAPI_API_KEY"] = '44eafc5bc26834f931324798f8e370e5c5039578dde6ef7a67918f24ed00599f'

from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
#------------------------------

logging.basicConfig(level=logging.INFO)
# 启动llm的缓存
# langchain.llm_cache = InMemoryCache()

class ChatGLM(LLM):
    # 模型服务url
    url = "http://18.183.251.31:8000"

    @property
    def _llm_type(self) -> str:
        return "chatglm"

    def _construct_query(self, prompt: str) -> Dict:
        """构造请求体
        """
        query = {
            "prompt": prompt
        }
        return query

    @classmethod
    def _post(cls, url: str, query: Dict) -> Any:
        """POST请求
        """
        _headers = {"Content_Type": "application/json"}
        with requests.session() as sess:
            resp = sess.post(url,
                             json=query,
                             headers=_headers,
                             timeout=60)
        return resp

    def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
        """_call
        """
        # construct query
        query = self._construct_query(prompt=prompt)
        print(query)

        # post
        resp = self._post(url=self.url, query=query)

        if resp.status_code == 200:
            resp_json = resp.json()
            predictions = resp_json["response"]
            return predictions
        else:
            return "请求模型"

    @property
    def _identifying_params(self) -> Mapping[str, Any]:
        """Get the identifying parameters.
        """
        _param_dict = {
            "url": self.url
        }
        return _param_dict


if __name__ == "__main__":
    llm = ChatGLM()

    # ------------------------------
    tools = load_tools(["serpapi"], llm=llm)
    agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
    agent.run("What's the date today? What great events have taken place today in history?")
    # ------------------------------

    # while True:
    #     prompt = input("Human: ")
    #
    #     begin_time = time.time() * 1000
    #     # 请求模型
    #     response = llm(prompt, stop=["you"])
    #     end_time = time.time() * 1000
    #     used_time = round(end_time - begin_time, 3)
    #     # logging.info(f"chatGLM process time: {used_time}ms")
    #     print("chatGLM process time %s" % {used_time})
    #     print(f"ChatGLM: {response}")
```

### Suggestion:

_No response_
Dynamic fields for BaseModels in PydanticOutputParser? 

### Issue you'd like to raise.

I have the following BaseModel: 

```python
class MainMagnetClass(BaseModel):
    main_materials: List[str] = Field(description="main material")
    additional_doping_elements: List[str] = Field(description="doping")
```
which can be instantiated as: 

```python
instance = PydanticOutputParser(pydantic_object=MainMagnetClass)
```

I would like to know if there is a way to dynamically load the description of the two fields. 

I tried with `construct()` but it doesn't seems to work. 

The reason is that I'm generating a set of queries and for each of them I want to have different "description" for the PydanticOutputParser that is going to be used. 

### Suggestion:

I would load a dict with the fields and their description and pass it to the object so that I could override the default descriptions.