delayedkarma/langchain-issues huggingface dataset:
Don't throw JSON decode error in OpenAIFunctionsAgent
Labels: name: area: agent, name: auto:bug

related to https://github.com/appfolio/af_reactor/issues/1438

### Expected behavior

For a `BaseTool` the OpenAIFunctionCallingAgent reliably outputs a response of the form
```json
{"name": "<tool_name>", "arguments": {"__arg1": "<tool_input>"}}
```

### Actual behavior

For some inputs it formats the response as
```json
{"name": "<tool_name>", "arguments": "<tool_input>"}
```
which leads to a `JSONDecodeError`. The agent doesn't seem to follow the "hacky" format very reliably, even when explicitly encouraged in the system prompt.

@hinthornw


<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - 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
 -->
Integration test on BingSearchAPIWrapper
Labels: name: auto:enhancement

### Feature request

Hello, I have a proposal on adding Integration TCs on BingSearchAPIWrapper, in utilities/bing_search, similar with GoogleSerperAPIWrapper.
As bing search provides several API endpoints like [Bing News Search API](https://www.microsoft.com/en-us/bing/apis/bing-news-search-api), I thought it would be good to add some TCs on bing search, to make baseline for further implementation on other bing apis.
For the test, "BING_SUBSCRIPTION_KEY" would be necessary.

### Motivation

As bing search provides several API endpoints like [Bing News Search API](https://www.microsoft.com/en-us/bing/apis/bing-news-search-api), I thought it would be good to add some TCs on bing search, to make baseline for further implementation on other bing apis.


### Your contribution

If you allow me, i would like to contribute on this.
Handle simpler tool input schemas for structured tools
Labels: name: auto:improvement

### Feature request

Recognize input schemas that do not use `Field` as structured schemas.

### Motivation

A simple schema without `Field` values such as this one will fail to be recognized as a structured schema:

```python
class RepeatTextSchema(BaseModel):
    text: str
    occurences: int
```

It will thus give such an error:

```
occurences
  field required (type=value_error.missing)
```

I guess it would provide a greater developer experience if any schema with multiple variables would be recognized as a structured schema.

### Your contribution

None so far but happy to help if I can.
Fix `allowed_search_types` in `VectorStoreRetriever`
Labels: name: area: vector store, name: auto:bug



<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - 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
 -->

I guess `allowed_search_types` is unexpectedly changed in https://github.com/hwchase17/langchain/commit/6792a3557dc396804a12ba8892b36a322434c7c6, so that we cannot specify `similarity_score_threshold` here.

```python
class VectorStoreRetriever(BaseRetriever):
    ...
    allowed_search_types: ClassVar[Collection[str]] = (
        "similarity",
        "similarityatscore_threshold",
        "mmr",
    )

    @root_validator()
    def validate_search_type(cls, values: Dict) -> Dict:
        """Validate search type."""
        search_type = values["search_type"]
        if search_type not in cls.allowed_search_types:
            raise ValueError(...)
        if search_type == "similarity_score_threshold":
            ... # UNREACHABLE CODE
```

VectorStores Maintainers: @rlancemartin @eyurtsev
Issue:in the multiprompt chain connecting sqldatabasechain
Labels: name: auto:question

### Issue you'd like to raise.

 def from_prompts(
        cls,
        llm: BaseLanguageModel,
        db: SQLDatabase,
        prompt_infos: List[Dict[str, str]],
        default_chain: Optional[LLMChain] = None,
        verbose: bool = False,
        **kwargs: Any,
    ) -> Self:
        """Convenience constructor for instantiating from destination prompts."""
        destinations = [f"{p['name']}: {p['description']}" for p in prompt_infos]
       
        destinations_str = "\n".join(destinations)
        
        router_template = MULTI_SQL_ROUTER_TEMPLATE.format(
            destinations=destinations_str
        )
        router_prompt = PromptTemplate(
            template=router_template,
            input_variables=["input"],
            output_parser=RouterOutputParser(next_inputs_inner_key="query"),
        )
        
        router_chain = LLMRouterChain.from_llm(llm, router_prompt)
        
        destination_chains = {}
        for p_info in prompt_infos:
            name = p_info["name"]
            prompt_template = p_info["prompt_template"]
            
            prompt = PromptTemplate(template=prompt_template,
                                    input_variables=["input" ],
                                    )
            
            chain = SQLDatabaseChain.from_llm(llm, db,prompt=prompt,
                                              output_key="text",
                                              return_intermediate_steps=True,
                                              verbose=True,)
            
            destination_chains[name] = chain
        _default_chain = default_chain or ConversationChain(llm=llm, output_key="text")
        
        return cls(
            router_chain=router_chain,
            destination_chains=destination_chains,
            default_chain=_default_chain,
            **kwargs,
        )
If the enter prompt is not related to database the how can we route them to the defaultchain Or LLMchain  and check the logs on which prompt info is executed for that particular prompt.

### Suggestion:

_No response_
Bug: Chroma().add_texts() return empty ids list when metadata is not None
Labels: name: area: embeddings, name: area: vector store, name: auto:bug

### System Info

LangChain version: '0.0.238'

### Who can help?

SemanticSimilarityExampleSelector().add_example() raise "IndexError" exception due to empty list ids returned from Chroma().add_texts() when metadata is not None.

@hwchase17

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

### Reproduction

from langchain.prompts.example_selector.semantic_similarity import SemanticSimilarityExampleSelector
from langchain.vectorstores import Chroma
from langchain.embeddings.huggingface import HuggingFaceEmbeddings

examples_dict = [{'a':'b'}]
embedding_function = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
example_selector = SemanticSimilarityExampleSelector.from_examples(
                                # This is the list of examples available to select from.
                                examples_dict,
                                # This is the embedding class used to produce embeddings which are used to measure semantic similarity.
                                embedding_function,
                                # This is the VectorStore class that is used to store the embeddings and do a similarity search over.
                                Chroma,  # type: ignore
                                # This is the number of examples to produce and include per prompt
                                k=min(3, len(examples_dict)),
                            )

example_selector.add_example(examples_dict[0])

### Expected behavior

ids returned from Chroma().add_texts() should be a list of ids of texts are added
DOC: Unable to Pass HuggingFace Access Token via Huggingface TextGen Inference for large language model hosted in HuggingFace Inference Endpoint in protected mode.
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:

**Documentation Link:** https://python.langchain.com/docs/modules/model_io/models/llms/integrations/huggingface_textgen_inference

### Idea or request for content:

_No response_
Support pydantic v2
Labels: name: auto:improvement

### Feature request

Please support pydantic v2 version.

### Motivation

Pydantic v2 [released](https://docs.pydantic.dev/latest/blog/pydantic-v2-final/) a few weeks ago with [a lot of features](https://docs.pydantic.dev/latest/blog/pydantic-v2/#performance) shipped.

> Looking at the pydantic-core [benchmarks](https://github.com/pydantic/pydantic-core/tree/main/tests/benchmarks) today, 
> pydantic V2 is between 4x and 50x faster than pydantic V1.9.1.
> In general, pydantic V2 is about 17x faster than V1 when validating a model containing a range of common fields.

### Your contribution

Let me know if you allow contribution to this then will try to work on this.
Issue: using Fine-tuning model with Langchain
Labels: name: area: agent, name: auto:improvement

### Issue you'd like to raise.

Hi, I am using a fine tuned model that generates user prompts to SQL queries, instead of the default model provided by langchain. The reason for doing this is because langchain does not know about all the data from the database unless you provide context to it but there is a lot of data hence why it can create incorrect SQL queries also it is unable to form complex queries for similar reasons even after you give it context. 

So my question is based upon the output I am getting below. Is there a way to keep the initial question I asked the same throughout like in the action input, instead of "SOME_BRANCH_NAME" I want the entire sentence to go through to the SQLDatabaseChain like the user initially asked which is "what is the summary of last 3 issues reported by SOME_BRANCH_NAME". Basically since the Action Input is different from what the user asked, it is generating the wrong SQL query since what it should be doing is this, "SELECT summary FROM sla_tat_summary WHERE organization like '%SOME_BRANCH_NAME%' ORDER BY ReportedDate DESC LIMIT 3;" instead of what is shown below. I could just use the SQLDatabaseChain on its own which does get the exact query I want since I was able to make sure only the prompt the user gave went through, but the agent is needed since I am using it for things other than SQL generation. 


user prompt:  what is the summary of last 3 issues reported by SOME_BRANCH_NAME 
> Entering new AgentExecutor chain...
 I need to find out what the last 3 issues reported by SOME_BRANCH_NAME were.
Action: TPS Issue Tracker Database
Action Input: SOME_BRANCH_NAME

> Entering new SQLDatabaseChain chain...
SOME_BRANCH_NAME:
SELECT organization, COUNT(*) FROM sla_tat_summary WHERE severity = 'Level 2 - Critical' GROUP BY organization ORDER BY COUNT(*) DESC LIMIT 1;

### Suggestion:

In summary send user prompt as it is to Action Input.
Invalid prompt schema; check for mismatched or missing input parameters. {'relevant_context', 'user_query'} (type=value_error)Issue: <Please write a comprehensive title after the 'Issue: ' prefix>
Labels: name: auto:bug

### Issue you'd like to raise.

Getting missing input parameter error. Is there anything i am missing?

````
ValidationError                           Traceback (most recent call last)
Input In [82], in <cell line: 17>()
      1 from langchain import LLMChain, OpenAI, PromptTemplate
      2 prompt_template = f"""
      3 Answer the question based on the contexts below. 
      4 If the question cannot be answered using the information 
   (...)
     14 Question:{user_query}
     15 Answer:"""
---> 17 prompt = PromptTemplate(
     18     input_variables=["relevant_context","user_query"], template=prompt_template
     19 )
     20 llm = LLMChain(llm=OpenAI(), prompt=prompt)

File ~/anaconda3/lib/python3.9/site-packages/pydantic/main.py:341, in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for PromptTemplate
__root__
  Invalid prompt schema; check for mismatched or missing input parameters. {'relevant_context', 'user_query'} (type=value_error)`
```

```
`from langchain import LLMChain, OpenAI, PromptTemplate
prompt_template = f"""
Answer the question based on the contexts below. 
If the question cannot be answered using the information 
provided answer with "I don't know".

###

Contexts:
{relevant_context}

###

Question:{user_query}
Answer:"""

prompt = PromptTemplate(
    input_variables=["relevant_context","user_query"], template=prompt_template
)
llm = LLMChain(llm=OpenAI(), prompt=prompt)`

```
### Suggestion:

_No response_
Langchain support Alibaba Cloud's Tongyi Qianwen model?
Labels: name: auto:question, name: auto:enhancement

### Feature request

How does Alibaba Cloud's Tongyi Qianwen Big Model combine with Langchain?
langchain如何与阿里云的通义千问大模型结合起来

### Motivation

 Alibaba Cloud's Tongyi Qianwen

### Your contribution

none
Issue:  Langsmith running using local docker containers, roadmap, local model support?
Labels: name: auto:question, name: auto:improvement

Hi! I have been using langmith on on local env using docker.
Is there a roadmap for continue supporting that? 
is langsmith going to be totally independent non-opensource per se?
Asking this because I can't really use the public langsmith service due to NDA, and I also have some issues that i'm happy to help fixing. Like I did with my other langchain contributions.
But since langsmith is not public I guess there is no workflow for contribution or bugfix?
Current i'm using langchain with local open source models, langsmith works great but playground won't work, my guess this is hardcoded to use OpenAI or something like that.
CallbackManager  _handle_event consumes Exceptions
Labels: name: auto:improvement

### Discussed in https://github.com/hwchase17/langchain/discussions/8003

<div type='discussions-op-text'>

<sup>Originally posted by **kevinmat** July 20, 2023</sup>
Hi,
I see that function consumes the Exception , Is it possible to override this functionality so that any exception from callbacks returns back the flow instead of continuing the flow

def _handle_event(
    handlers: List[BaseCallbackHandler],
    event_name: str,
    ignore_condition_name: Optional[str],
    *args: Any,
    **kwargs: Any,
) -> None:
    """Generic event handler for CallbackManager."""
    message_strings: Optional[List[str]] = None
    for handler in handlers:
        try:
            if ignore_condition_name is None or not getattr(
                handler, ignore_condition_name
            ):
                getattr(handler, event_name)(*args, **kwargs)
        except NotImplementedError as e:
            if event_name == "on_chat_model_start":
                if message_strings is None:
                    message_strings = [get_buffer_string(m) for m in args[1]]
                _handle_event(
                    [handler],
                    "on_llm_start",
                    "ignore_llm",
                    args[0],
                    message_strings,
                    *args[2:],
                    **kwargs,
                )
            else:
                logger.warning(f"Error in {event_name} callback: {e}")
        except Exception as e:
            logging.warning(f"Error in {event_name} callback: {e}")</div>
Update base.py to remove ValueError
Labels: name: area: memory, name: auto:improvement

  - Description: This update removes the ValueError raised in the self.memory and _chain_type methods. These errors were causing issues when users attempted to use chains without intending to save. The methods now instead raise warnings, allowing chains to function as intended when not being saved.
  - Issue: Not applicable. This is an improvement rather than a bug fix.
  - Dependencies: No new dependencies introduced.
  - Tag maintainer: @hwchase17, as this change affects the Memory functionality of LangChain.

All checks for linting and testing are passing. No new integration is added so there are no additional tests or example notebooks included.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11
feat: Add with_history option for chatglm
Labels: name: auto:improvement

In certain 0-shot scenarios, the existing stateful language model can unintentionally send/accumulate the .history.

This commit adds the "with_history" option to chatglm, allowing users to control the behavior of .history and prevent unintended accumulation.

Possible reviewers @hwchase17 @baskaryan @mlot

Refer to discussion over this thread: https://twitter.com/wey_gu/status/1681996149543276545?s=20
Added streaming support to Replicate
Labels: name: auto:improvement

Streaming support is useful if you are doing long-running completions or need interactivity e.g. for chat... adding it to replicate, using a similar pattern to other LLMs that support streaming.

Housekeeping: I ran `make format` and `make lint`, no issues reported in the files I touched.

I did update the replicate integration test but ran into some issues, specifically:

1. The original test was failing for me due to the model argument not being specified... perhaps this test is not regularly run? I fixed it by adding a call to the lightweight hello world model which should not be burdensome for replicate infra.
2. I couldn't get the `make integration_tests` command to pass... a lot of failures in other integration tests due to missing dependencies... however I did make sure the particluar test file I updated does pass, by running `poetry run pytest tests/integration_tests/llms/test_replicate.py`

Finally, I am @tjaffri https://twitter.com/tjaffri for feature announcement tweets... or if you could please tag @docugami https://twitter.com/docugami we would really appreciate that :-)

Tagging model maintainers @hwchase17  @baskaryan 

Thank for all the awesome work you folks are doing.
HuggingFaceTextGenInference bug fix: Multiple values for keyword argument
Labels: name: lgtm, name: auto:bug

Fixed the bug causing: `TypeError: generate() got multiple values for keyword argument 'stop_sequences'`

```python
res = await self.async_client.generate(
                prompt,
                **self._default_params,
                stop_sequences=stop,
                **kwargs,
            )
```
The above throws an error because stop_sequences is in also in the self._default_params.

@baskaryan review please?
Issue: Tool is always called with a string parameter instead of Model despite using OPENAI_FUNCTIONS agent 
Labels: name: area: agent, name: auto:question

### Issue you'd like to raise.

Hi, 

I have defined an OPENAI_FUNCTIONS agent. I have created a tool from a function where I have defined a BaseModel as input parameter

```
class FooInputModel(BaseModel):
    id: str 
    name: str

agent_kwargs = {
    "extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")]
}
memory = ConversationBufferMemory(memory_key="memory", return_messages=True)

tool= Tool.from_function(
      name= "FooGenerator",
      description= "Foo the bar",
      func=foo,
      args_schema= FooInputModel
    )

agent = initialize_agent([tool],
                         llm,
                         agent=AgentType.OPENAI_FUNCTIONS,
                         agent_kwargs=agent_kwargs,
                         memory=memory)
```

my function foo is properly called when necessary, however the input is always a string whereas I would like a "FooInputModel". How can I achieve this ? And how can I see if the agent is actually using the functions calling from OpenAI because I have doubts it's working and when I print the agent I don't see any FunctionMessage in the history.

Thanks


### Suggestion:

_No response_