delayedkarma/langchain-issues huggingface dataset:
Typo in Variable Name in script_chain.run() 
Labels: name: auto:bug, name: area: models

### System Info

Name: langchain
Version: 0.0.265
Python 3.10.7


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

### Reproduction

prompt=st.text_input("enter search key")

llm=OpenAI(temperature=0.9)
script_memory=ConversationBufferMemory(input_key='title', memory_key='history')
script_template=PromptTemplate(
    input_variables=['title', 'wikiepedia_research'],
    template='Write me Youtube video script based on this TITLE: {title} while leveraging this wikipedia research: {wikiepedia_research}'

)
script_chain=LLMChain(llm=llm, prompt=script_template, verbose=True, output_key='script',memory=script_memory)

wiki = WikipediaAPIWrapper()
wiki_research = wiki.run(prompt)
# key should be wikipedia_research
 script = script_chain.run(title=title, wikiepedia_research=wiki_research)


![github](https://github.com/langchain-ai/langchain/assets/47233790/490f2da5-7ab6-4490-ac84-056bb902587b)


### Expected behavior

 script = script_chain.run(title=title, wikipedia_research=wiki_research)
If values["document_variable_name"] happens to be equal to one of the variable names in llm_chain_variables, the if condition check would fail, skipping the error throw.
Labels: name: auto:bug

https://github.com/langchain-ai/langchain/blob/e986afa13a1de73f403eebe05bd4b25781c12788/libs/langchain/langchain/chains/combine_documents/stuff.py#L96C76-L96C76

 If values["document_variable_name"] happens to be equal to one of the variable names in llm_chain_variables, the if condition check would fail, skipping the error throw.
DOC: missed items in the `API Reference:` auto-generated section
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:

See this page: https://python.langchain.com/docs/use_cases/multi_modal/image_agent
![image](https://github.com/langchain-ai/langchain/assets/2256422/4847b842-8b44-471e-8bda-4181ca6738da)

The `from langchain import OpenAI` class was not extracted into the `API Reference:` section.

My guess is that was because the `langchain import` doesn't have `.` in the namespace. Other classes with `dot` were extracted.

Another example: https://python.langchain.com/docs/use_cases/more/code_writing/llm_math

### Idea or request for content:

_No response_
Cassandra Vector Store, add metadata filtering + improvements
Labels: name: area: vector store, name: auto:improvement

This PR addresses a few minor issues with the Cassandra vector store implementation and extends the store to support Metadata search.

Thanks to the latest cassIO library (>=0.1.0), metadata filtering is available in the store.

Further,
- the "relevance" score is prevented from being flipped in the [0,1] interval, thus ensuring that 1 corresponds to the closest vector (this is related to how the underlying cassIO class returns the cosine difference);
- bumped the cassIO package version both in the notebooks and the pyproject.toml;
- adjusted the textfile location for the vector-store example after the reshuffling of the Langchain repo dir structure;
- added demonstration of metadata filtering in the Cassandra vector store notebook;
- better docstring for the Cassandra vector store class;
- fixed test flakiness and removed offending out-of-place escape chars from a test module docstring;

To my knowledge all relevant tests pass and mypy+black+ruff don't complain. (mypy gives unrelated errors in other modules, which clearly don't depend on the content of this PR).

Thank you!
Stefano
Stream the response of the custom tools in the agent
Labels: name: area: agent, name: auto:question

### Issue you'd like to raise.

llm = ChatOpenAI(temperature=0, model_name = args.ModelName, verbose = True, streaming = True, callbacks = [MyCallbackHandler(new_payload)])


class StaticSearchTool(BaseTool):
    name = "Search_QA_System"
    description = "Use this tool to answer cuurent events 
    # return_direct = True

    def _run(
        self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None
    ) -> str:
        """Use the tool."""
        return qa.run(query)

    async def _arun(
        self, query: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None
    ) -> str:
        """Use the tool asynchronously."""
        return await qa.arun(query)
    
def define_search_tool():
    search = [StaticSearchTool()]
    return search
agent_executor = initialize_agent(
        define_search_tool(),
        llm,
        system_message = system_message,
        extra_prompt_messages = [MessagesPlaceholder(variable_name="memory")],
        agent_instructions = "Analyse the query closely and decide the query intend. If the query requires internet to search than use google-serper to answer the query. Try to invoke `google-serper` most of the times",
        agent=AgentType.OPENAI_FUNCTIONS,
        agent_kwargs= agent_kwargs,
        verbose = True,
        memory = memory,
        handle_parsing_errors=True,
    )


In this code I need to stream the output of the StaticSearchTool() not the output of the agent.
How can we do this 

### Suggestion:

_No response_
Issue: openai.error.PermissionError: You are not allowed to generate embeddings from this model
Labels: name: area: embeddings, name: auto:bug, name: auto:question, name: area: models

### Issue you'd like to raise.

I have an issue when trying to set 'gpt-3.5-turbo' as a model to create embeddings.

When using the 'gpt-3.5-turbo' to create LLM, everything works fine:

`llm = OpenAI(model_name='gpt-3.5-turbo', temperature=0, openai_api_key=OPENAI_API_KEY, max_tokens=512)`

Also creating embeddings without specifying a model works fine:
`embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)`

But when I try to use 'gpt-3.5-turbo' for embeddings, I get the following error: 
`embeddings = OpenAIEmbeddings(model='gpt-3.5-turbo', openai_api_key=OPENAI_API_KEY)`

Error:
_openai.error.PermissionError: You are not allowed to generate embeddings from this model_

This seems weird to me since I have just used the same model to create LLM. So I have access to it and should be able to use it. Unless creation of embeddings and LLM differs somehow.

Can somebody please advise?



### Suggestion:

_No response_
Fix region sagemaker
Labels: name: auto:bug, name: area: models

I encountered an issue while working with the Sagemaker endpoint module and attempting to establish a connection to the client. 
The error message `"Failed to load credentials for AWS client authentication`" was being raised, despite passing the **`profile_name`** parameter. 

Upon reviewing the code, I realized that the error was caused by the omission of the **`region_name`** parameter. To address this, I introduced a validation step to ensure that the **`region_name`** parameter is provided, and I implemented an error-raising mechanism in case the parameter is found to be `None`. 

This adjustment effectively resolved the issue.

Thanks!
Random compatibility issues
Labels: name: auto:improvement

A fix for random issues like this:

```
from pydantic import BaseModel, Field # <-- may be v2 namespace


class CalculatorInput(BaseModel):
    question: str = Field()

Tool.from_function( # <-- tool uses v1 namespace
    func=lambda question: 'hello',
    name="Calculator",
    description="useful for when you need to answer questions about math",
    args_schema=CalculatorInput
)

```
Added generic event handler for both tockens and functions calls
Labels: name: auto:improvement, name: area: models

# Description

Main motivation for this PR is to sync with JS langchain https://github.com/hwchase17/langchainjs/pull/2025

Added `on_event` callback that works for both token and openai function calls in streaming mode

Twitter: [@ShelfDev](https://twitter.com/ShelfDev)
intermediate_steps missing last thought content
Labels: name: area: agent, name: auto:bug

### System Info

Problem:
The intermediate_steps don't contain last `AI thought information`. Did I do anything wrong or was that a bug?
Or is there anything I can do to extract the last `AI thought information`?

Code:
```
agent = initialize_agent(
            [self.search_tool, self.wikipedia_tool],
            self.llm,
            agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
            verbose=True,
            max_iterations=5,
            handle_parsing_errors=True,
            return_intermediate_steps=True
        )
        result = agent(formatted_script_template)
        intermediate_steps = result['intermediate_steps']
```

The intermediate_steps contains only one step and it is missing the last `Thought`

What intermediate_steps look like:
<img width="644" alt="Screenshot 2023-08-15 at 11 19 40 AM" src="https://github.com/langchain-ai/langchain/assets/3535601/d22bc6dd-11b1-4974-97dd-594bd7038d04">

What I expected to have:
<img width="1170" alt="Screenshot 2023-08-15 at 11 20 59 AM" src="https://github.com/langchain-ai/langchain/assets/3535601/6457135b-3257-42ba-801c-8f5523830337">



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

### Reproduction

Run the code I provided in the description and set breakpoint to inspect intermediate steps.
The thought was missing in intermediate steps.

### Expected behavior

The complete observation & thought will be available in intermediate steps.
use openapi_pydantic
Labels: name: auto:refactor

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Store and retrieve documents from remote instance
Labels: name: area: vector store, name: auto:documentation



Replace this entire comment with:
  - Description: I have added documentation on how to create a remote instance of chromadb on AWS, store the documents in it, retrieve the documents from it and then query them using chains, 
  - Issue: NA,
  - Dependencies: NA,
  - Tag maintainer: @eyurtsev,
  - Twitter handle: NA
milvus not support normalize_L2 of embedding
Labels: name: area: embeddings, name: area: vector store, name: auto:enhancement

### Feature request

cur version, milvus not support normalize_L2 of embedding, when can add this feature?

Thanks

### Motivation

Normalization and regularization of features can improve retrieval performance, and it is convenient to set thresholds when calculating similarity through inner product

### Your contribution

NO
fix faiss bug, reset index_to_docstore_id
Labels: name: area: vector store, name: auto:bug

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
How to output code variables word by word in `ChatOpenAI` instead of console？
Labels: name: auto:question, name: area: models

![image](https://github.com/langchain-ai/langchain/assets/49063302/351cde17-07aa-43a6-9b8b-596c5213a948)

As shown in the figure, I hope that the `resp `variable can capture these outputs in each for loop, rather than displaying them on the console, What should I do?
OpenAIFunctionsAgent | Streaming Bug
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

langchain = "^0.0.264"
python = "^3.10"



### Who can help?

@agola11 @hwchase17

### Information

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

### Reproduction

```py
from langchain.agents.agent_toolkits import create_retriever_tool
from langchain.agents.agent_toolkits import create_conversational_retrieval_agent
from langchain.agents import AgentExecutor
from langchain.chat_models import ChatOpenAI
from langchain.agents.openai_functions_agent.agent_token_buffer_memory import AgentTokenBufferMemory
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
from langchain.schema.messages import SystemMessage
from langchain.prompts import MessagesPlaceholder


llm = ChatOpenAI(temperature = 0, model="gpt-3.5-turbo-0613", stream=True)
memory = AgentTokenBufferMemory(memory_key="history", llm=llm)
retriever = vectorstore.as_retriever()
 
tool = load_custom_tool(retriever, model_name="gpt-3.5-turbo", return_direct=False)
tools = [tool]

system_message = SystemMessage(
        content=(
            "Do your best to answer the questions. "
            "Feel free to use any tools available to look up "
            "relevant information, only if necessary"
        )
)
prompt = OpenAIFunctionsAgent.create_prompt(
    system_message=system_message,
    extra_prompt_messages=[MessagesPlaceholder(variable_name="history")]
)
agent = OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt)


agent_executor = AgentExecutor(
    agent=agent, 
    tools=tools, 
    memory=memory, 
    verbose=True,
    return_intermediate_steps=True
)

result = await agent_executor.acall({"input": "What color is the sky?"})
result
```

### Expected behavior

The code errors with the following

```
in Chain.acall(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    347 except (KeyboardInterrupt, Exception) as e:
    348     await run_manager.on_chain_error(e)
--> 349     raise e
    350 await run_manager.on_chain_end(outputs)
    351 final_outputs: Dict[str, Any] = self.prep_outputs(
    352     inputs, outputs, return_only_outputs
    353 )

in Chain.acall(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    337 run_manager = await callback_manager.on_chain_start(
    338     dumpd(self),
...
    361             message=message,
    362             generation_info=dict(finish_reason=res.get("finish_reason")),
    363         )

TypeError: 'async_generator' object is not subscriptable
```

I was hoping to be able to use the OpenAIFunctions agent as a drop in replacement for my existing agent. I need streaming to be working to do so. Is streaming supported?
fix: max_marginal_relevance_search and docs in Dingo
Labels: name: area: vector store, name: auto:bug

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Random question and Answer generation while using ConversationalRetrievalChain  
Labels: name: area: memory, name: area: vector store, name: auto:bug, name: area: models

### System Info

python 3.11
langchain 0.0.263.

### Who can help?

@agol

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

### Reproduction

I want to add memory into docs based question answer chatbot but after adding memory the chatbot randomly generate question and answer automatically.
![testing](https://github.com/langchain-ai/langchain/assets/125140336/52cf28c9-da29-42c0-8ab5-075983679c61)


### Expected behavior

I need chatbot for docs based question answer and chat history.
add Epsilla vectorstore
Labels: name: area: vector store, name: auto:enhancement

[Epsilla](https://github.com/epsilla-cloud/vectordb) vectordb is an open-source vector database that leverages the advanced academic parallel graph traversal techniques for vector indexing.
This PR adds basic integration with [pyepsilla](https://github.com/epsilla-cloud/epsilla-python-client)(Epsilla vectordb python client) as a vectorstore.
docs: update LlamaCpp max_tokens args
Labels: name: lgtm, name: auto:documentation

This PR updates documentations only, `max_length` should be `max_tokens` according to latest LlamaCpp API doc: https://api.python.langchain.com/en/latest/llms/langchain.llms.llamacpp.LlamaCpp.html

<!-- 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/hwchase17/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. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
This is not a chat model and thus not supported in the v1/chat/completions endpoint. Did you mean to use v1/completions?
Labels: name: auto:bug, name: area: models

### Issue you'd like to raise.

def define_model(model_threshold):
  get_no = np.random.randint(1, 11)
  if int(model_threshold) >= get_no:
    return "gpt-4-0613"
  else:
    return "gpt-3.5-turbo-16k-0613"

messages = get_chat_history_format(api_params=api_params)    
    model_name = define_model(model_threshold)
    print(f"Model Name : {model_name}")
    llm = ChatOpenAI(temperature=0.7, model_name = model_name, streaming = True, callbacks = [MyCallbackHandler(api_params)])
    agent_executor = initialize_agent(
        define_search_tools(llm),
        llm,
        system_message = system_message,
        extra_prompt_messages = [MessagesPlaceholder(variable_name="memory")],
        agent_instructions = "Analyse the query closely and decide the query intend. If the query requires internet to search than use google-serper to answer the query. Try to invoke `google-serper` most of the times",
        agent=AgentType.OPENAI_FUNCTIONS,
        agent_kwargs= agent_kwargs,
        verbose = True,
        memory = memory,
        handle_parsing_errors=True,
    )


I am getting endpoint error




### Suggestion:

_No response_
Issue: load_summarization_chain in 'map_reduce' mode not breaking up document
Labels: name: area: doc loader, name: auto:bug, name: area: models

### Issue you'd like to raise.

I'm using the load_summarization_chain with the type of 'map_reduce' in the following fashion:

```
    summary_prompt = ChatPromptTemplate.from_template(
        "Write a long-form summary of the following text delimited by triple backquotes. "
        "Include detailed evidence and arguments to make sure the generated paragraph is convincing. "
        "Write in Chinese."
        "```{text}```"
    )

    combine_prompt = ChatPromptTemplate.from_template(
        "Write a long-form summary of the following text delimited by triple backquotes. "
        "Include all the details as much as possible."
        "Write in Chinese."
        "```{text}```"
    )
    combined_summary_chain = load_summarize_chain(llm=llm, chain_type="map_reduce", map_prompt=summary_prompt,
                                                  combine_prompt=combine_prompt, return_intermediate_steps=True)

    summary, inter_steps = combined_summary_chain({"input_documents": data, "token_max": 8000})

```

I've checked several tutorials and there doesn't seem to be anything wrong with this. But I keep getting this error:
`openai.error.InvalidRequestError: This model's maximum context length is 8192 tokens. However, your messages resulted in 15473 tokens. Please reduce the length of the messages.`

It's as if the map_reduce chain isn't breaking up the data and running as if it's a stuffing chain instead. What did I do wrong?


### Suggestion:

_No response_