delayedkarma/langchain-issues huggingface dataset:
ImportError: cannot import name 'BabyAGI' from 'langchain_experimental' 
Labels: name: area: embeddings, name: auto:bug, name: area: models

### System Info

I can not import BabyAGI

from langchain_experimental import BabyAGI

The langchain version is:

pip show langchain
Name: langchain
Version: 0.0.334
Summary: Building applications with LLMs through composability
Home-page: https://github.com/langchain-ai/langchain
Author:
Author-email:
License: MIT
Location: c:\users\test\anaconda3\envs\nenv\lib\site-packages
Requires: aiohttp, anyio, async-timeout, dataclasses-json, jsonpatch, langsmith, numpy, pydantic, PyYAML, requests, SQLAlchemy, tenacity
Required-by: langchain-experimental


### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

import dotenv
from dotenv import load_dotenv
load_dotenv()
import os

import langchain
from langchain.embeddings import OpenAIEmbeddings
import faiss
from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore

# Define the embedding model
embeddings_model = OpenAIEmbeddings(model="text-embedding-ada-002")

# Initialize the vectorstore
embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)
vectorstore = FAISS(embeddings_model, index, InMemoryDocstore({}), {})

from langchain.llms  import OpenAI
from langchain_experimental import BabyAGI

### Expected behavior

I want to be able  to execute:

# Define the embedding model
embeddings_model = OpenAIEmbeddings(model="text-embedding-ada-002")
OpenAI Assistant in Python 
Labels: name: area: agent, name: auto:enhancement, name: area: models

### Feature request

I hope this message finds you well. I noticed that OpenAI has recently unveiled their Assistant API, and I observed that the Langchain framework in JavaScript has already implemented an agent utilizing this new API. Could you kindly provide information on when this integration will be extended to Python?

For your reference, here is the documentation for the JavaScript implementation: [JavaScript Doc Reference](https://js.langchain.com/docs/modules/agents/agent_types/openai_assistant).

Thank you for your assistance.

### Motivation

This is a new feature from OpenAI and will be really useful for building LLM-based Apps which needs to utilize code generation feature.

### Your contribution

N/A
Add `SagemakerAsyncEndpoint` to use sagemaker async endpoints
Labels: name: auto:enhancement, name: area: models, name: integration: aws, name: size:XXL

  - **Description:** Add a SagemakerAsyncEndpoint to be able to use not only realtime inference Endpoints. Started from #6940 and added some enhancements. Moreover, fixed documentation issues for SagemakerEndpoint as well.
  - **Issue:** does not apply
  - **Dependencies:** no additional dependencies
  - **Tag maintainer:** 
  - **Twitter handle:** small and no thanks :-)
Add a `MultiFieldRetriever` to search content and metadata at the sametime.
Labels: name: auto:enhancement, name: size:L

  - **Description:** I created the `MultiFieldRetriever` to search not only the content of a document but also its metadata. The difference between it and the `Self-query Retriever` is that the `MultiFieldRetriever` merges the document's content and metadata and performs a single search, rather than searching the content first and then filtering the results by metadata. **You can see how it works in the [document notebook ](https://github.com/langchain-ai/langchain/blob/008618d38a3f8329c5aef4f2eb1f5da4f1e89401/docs/docs/modules/data_connection/retrievers/multi_field.ipynb)
  
  - **Dependencies:** No
  - **Tag maintainer:** @baskaryan 
  - **Twitter handle:** DayuanJian21687
docs: align custom_tool document headers
Labels: name: area: doc loader, name: auto:documentation

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->

On the [Defining Custom Tools](https://python.langchain.com/docs/modules/agents/tools/custom_tools) page, there's a 'Subclassing the BaseTool class' paragraph under the 'Completely New Tools - String Input and Output' header. Also there's another 'Subclassing the BaseTool' paragraph under no header, which I think may belong to the 'Custom Structured Tools' header.

Another thing is, there's a 'Using the tool decorator' and a 'Using the decorator' paragraph, I think should belong to 'Completely New Tools - String Input and Output' and 'Custom Structured Tools' separately.

This PR moves those paragraphs to corresponding headers.
Any time I try to use a openAPI API that requires auth, the openapi_chain call fails. 
Labels: name: auto:bug, name: area: models

### System Info

langchain                 0.0.334
python                      3.11.5

### Who can help?
@hwchase17 


### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

hubspot_chain = get_openapi_chain("https://api.hubspot.com/api-catalog-public/v1/apis/crm/v3/objects/companies",
headers={"Authorization": "Bearer <My Hubspot API token>"})

hubspot_chain("Fetch all contacts in my CRM, please")
 
 I get the error : 
BadRequestError: Error code: 400 - {'error': {'message': "'get__crm_v3_objects_companies_{companyId}_getById' does not match '^[a-zA-Z0-9_-]{1,64}$' - 'functions.1.name'", 'type': 'invalid_request_error', 'param': None, 'code': None}}

This happens with other APIs too, I've tried the following :
1. OpenAPI
2. Asana
3. Hubspot
4. Slack
None work. 




### Expected behavior

The API calls should work, I should get response to my natural language requests, which should get internally mapped to actions, as specified in the OpenAPI specs I've supplied.
Issue: How to use other natural languages besides English?
Labels: name: auto:question, name: auto:improvement, name: area: models

### Issue you'd like to raise.

Hello,
Thanks for this framework. It's making everyone's work simpler!

I'm using an LLM model to infer data from Portuguese websites, and expecting answers in Portuguese. But some of Langchain features, namely the "Get format instructions" for Output Parses come written in English. I'm not sure what the best approach would be here.

Should I do all my prompting in English, and just add "Answer in Portuguese" at the end?

Should this be a feature in Langchain, and if so, how would it work?

I'm not sure asking the community to translate it would be the right approach, because this is not just about translation, but making sure the prompts work correctly. I would be fine with some api call to replace the English text with my translation, but that doesn't seem to be part of the public API at the moment.

Thanks,

### Suggestion:

_No response_
why when the system doesn't find the answer to the user's question, show hadith still appears?
Labels: name: area: agent, name: auto:bug, name: area: models

async def query(update: Update, context: CallbackContext):
  global chain, metadatas, texts

  if chain is None:
      await context.bot.send_message(
          chat_id=update.effective_chat.id,
          text="Please load the chain first using /load")
      return

  user_query = update.message.text

  cb = AsyncFinalIteratorCallbackHandler()
  cb.stream_final_answer = True
  cb.answer_prefix_tokens = ["FINAL", "ANSWER"]

  cb.answer_reached = True
  res = await chain.acall(user_query, callbacks=[cb])
  answer = res["answer"]
  sources = res.get("source_documents", [])
  context.user_data['sources'] = sources

  await context.bot.send_message(chat_id=update.effective_chat.id, text=answer)

  for idx, source in enumerate(sources, start=1):
      source_name = source.metadata.get("source", f"Unknown Source {idx}").replace(".", "")
      keyboard = [[InlineKeyboardButton("Show Hadith", callback_data=str(idx))]]

      await context.bot.send_message(chat_id=update.effective_chat.id,
                                     text=f"{idx}. {source_name}",
                                     reply_markup=InlineKeyboardMarkup(keyboard))



### Idea or request for content:

please help me, if the system cannot find the user's answer based on the existing context then the show hadith will not be displayed either the source name or keyboard
Add docugami-kg-rag template
Labels: name: area: doc loader, name: auto:enhancement, name: template, name: size:XXL

**Description**: Adds a new template that uses the Docugami Loader for KG-RAG conversation. This template contains a reference architecture for Retrieval Augmented Generation against a set of documents using Docugami's XML Knowledge Graph (KG-RAG).

More information found in the [README](https://github.com/docugami/langchain/tree/kgrag/template/templates/docugami-kg-rag#readme)
Issue: <openai APIConnectionError>
Labels: name: auto:bug, name: area: models

### Issue you'd like to raise.

```
import uvicorn
import os

from typing import AsyncIterable, Awaitable
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.responses import FileResponse, StreamingResponse
from langchain.callbacks import AsyncIteratorCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage, ChatMessage
import asyncio

async def wait_done(fn, event):
    try:
        await fn
    except Exception as e:
        print('error', e)
        event.set()
    finally:
        event.set()

async def call_openai(question):
    callback = AsyncIteratorCallbackHandler()
    model = ChatOpenAI(
        openai_api_key= os.environ["OPENAI_API_KEY"],
        streaming=True, 
        callbacks=[callback]
    )

    print('question', question)
    coroutine = wait_done(model.agenerate(messages=[[HumanMessage(content=question)]]), callback.done)
    task = asyncio.create_task(coroutine)
    print('task', task)
    print('coroutine', callback.aiter())

    async for token in callback.aiter():
        yield f"{token}"

    await task

app = FastAPI()

@app.get("/")
async def homepage():
    return FileResponse('static/index.html')

@app.post("/ask")
def ask(body: dict):
    print('body', body)
    # return call_openai(body['question'])
    return StreamingResponse(call_openai(body['question']), media_type="text/event-stream")

if __name__ == "__main__":
   uvicorn.run(host="127.0.0.1", port=8888, app=app)
```
   
   
   run it:
   
(venv) (base) zhanglei@zhangleideMacBook-Pro chatbot % python server.py                                                                                                
INFO:     Started server process [46402]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8888 (Press CTRL+C to quit)
INFO:     127.0.0.1:53273 - "GET / HTTP/1.1" 200 OK
body {'question': '你好'}
INFO:     127.0.0.1:53273 - "POST /ask HTTP/1.1" 200 OK
question 你好
question 你好
task <Task pending name='Task-6' coro=<wait_done() running at /Users/zhanglei/Desktop/github/chatbot/server.py:21>>
coroutine <async_generator object AsyncIteratorCallbackHandler.aiter at 0x117158e40>
Retrying langchain.chat_models.openai.acompletion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised APIConnectionError: Error communicating with OpenAI.
   
 

### Suggestion:

_No response_
Add new models to openai callback
Labels: name: auto:improvement, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
**Description:** Adding the new models to the openai callback function, info taken from [model announcement](https://platform.openai.com/docs/models) and [pricing](https://openai.com/pricing)

A short description for a short PR :)
I get a `NotImplementedError` when I use `docsearch.as_retriever` with `similarity_score_threshold`
Labels: name: area: embeddings, name: area: vector store, name: auto:bug

### Discussed in https://github.com/langchain-ai/langchain/discussions/12799

<div type='discussions-op-text'>

<sup>Originally posted by **younes-io** November  2, 2023</sup>
I have an `NotImplementedError: ` error when I run this code:


```python
embeddings = OpenAIEmbeddings(deployment=embedding_model, chunk_size=1)
docsearch = OpenSearchVectorSearch(index_name=index_company_docs, embedding_function=embeddings,opensearch_url=opensearch_url, http_auth=('user', auth))

doc_retriever = docsearch.as_retriever(
                search_type="similarity_score_threshold",
                search_kwargs={'score_threshold': 0.8}
            )


qa = RetrievalQAWithSourcesChain.from_chain_type(
    memory=memory,
    llm=llm,
    chain_type="stuff",  # See other types of chains here
    retriever=doc_retriever,
    return_source_documents=True,
    verbose=True,
    chain_type_kwargs=chain_type_kwargs,
)

response = qa({"question": "When was the company founded?"})

```</div>
@tool decorator for StructuredTool.from_function doesn't fill in the `__name__` attribute correctly
Labels: name: area: agent, name: auto:bug

### System Info

Macos: 13.4.1 (apple silicon M1)
python version 3.10.13
relevant packages: 
langchain 				0.0.334
pydantic					1.10.13
pydantic_core			2.10.1


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

### Reproduction

https://colab.research.google.com/drive/18d2UIFd3LHwkD3ml6_OydetvytKNnoBW?usp=sharing

1. `from langchain.tools import tool`
2. define a simple structured function
3. Use `StructuredTool.from_function(simple_function)`



### Expected behavior

I expected that it would either work, or tell me that the @tool decorator is not meant to be used with StructuredTool. This is not specified anywhere in the docs or code.
Fix typo in timescalevector.ipynb
Labels: name: area: vector store, name: auto:documentation

enviornment -> environment

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Add OpenAI API v1 support for ChatAnyscale and fixed a bug with openai_api_key
Labels: name: auto:improvement, name: area: models

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
1. Add OpenAI API v1 support
2. Fixed a bug to call `get_secret_value` on a str value (values["openai_api_key"])
If i assign two SemanticSimilarityExampleSelector with different data in different variable but it combines
Labels: name: auto:bug, name: area: models

### System Info

I'm using colab

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] 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

from langchain.prompts.example_selector.semantic_similarity import SemanticSimilarityExampleSelector

key_selector = SemanticSimilarityExampleSelector(vectorstore=few_shots,k=2)

few_shots_selector = SemanticSimilarityExampleSelector(vectorstore=few_shots,k=2)

key_selector.select_examples({"All": "who is in Bengaluru?"})

# It's return from few_shots_selector

### Expected behavior

key_selector.select_examples({"All": "who is in Bengaluru?"})

it's need to return from key_selector
Issue: <ConversationalRetrievalChain.from_llm and  partition_pdf  >
Labels: name: area: memory, name: area: embeddings, name: area: vector store, name: auto:question, name: area: models, name: integration: chroma

### Issue you'd like to raise.

Why did I follow the tutorial below to generate vector library data, but I wanted to use ConversationalRetrievalChain.from_llm to answer my question, but couldn't answer the question? Or can I only answer with chain?


https://github.com/langchain-ai/langchain/blob/master/cookbook/Semi_Structured_RAG.ipynb?ref=blog.langchain.dev


code show as below:

def read_item(query=Body(..., embed=True)):
    question=query
    print(question)
    embeddings = OpenAIEmbeddings()
    vector_store_path = r"/mnt/PD/VS"
    docsearch = Chroma(persist_directory=vector_store_path, embedding_function=embeddings)


    # Build prompt
    template = """Use the following pieces of context to answer the question at the end. \
    If you don't know the answer, just say that you don't know, don't try to make up an answer. \
    Use three sentences maximum. Keep the answer as concise as possible. Always say "thanks for asking!" \
    at the end of the answer.
    {context}
    {chat_history}
    Question: {question}
    Helpful Answer:"""

    # Build prompt


    #QA_CHAIN_PROMPT = PromptTemplate.from_template(template)
    prompt = PromptTemplate(
    input_variables=["chat_history", "context", "question"],
    template=template,
)

    store = InMemoryStore()
    id_key = "doc_id"

    # The retriever (empty to start)
    retriever = MultiVectorRetriever(
        vectorstore=docsearch,
        docstore=store,
        id_key=id_key,
    )

    llm = OpenAI(
        temperature=0,max_tokens=1024,
        model_name="gpt-4-1106-preview"
    )
    memory = ConversationKGMemory(llm=llm,memory_key='chat_history',return_messages=True,output_key='answer')
    qa = ConversationalRetrievalChain.from_llm(
        llm=llm,
        chain_type="stuff",
        retriever=retriever,
        memory=memory,
        return_source_documents=True,
        return_generated_question=True,
        combine_docs_chain_kwargs={'prompt': prompt}
    )
    # 进行问答
    result = qa({"question": question})
    #print(qa.combine_documents_chain.memory)
    return  result

### Suggestion:

_No response_
PGVector needs to close its connection if it is garbage collected
Labels: name: area: vector store, name: auto:bug

Description: Without this change, PGVector was using lots of connections and would eventually be unable to keep making connections. 
Issue: Resolves #9696 
Dependencies: None 
Twitter: @sumukhsridhara 

More context: 

The `__del__` method gets called when the object is about to be garbage collected.  Without this, users (like us) have run into errors like the below 

```
psql: FATAL: remaining connection slots are reserved for non-replication superuser connections
```


<!-- Thank you for contributing to LangChain!

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->