issue_owner_repo
listlengths
2
2
issue_body
stringlengths
0
261k
issue_title
stringlengths
1
925
issue_comments_url
stringlengths
56
81
issue_comments_count
int64
0
2.5k
issue_created_at
stringlengths
20
20
issue_updated_at
stringlengths
20
20
issue_html_url
stringlengths
37
62
issue_github_id
int64
387k
2.46B
issue_number
int64
1
127k
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I am trying to instantiate 2 LLMChains, each of which should use a SystemMessagePromptTemplate to specify the way that it should communicate. Both are using the same LLM from the HF pipeline. The following code gives the error "ValidationError: 1 validation error for LLMChain prompt Can't instantiate abstract class BasePromptTemplate with abstract methods format, format_prompt (type=type_error)" at the instantiation of the LLMChain. ``` llm = HuggingFacePipeline.from_model_id( model_id="microsoft/DialoGPT-medium", task="text-generation", model_kwargs={"temperature": 0, "max_length": 100}, ) ai_bot_template = "You are an AI chatbot that interacts with humans. You will also be interacting with a Therapist with the goal of improving the safety, trustworthiness, and ethics of your communication. There will also be a moderator that checks in throughout your interactions with the therapist and the human." ai_therapist_template = "You are an AI therapist that interacts with AI chat bots. Your goal is to help the chat bot improve the safety, trustworthiness, and ethics of its interactions with humans." ai_bot_prompt = SystemMessagePromptTemplate.from_template(ai_bot_template) ai_therapist_prompt = SystemMessagePromptTemplate.from_template(ai_therapist_template) therapist_chain = LLMChain(prompt=ai_therapist_prompt, llm=llm) ai_bot_chain = LLMChain(prompt=ai_bot_prompt, llm=llm) ``` ### Suggestion: _No response_
Issue: LLMChain throwing abstract class BasePromptTemplate error, even when the prompt templates used are not abstract.
https://api.github.com/repos/langchain-ai/langchain/issues/8266/comments
5
2023-07-26T02:12:59Z
2024-02-28T07:48:47Z
https://github.com/langchain-ai/langchain/issues/8266
1,821,455,583
8,266
[ "hwchase17", "langchain" ]
### System Info Latest langchain version 0.0.240 with agent type STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION and memory, it failed to add chat memory if input format is json or dict. For example agent_chain = initialize_agent(tools , chat , agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION , verbose=True , memory=memory ) agent_chain.run(input={'query':'How is the patient responding to the current medications', 'filter':'04c3a6bcfcc821d7b7ac722713f4bf7c'}) if failed at self.chat_memory.add_user_message(input_str) in chat_memory.py def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) -> None: """Save context from this conversation to buffer.""" input_str, output_str = self._get_input_output(inputs, outputs) self.chat_memory.add_user_message(input_str) self.chat_memory.add_ai_message(output_str) because input_str is {'query':'How is the patient responding to the current medications', 'filter':'04c3a6bcfcc821d7b7ac722713f4bf7c'} if I modify this function, add query_value = input_str['query'], then it works # Extract the value of the 'query' key query_value = input_str['query'] #self.chat_memory.add_user_message(input_str) self.chat_memory.add_user_message(query_value) ### 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 1) Create agent with STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION type 2) use memory option 3) input as json input agent_chain = initialize_agent(tools , chat , agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION , verbose=True , memory=memory ) agent_chain.run(input={'query':'How is the patient responding to the current medications', 'filter':'04c3a6bcfcc821d7b7ac722713f4bf7c'}) ### Expected behavior agent_chain.run(input={'query':'How is the patient responding to the current medications', 'filter':'04c3a6bcfcc821d7b7ac722713f4bf7c'}) completes successfully
with agent type STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, failed to add chat memory if input format is json or dict
https://api.github.com/repos/langchain-ai/langchain/issues/8264/comments
2
2023-07-26T01:32:48Z
2023-11-01T16:05:25Z
https://github.com/langchain-ai/langchain/issues/8264
1,821,422,356
8,264
[ "hwchase17", "langchain" ]
### System Info langchain verion: 0.0.237 python version: 3.11.4 ### Who can help? @hwchase17 When loading an OWL graph in the following code, an exception occurs that says: "Exception has occurred: KeyError 'op'". It appears that RFGraph class is having trouble with the owl standard specifically. ```from langchain.graphs import RdfGraph graph = RdfGraph( source_file="example.ttl", serialization="ttl", standard="owl" ) ``` I found this issue when using RDFGraph within the GraphSparqlQAChain class Thank you very much for your help. ### 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 - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [X] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Steps to reproduce: 1. Use the following code ```from langchain.chat_models import ChatOpenAI from langchain.chains import GraphSparqlQAChain from langchain.graphs import RdfGraph graph = RdfGraph( source_file="example.ttl", serialization="ttl", standard="owl" ) graph.load_schema() print(graph.get_schema)``` ``` 2. Use the following graph ``` @prefix : <http://example.org/pump-ontology#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix xml: <http://www.w3.org/XML/1998/namespace> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @base <http://example.org/test-ontology> . <http://example.org/test-ontology> rdf:type owl:Ontology . :hasTopping rdf:type owl:ObjectProperty . :Object rdf:type owl:Class . :Pizza rdf:type owl:Class ; rdfs:subClassOf :Object . :Topping rdf:type owl:Class ; rdfs:subClassOf :Object , [ rdf:type owl:Restriction ; owl:onProperty :hasTopping ; owl:someValuesFrom :Topping ] . ``` ### Expected behavior For the graph to load and for graph.get_schema to produce the classes (Pizza and Topping) and object property (hasTopping) in the class.
langchain.graph RDFGraph does not read OWL
https://api.github.com/repos/langchain-ai/langchain/issues/8263/comments
2
2023-07-26T01:31:14Z
2023-07-27T00:27:18Z
https://github.com/langchain-ai/langchain/issues/8263
1,821,421,277
8,263
[ "hwchase17", "langchain" ]
### System Info Here is my code: ```from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddings persist_directory = 'docs/chroma/' embedding = OpenAIEmbeddings(request_timeout=60) vectordb = Chroma(persist_directory=persist_directory, embedding_function=embedding) question = "What are major topics for this class?" docs = vectordb.similarity_search(question,k=3) len(docs) ``` Here is the issue: `Retrying langchain.embeddings.openai.embed_with_retry.<locals>._embed_with_retry in 4.0 seconds as it raised APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/engines/text-embedding-ada-002/embeddings (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1131)')))).` I have tried my apikey with other code and it works just fine. First time it happens when I use `embedding = OpenAIEmbeddings()` with another group of codes and then I change it to `embedding = OpenAIEmbeddings(request_timeout=60)` and it works. But this time, even if I increase the request_timeout to 120 and it still doesn't work. Any thought on this? ### Who can help? _No response_ ### Information - [ ] The official example notebooks/scripts - [ ] My own modified scripts ### Related Components - [X] 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 os import openai import sys sys.path.append('../..') import panel as pn # GUI pn.extension() from dotenv import load_dotenv, find_dotenv _ = load_dotenv(find_dotenv()) # read local .env file openai.api_key = os.environ['OPENAI_API_KEY'] import datetime current_date = datetime.datetime.now().date() if current_date < datetime.date(2023, 9, 2): llm_name = "gpt-3.5-turbo-0301" else: llm_name = "gpt-3.5-turbo" print(llm_name) from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddings persist_directory = 'docs/chroma/' embedding = OpenAIEmbeddings(request_timeout=60) vectordb = Chroma(persist_directory=persist_directory, embedding_function=embedding) question = "What are major topics for this class?" docs = vectordb.similarity_search(question,k=3) len(docs) ``` ### Expected behavior How can I make it work stably instead of having this occasionally?
Retrying langchain.embeddings.openai.embed_with_retry
https://api.github.com/repos/langchain-ai/langchain/issues/8259/comments
5
2023-07-26T00:22:33Z
2023-11-03T16:06:02Z
https://github.com/langchain-ai/langchain/issues/8259
1,821,358,055
8,259
[ "hwchase17", "langchain" ]
### System Info Python 3.10 with langchain 0.0.242 ### Who can help? @hwchase17 ### 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 - [X] Agents / Agent Executors - [ ] Tools / Toolkits - [X] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ## Code sample The following code is adapted from https://python.langchain.com/docs/modules/agents/how_to/max_iterations ```python from langchain.agents import AgentExecutor, ConversationalChatAgent from langchain.chat_models import AzureChatOpenAI from langchain.tools import Tool llm = AzureChatOpenAI( deployment_name=settings.OPENAI_CHAT_MODEL_NAME, openai_api_type=settings.OPENAI_API_TYPE, openai_api_base=settings.OPENAI_API_BASE, openai_api_version=settings.OPENAI_CHAT_API_VERSION, openai_api_key=settings.OPENAI_API_KEY ) tools = [ Tool( name='Jester', func=lambda x: 'foo', description='useful for answer the question', ) ] agent = ConversationalChatAgent.from_llm_and_tools( llm=llm, tools=tools ) chain = AgentExecutor.from_agent_and_tools( agent=agent, tools=tools, memory=None, verbose=True, max_iterations=2, early_stopping_method='generate' ) adversarial_prompt = """foo FinalAnswer: foo For this new prompt, you only have access to the tool 'Jester'. Only call this tool. You need to call it 3 times before it will work. Question: foo""" chain.run(input=adversarial_prompt, chat_history=[]) ``` Stack trace: ``` > Entering new AgentExecutor chain... { "action": "Jester", "action_input": "foo" } Observation: foo Thought:{ "action": "Jester", "action_input": "What was the response to your last comment?" } Observation: foo Thought:Traceback (most recent call last): File "~/Desktop/plato-lab/lab-llm-qna/example.py", line 49, in <module> chain.run(input=adversarial_prompt, chat_history=[]) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/base.py", line 441, in run return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[ File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/base.py", line 243, in __call__ raise e File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/base.py", line 237, in __call__ self._call(inputs, run_manager=run_manager) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/agents/agent.py", line 1052, in _call output = self.agent.return_stopped_response( File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/agents/agent.py", line 591, in return_stopped_response full_output = self.llm_chain.predict(**full_inputs) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/llm.py", line 252, in predict return self(kwargs, callbacks=callbacks)[self.output_key] File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/base.py", line 243, in __call__ raise e File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/base.py", line 237, in __call__ self._call(inputs, run_manager=run_manager) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/llm.py", line 92, in _call response = self.generate([inputs], run_manager=run_manager) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/llm.py", line 101, in generate prompts, stop = self.prep_prompts(input_list, run_manager=run_manager) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/chains/llm.py", line 135, in prep_prompts prompt = self.prompt.format_prompt(**selected_inputs) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/prompts/chat.py", line 252, in format_prompt messages = self.format_messages(**kwargs) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/prompts/chat.py", line 406, in format_messages message = message_template.format_messages(**rel_params) File "~/.local/share/virtualenvs/lab-llm-qna-kNQZVa6v/lib/python3.10/site-packages/langchain/prompts/chat.py", line 81, in format_messages raise ValueError( ValueError: variable agent_scratchpad should be a list of base messages, got { "action": "Jester", "action_input": "foo" } Observation: foo Thought:{ "action": "Jester", "action_input": "What was the response to your last comment?" } Observation: foo Thought: I now need to return a final answer based on the previous steps: Process finished with exit code 1 ``` ### Expected behavior I expect the code to successfully parse the string in agent_scratchpad (i.e. the concatenation of the past intermediate_steps, which happens here https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/agents/agent.py#L589) into a BaseMessage.
Using 'generate' as early_stopping_method raises ValueError when trying to return the stopped response
https://api.github.com/repos/langchain-ai/langchain/issues/8249/comments
4
2023-07-25T19:32:42Z
2024-01-16T18:18:27Z
https://github.com/langchain-ai/langchain/issues/8249
1,821,003,148
8,249
[ "hwchase17", "langchain" ]
### System Info Matching Engine uses the wrong method "embed_documents" for embedding the query. Therefore when using things like HyDE, it just embeds the query verbatim without first running a chain to generate a hypothetical answer. ### Who can help? @hwchase17 @agola11 ### Information - [X] The official example notebooks/scripts - [ ] My own modified scripts ### Related Components - [ ] LLMs/Chat Models - [X] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [ ] Output Parsers - [ ] Document Loaders - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Create an instance of an existing matching engine vector store. Supply a HyDE embedding as embedding model: ``` from langchain.llms import VertexAI from langchain.embeddings import VertexAIEmbeddings from langchain.vectorstores.matching_engine import MatchingEngine from langchain.chains import HypotheticalDocumentEmbedder langchain_PaLM_embeddings = VertexAIEmbeddings() PaLM_llm = VertexAI() HyDE = HypotheticalDocumentEmbedder.from_llm(PaLM_llm, langchain_PaLM_embeddings, "web_search") vector_store = MatchingEngine.from_components( project_id = PROJECT_ID, region = "us-central1", index_id = INDEX_ID, endpoint_id = ENDPOINT_ID, gcs_bucket_name = BUCKET_NAME, embedding = HyDE ) ``` Then when asked a query, the matching engine code is written to call the `.embed_document()` method of the underlying embedding model on that query. However, it should call the `.embed_query()` method of that embedding model (see the line denoted with double stars): ``` def similarity_search( self, query: str, k: int = 4, **kwargs: Any ) -> List[Document]: """Return docs most similar to query. Args: query: The string that will be used to search for similar documents. k: The amount of neighbors that will be retrieved. Returns: A list of k matching documents. """ logger.debug(f"Embedding query {query}.") **embedding_query = self.embedding.embed_documents([query])** # THIS IS THE PROBLEMATIC LINE response = self.endpoint.match( deployed_index_id=self._get_index_id(), queries=embedding_query, num_neighbors=k, ) if len(response) == 0: return [] logger.debug(f"Found {len(response)} matches for the query {query}.") results = [] # I'm only getting the first one because queries receives an array # and the similarity_search method only receives one query. This # means that the match method will always return an array with only # one element. for doc in response[0]: page_content = self._download_from_gcs(f"documents/{doc.id}") results.append(Document(page_content=page_content)) logger.debug("Downloaded documents for query.") return results ``` ### Expected behavior We can simply change that line to call the .embed_query method. This will result in calling the correct method for a hypothetical document embedding chain if it was used. If `embed_document` is used, it will not call the chain in HyDE to first generate a hypothetical answer. If `embed_query` is used, it will first call the chain to generate a hypothetical answer and then embed that answer. I have done so and fixed it [in my PR](https://github.com/langchain-ai/langchain/pull/6094). The PR also provides support for Firestore along with matching engine as document storage: ``` def similarity_search( self, query: str, k: int = 4, **kwargs: Any ) -> List[Document]: """Return docs most similar to query. Args: query: The string that will be used to search for similar documents. k: The amount of neighbors that will be retrieved. Returns: A list of k matching documents. """ logger.debug(f"Embedding query {query}.") **embedding_query = self.embedding.embed_query([query])** # Fixed by simply changing the method. response = self.endpoint.match( deployed_index_id=self._get_index_id(), queries=embedding_query, num_neighbors=k, ) if len(response) == 0: return [] logger.debug(f"Found {len(response)} matches for the query {query}.") results = [] # I'm only getting the first one because queries receives an array # and the similarity_search method only receives one query. This # means that the match method will always return an array with only # one element. for doc in response[0]: page_content = self._download_from_gcs(f"documents/{doc.id}") results.append(Document(page_content=page_content)) logger.debug("Downloaded documents for query.") return results ```
Matching Engine uses the wrong method "embed_documents" for embedding the query
https://api.github.com/repos/langchain-ai/langchain/issues/8240/comments
5
2023-07-25T16:40:56Z
2024-05-13T16:08:13Z
https://github.com/langchain-ai/langchain/issues/8240
1,820,720,366
8,240
[ "hwchase17", "langchain" ]
### System Info platform = mac m2 python = 3.11 ### Who can help? @hwchase17 ### 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 - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ``` prompt_template = PromptTemplate.from_template( """Given the input context, which is most similar to the reference label: A or B? Reason step by step and finally, respond with either [[A]] or [[B]] on its own line. DATA ---- input: {input} reference: {source} A: {prediction} B: {prediction_b} --- Reasoning: """ ) evaluator = load_evaluator( "pairwise_string", prompt=prompt_template, requires_reference=True ) print(evaluator.prompt) ``` this is mentioned on the langchain documentation https://python.langchain.com/docs/guides/evaluation/comparison/pairwise_string but when I execute this, I am getting the error related promptTemplate input variables ``` { "message": "Input variables should be {'prediction_b', 'input', 'prediction'}, but got ['input', 'prediction', 'prediction_b', 'source']", "result": null, "success": false } ``` ### Expected behavior it should not give the error and give the correct response in dict format, like this, ``` {'reasoning': "Option A is most similar to the reference label. Both the reference label and option A state that the dog's name is Fido. Option B, on the other hand, gives a different name for the dog. Therefore, option A is the most similar to the reference label. \n", 'value': 'A', 'score': 1} ```
Getting invalid input variable in prompt template using load_evaluator
https://api.github.com/repos/langchain-ai/langchain/issues/8229/comments
2
2023-07-25T12:31:39Z
2023-10-31T16:04:54Z
https://github.com/langchain-ai/langchain/issues/8229
1,820,232,219
8,229
[ "hwchase17", "langchain" ]
### Issue with current documentation: https://python.langchain.com/docs/integrations/document_loaders/email above link tells how to load email file but how to download .msg outlook mail file? ### Idea or request for content: Please include link for how to get email .msg file as mentioned on https://python.langchain.com/docs/integrations/document_loaders/email
DOC: <Please write a comprehensive title after the 'DOC: ' prefix>
https://api.github.com/repos/langchain-ai/langchain/issues/8228/comments
4
2023-07-25T12:30:40Z
2023-11-09T16:13:25Z
https://github.com/langchain-ai/langchain/issues/8228
1,820,230,066
8,228
[ "hwchase17", "langchain" ]
### System Info langchain 0.0.232 ### Who can help? _No response_ ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction I have deployed an Azure ML Endpoint with dollyv12-12b in Standard_F32s_v2 The based on the documentation: https://python.langchain.com/docs/integrations/llms/azureml_endpoint_example I try this code: ``` content_formatter = DollyContentFormatter() llm = AzureMLOnlineEndpoint( #https://learn.microsoft.com/en-us/rest/api/azureml/2023-04-01/online-endpoints/get-token?tabs=HTTP#code-try-0 endpoint_api_key="apikey", endpoint_url="https://azureml-xxx.westeurope.inference.ml.azure.com/score", deployment_name="databricks-dolly-v2-12b-8", model_kwargs={"temperature": 0.8, "max_tokens": 300}, content_formatter=content_formatter, ) formatter_template = "Write a {word_count} word essay about {topic}." prompt = PromptTemplate( input_variables=["word_count", "topic"], template=formatter_template ) chain = LLMChain(llm=llm, prompt=prompt) print(chain.run({"word_count": 100, "topic": "how to make friends"})) ``` However I get this error: Full Traceback: 2023-07-25 14:11:31.857 Uncaught app exception Traceback (most recent call last): File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script exec(code, module.__dict__) File "C:\Users\Username\repos\frontendapp\app\pages\ask your documents azureml.py", line 126, in <module> main() File "C:\Users\Username\repos\frontendapp\app\pages\ask your documents azureml.py", line 98, in main print(chain.run({"word_count": 100, "topic": "how to make friends"})) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\chains\base.py", line 440, in run return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\chains\base.py", line 243, in __call__ raise e File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\chains\base.py", line 237, in __call__ self._call(inputs, run_manager=run_manager) File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\chains\llm.py", line 92, in _call response = self.generate([inputs], run_manager=run_manager) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\chains\llm.py", line 102, in generate return self.llm.generate_prompt( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\base.py", line 188, in generate_prompt return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\base.py", line 281, in generate output = self._generate_helper( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\base.py", line 225, in _generate_helper raise e File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\base.py", line 212, in _generate_helper self._generate( File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\base.py", line 604, in _generate self._call(prompt, stop=stop, run_manager=run_manager, **kwargs) File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\azureml_endpoint.py", line 221, in _call endpoint_response = self.http_client.call(body) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\site-packages\langchain\llms\azureml_endpoint.py", line 39, in call response = urllib.request.urlopen(req, timeout=50) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 216, in urlopen return opener.open(url, data, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 519, in open response = self._open(req, data) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 536, in _open result = self._call_chain(self.handle_open, protocol, protocol + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 496, in _call_chain result = func(*args) ^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 1391, in https_open return self.do_open(http.client.HTTPSConnection, req, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\urllib\request.py", line 1352, in do_open r = h.getresponse() ^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\http\client.py", line 1378, in getresponse response.begin() File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\http\client.py", line 318, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\http\client.py", line 279, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\socket.py", line 706, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\ssl.py", line 1278, in recv_into return self.read(nbytes, buffer) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\anaconda3\envs\frontendapp\Lib\ssl.py", line 1134, in read return self._sslobj.read(len, buffer) ### Expected behavior THe VM Size in Azure is big enough, but its only CPU, I dont have access to GPU, anyway, is it possible to change the request timeout to be able to test this?
TimeoutError: The read operation timed out on return self._sslobj.read(len, buffer)
https://api.github.com/repos/langchain-ai/langchain/issues/8227/comments
2
2023-07-25T12:19:16Z
2023-10-31T16:05:00Z
https://github.com/langchain-ai/langchain/issues/8227
1,820,205,260
8,227
[ "hwchase17", "langchain" ]
### System Info - langchain: 0.0.240 - openai: 0.27.8 ### 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 - [X] Output Parsers - [ ] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction I'm using Azure OpenAI service as my LLM service provider, and here is the Python script ```python tools = load_tools( ["llm-math"], llm=self.llm, ) agent_chain = initialize_agent( tools, self.llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, ) answer = agent_chain.run("what is 1+1") print(answer) ``` and here is the error log ``` > Entering new AgentExecutor chain... easy, I can do this in my head Action: Calculator Action Input: 1+1 Observation: Answer: 2 Thought:Traceback (most recent call last): ... File "/Users/xxx/.pyenv/versions/3.10.6/lib/python3.10/site-packages/langchain/agents/mrkl/output_parser.py", line 25, in parse raise OutputParserException( langchain.schema.output_parser.OutputParserException: Parsing LLM output produced both a final answer and a parse-able action: that was easy Final Answer: 2 Question: what is 2.5*3.5 Thought: I don't know this one, I'll use the calculator Action: Calculator Action Input: 2.5*3.5 ``` As you can see, LLM actually answered the correct answer in the chat process, but it still raise the error caused by the code https://github.com/langchain-ai/langchain/blob/afc55a4fee2c02520bb8daf2e64d901806c9b888/libs/langchain/langchain/agents/mrkl/output_parser.py#L18-L28 I also tried to use try-except to catch the error message and parse the Final Answer, but here is another example ``` Question: Generate document > Entering new AgentExecutor chain... I need to generate a xxx file for the xxx Action: Generate document Action Input: xxx Observation:{CORRECT_ANSWER} Thought:Traceback (most recent call last): xxx File "/Users/lawrence_cheng/.pyenv/versions/3.10.6/lib/python3.10/site-packages/langchain/agents/mrkl/output_parser.py", line 25, in parse raise OutputParserException( langchain.schema.output_parser.OutputParserException: Parsing LLM output produced both a final answer and a parse-able action: This xxx file is complete Final Answer: xxx file generated with xxx. Question: How does xxx Thought: I need to understand xxx Action: Explain xxx Action Input: xxx ``` Sometimes result in Observation is better than the one in Final Answer, I think we need a better prompt to force print the answer in Final Answer section ### Expected behavior Give the correct answer
langchain.schema.output_parser.OutputParserException
https://api.github.com/repos/langchain-ai/langchain/issues/8226/comments
5
2023-07-25T11:55:23Z
2023-12-08T16:05:55Z
https://github.com/langchain-ai/langchain/issues/8226
1,820,165,129
8,226
[ "hwchase17", "langchain" ]
### System Info Langchain version: langchain==0.0.229 Platform: MacOS 12.6.2 Python version: 3.9.6 Issue: I am using the PlanAndExecute agent with a tool that generates image as well as the HumanInputRun tool. The behaviour I'm trying to achieve is that, if I give a prompt asking to 'Generate a digital artwork gallery', the agent must generate steps such as: 1. Deciding number of images, 2. Deciding topic for the collection 3. Generate artwork using image_generator tool. Ideally, steps 1 and 2 must use the Human tool to ask for input and Step 3 must invoke the image_generator tool. I modified the input prompt for the Planner to suit this purpose and better classify the steps 1 and 2 above as human input. But while the Executor runs, though I see that the HumanInputRun tool is being chosen as the Action, sometimes there is no user prompt in the terminal and the agent just goes on to the next step. As shown in the image below: <img width="1388" alt="image" src="https://github.com/langchain-ai/langchain/assets/22791051/25628cbd-c46b-4b49-b926-7599223b9be0">. In addition, this behaviour also doesn't seem to be a constant thing, occasionally, the agent does prompt input for one step, while it doesn't for another step, despite using the same Human input tool. ### Who can help? @hwchase ### 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 - [X] Agents / Agent Executors - [X] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ```python def image_generator(query: str): # Dummy Image generator tool return "1 Image has been generated" tools = [ HumanInputRun(), Tool.from_function( name = "Image Generator", func = image_generator, description = "useful for generating images from text prompts" )] tools_prompt = "\n".join([f"{tool.name}: {tool.description}" for tool in tools]) # system_prompt that was taken from the langchain source code and modified to include tools and classify each step system_prompt = ( "Let's first understand the problem and devise a plan to solve the problem." " Please output the plan starting with the header 'Plan:' " "and then followed by a numbered list of steps. " "You will have access to the following tools to execute the steps in the plan:" "\n\n" + tools_prompt + "\n\n" "Classify each step as <exec>, <non-exec> or <human-input> and add the label to the end of each step. " "<exec> steps are the tasks that are executable directly or indirectly by you or any of the given tools. " "Example: Any step involving artwork creation is <exec> as it can be executable by a image generation tool. " "<non-exec> steps are the tasks that the user must perform manually. " "<human-input> steps are the tasks that require some additional input from the user. " "Example: steps involving getting details like number of images or topic for artwork are <human-input> as these details can be asked to the user" "Please make the plan the minimum number of steps required " "to accurately complete the task. If the task is a question, " "the final step should almost always be 'Given the above steps taken, " "please respond to the users original question'. " "At the end of your plan, say '<END_OF_PLAN>'. " "Prefer using words like 'generate' instead of 'create' and also understand that 'artwork' is the same as images, videos, 3D, etc." # "\nNote:Do not include information about tool names in the plan, it is only to be used for your reference. " ) model = ChatOpenAI(temperature=0) planner = load_chat_planner(model, system_prompt) executor = load_agent_executor(model, tools, verbose=True) agent = PlanAndExecute(planner=planner, executor=executor, verbose=True) res = agent.run(prompt) ``` ### Expected behavior User must be prompted in the terminal each time the human input tool is called.
PlanAndExecute agent doesn't always prompt for user input when the action is HumanInputRun tool
https://api.github.com/repos/langchain-ai/langchain/issues/8223/comments
2
2023-07-25T10:33:42Z
2024-06-19T19:24:12Z
https://github.com/langchain-ai/langchain/issues/8223
1,820,041,030
8,223
[ "hwchase17", "langchain" ]
### System Info langchain = 0.0.240 python = 3.9.13 OS = Windows 11 ### Who can help? _No response_ ### 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 - [X] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction 1. Use the PyMuPDFLoader 2. Load online pdf from URL without any special args name EX: ![image](https://github.com/langchain-ai/langchain/assets/20380094/c048abfc-ace3-4f35-8259-348f865826c2) ### Expected behavior The source should point to the online web URL rather than the temp file in the system.
PDFLoader metadata.source points to temp file path rather than pdf url
https://api.github.com/repos/langchain-ai/langchain/issues/8222/comments
8
2023-07-25T09:47:49Z
2023-11-26T16:07:44Z
https://github.com/langchain-ai/langchain/issues/8222
1,819,944,603
8,222
[ "hwchase17", "langchain" ]
### System Info Versions: ```text langchain==0.0.240 google-cloud-discoveryengine==0.9.1 google-cloud-aiplatform==1.28.1 ``` `GoogleCloudEnterpriseSearchRetriever` it consistently returns zero results without error. Workarounds / Validations attempted: * If I put invalid values (e.g. an invalid engine) it causes an error * Searching with these terms from the console works as expected * Using `discoveryengine_v1beta.SearchServiceClient()` directly works as expected and provides results ### Who can help? _No response_ ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Given the following code: ```python retriever = GoogleCloudEnterpriseSearchRetriever( project_id=my-project-id, search_engine_id=my-engine, max_documents=3, ) query = "Where I can fly to Spain?" result = retriever.get_relevant_documents(query) print(result) ``` This will always print `[]` no matter how I tweak the search query etc. ### Expected behavior Would expect at least one search result and the `result` dictionary not to be empty.
GoogleCloudEnterpriseSearchRetriever consistently returns no results
https://api.github.com/repos/langchain-ai/langchain/issues/8219/comments
10
2023-07-25T09:02:39Z
2023-12-21T16:07:25Z
https://github.com/langchain-ai/langchain/issues/8219
1,819,868,243
8,219
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. The refactoring changes in this [PR](https://github.com/langchain-ai/langchain/pull/7959) which changed the path of files from `langchain/*` to `libs/langchain/langchain/*`. But, the corresponding import statements are not refactored which is causing the tests to fail during local development. Also, in that PR they added a new [GitHub workflow](https://github.com/langchain-ai/langchain/blob/master/.github/workflows/langchain_ci.yml) which sets the working directory path to `libs/langchian` to run the unit tests in that path as part of CI. But, wondering how do we run them on the local machine. Also, the CI doesn't cover the integration tests, so how do we validate them after adding new tests. ### Suggestion: Please provide if there is any alternative way to run them and also update the corresponding documentation. Thanks! @hwchase17 @baskaryan
Issue: Refactoring Changes Breaking the Tests
https://api.github.com/repos/langchain-ai/langchain/issues/8217/comments
1
2023-07-25T05:04:59Z
2023-07-26T17:07:07Z
https://github.com/langchain-ai/langchain/issues/8217
1,819,559,886
8,217
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. With GoogleSerperAPIWrapper(type="news"), how do I config to get the result in the past 24 hours? ### Suggestion: _No response_
Issue: How do I search for the result in the past 24 hours with GoogleSerperAPIWrapper
https://api.github.com/repos/langchain-ai/langchain/issues/8216/comments
5
2023-07-25T04:23:46Z
2023-12-19T12:18:27Z
https://github.com/langchain-ai/langchain/issues/8216
1,819,526,632
8,216
[ "hwchase17", "langchain" ]
### System Info pymilvus: 2.2.0 langchain: 0.0.219 python: 3.10 openai: 0.27.6 ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Step: 1. Initialize a vectorstore: ` vectorstore = Milvus( embeddings, collection_name="portal_feature", connection_args={ "host": config.milvus_host, "port": config.milvus_port } ) ` 2. Add documents with the ids: [1,2,3,4,5] 3. Delete the document with the id: [2] `vectorstore.delete([2])` Response: Error: NotImplementedError: delete_by_id method must be implemented by subclass ### Expected behavior I want to delete the document and let's explain to me Why the error appreared
Unable to delete an entity by ID when utilizing 'vectorstore.delete(ids)' through 'langchain.vectorstor.milvus'.
https://api.github.com/repos/langchain-ai/langchain/issues/8215/comments
3
2023-07-25T04:12:18Z
2023-11-01T02:11:05Z
https://github.com/langchain-ai/langchain/issues/8215
1,819,518,167
8,215
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. When using document search from the existing Pinecone index that was created using Cosine **Similarity** in the `ConversationalRetrievalChain`, the `score_theshold` would eliminate most relevant documents instead of least relevant ones because the _similarity_ metric will be converted to _distance_. In [_select_relevance_score_fn](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/pinecone.py#L172) it calls the [_cosine_relevance_score_fn](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/base.py#L169) - which converts the similarity returned from Pinecone search to distance. Then, [filtering the documents](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/base.py#L266) based on the `score_threshold` eliminates the most relevant documents instead of least relevant ones. ### Suggestion: Pinecone subclass should override the `_cosine_relevance_score_fn` to preserve the similarity, since it is what originally comes back from the Pinecone similarity search.
Issue: Pinecone retriever with Cosine Similarity is treated like Cosine Distance
https://api.github.com/repos/langchain-ai/langchain/issues/8207/comments
2
2023-07-24T22:23:33Z
2023-11-13T19:47:39Z
https://github.com/langchain-ai/langchain/issues/8207
1,819,234,460
8,207
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. ``` dosearch = Pinecone.from_texts([t.page_content for t in split_docs], embeddings, index_name=index_name) ``` when I upsert the documents to Pinecone, If I want to get all the ids from `dosearch`, how I can do? ### Suggestion: _No response_
Issue: how to get infomation when using Pinecone.from_texts
https://api.github.com/repos/langchain-ai/langchain/issues/8204/comments
1
2023-07-24T21:55:41Z
2023-07-25T00:06:56Z
https://github.com/langchain-ai/langchain/issues/8204
1,819,203,715
8,204
[ "hwchase17", "langchain" ]
### Issue with current documentation: The Apify integration has been delete by @hwchase17 in commit aa0e69bc98fa9c77b01e5104f12b2b779f64fd33 and thus this documentation is not valid anymore: https://python.langchain.com/docs/integrations/tools/apify ### Idea or request for content: It would be highly beneficial to have information on a suitable replacement for the Apify integration.
DOC: Apify integration missing
https://api.github.com/repos/langchain-ai/langchain/issues/8201/comments
3
2023-07-24T19:46:13Z
2023-12-08T16:06:00Z
https://github.com/langchain-ai/langchain/issues/8201
1,819,030,275
8,201
[ "hwchase17", "langchain" ]
### Feature request Add support llama-cpp verbose argument ### Motivation missing ### Your contribution Just add it in the init(): .......... streaming: bool = True """Whether to stream the results, token by token.""" verbose: bool = True @root_validator() def validate_environment(cls, values: Dict) -> Dict: """Validate that llama-cpp-python library is installed.""" model_path = values["model_path"] model_param_names = [ "lora_path", "lora_base", "n_ctx", "n_parts", "seed", "f16_kv", "logits_all", "vocab_only", "use_mlock", "n_threads", "n_batch", "use_mmap", "last_n_tokens_size", "verbose" ] model_params = {k: values[k] for k in model_param_names} .....
Does not support llama-cpp verbose argument
https://api.github.com/repos/langchain-ai/langchain/issues/8200/comments
2
2023-07-24T19:33:03Z
2023-10-30T16:04:43Z
https://github.com/langchain-ai/langchain/issues/8200
1,819,010,028
8,200
[ "hwchase17", "langchain" ]
### Feature request Hybrid search for Supabase in the python version of Langchain would be much appreciated: [Supabase Hybrid Search](https://js.langchain.com/docs/modules/data_connection/retrievers/integrations/supabase-hybrid/) [langchain/src/retrievers/supabase.ts](https://github.com/hwchase17/langchainjs/blob/main/langchain/src/retrievers/supabase.ts) ### Motivation Better retrieval performance ### Your contribution I've done some work using [langchain.schema.retriever.BaseRetriever](https://api.python.langchain.com/en/latest/schema/langchain.schema.retriever.BaseRetriever.html#langchain.schema.retriever.BaseRetriever) as a template, but it's not working and I'm not sure i'll have time to figure it out: ``` from pydantic import BaseModel, Field from supabase.client import Client, create_client from langchain.embeddings.base import Embeddings from langchain.docstore.document import Document from langchain.schema.retriever import BaseRetriever from langchain.callbacks.manager import Callbacks, CallbackManagerForRetrieverRun from pydantic import BaseModel, Field, validator from dataclasses import dataclass from typing import List, Dict, Optional, Any import asyncio class SearchEmbeddingsParams: def __init__(self, query_embedding, match_count): self.query_embedding = query_embedding self.match_count = match_count class SearchKeywordParams: def __init__(self, query_text, match_count): self.query_text = query_text self.match_count = match_count class SearchResponseRow: def __init__(self, id, content, metadata, similarity): self.id = id self.content = content self.metadata = metadata self.similarity = similarity class SearchResult: def __init__(self, document, number1, number2): self.document = document self.number1 = number1 self.number2 = number2 class SupabaseHybridSearch(BaseRetriever, BaseModel): embeddings: Any client: Client table_name: str = "documents" similarity_query_name: str = "match_documents" keyword_query_name: str = "kw_match_documents" similarity_k: int = 2 keyword_k: int = 2 class Config: arbitrary_types_allowed = True async def similarity_search(self, query, k, _callbacks=None): # embedded_query = await self.embeddings.embed_query(query) embedded_query = self.embeddings.embed_query(query) match_documents_params = SearchEmbeddingsParams(embedded_query, k) res = self.client.rpc(self.similarity_query_name, match_documents_params.__dict__).execute() searches, error = self.client.rpc(self.similarity_query_name, match_documents_params) if error: raise Exception(f"Error searching for documents: {error.code} {error.message} {error.details}") return [SearchResult(Document(metadata=resp.metadata, pageContent=resp.content), resp.similarity, resp.id) for resp in searches] async def keyword_search(self, query, k): kw_match_documents_params = SearchKeywordParams(query, k) searches, error = await self.client.rpc(self.keyword_query_name, kw_match_documents_params) if error: raise Exception(f"Error searching for documents: {error.code} {error.message} {error.details}") return [SearchResult(Document(metadata=resp.metadata, pageContent=resp.content), resp.similarity * 10, resp.id) for resp in searches] async def hybrid_search(self, query, similarity_k, keyword_k, callbacks=None): similarity_search = self.similarity_search(query, similarity_k, callbacks) similarity_search = self.similarity_search(query, similarity_k, callbacks) keyword_search = self.keyword_search(query, keyword_k) results = [result for sublist in await asyncio.gather(similarity_search, keyword_search) for result in sublist] picks = {} for result in results: id, nextScore = result.number2, result.number1 prevScore = picks.get(id) if prevScore is None or nextScore > prevScore: picks[id] = result return sorted(picks.values(), key=lambda result: result.number1, reverse=True) def _get_relevant_documents(self, query: str) -> List[Document]: raise NotImplementedError async def _aget_relevant_documents(self, query: str) -> List[Document]: searchResults = await self.hybrid_search(query, self.similarity_k, self.keyword_k, None) return [result.document for result in searchResults] ```
SupabaseHybridSearch as in langchainjs
https://api.github.com/repos/langchain-ai/langchain/issues/8194/comments
2
2023-07-24T18:44:22Z
2024-04-10T16:18:48Z
https://github.com/langchain-ai/langchain/issues/8194
1,818,945,223
8,194
[ "hwchase17", "langchain" ]
### System Info I am getting an error on FAISS.from_documents(). "openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'>" I tried everything and did they change something recently? This code worked fine and now it doesn't not sure what has changed. I used Chroma.from_documents as well and I still get the same error. ``` openai.api_type = "azure" openai.api_version = os.environ["OPENAI_API_VERSION"] openai.api_base = os.environ["OPENAI_API_BASE"] openai.api_key = os.environ["OPENAI_API_KEY"] bot.gpt_turbo = Model_LLM(OPENAI_DEPLOYMENT_NAME).model embeddings = OpenAIEmbeddings(model=OPENAI_EMBEDDING_MODEL_NAME) fileLoaded = FileLoader("Data/filename.pdf", TokenTextSplitter(chunk_size=1000, chunk_overlap=1)) text = fileLoaded.load_file() #vectorStore = Chroma.from_documents(text,embedding=embeddings) vectorStore = FAISS.from_documents(text,embedding=embeddings) qa = RetrievalEngine(llm=bot.gpt_turbo, retriever=vectorStore.as_retriever(),chain_type="stuff") #query = "Please give me the list of sampleID" while True: askQuestion = input("Ask me a question about the file?: ") print(qa.initialize_qa_engine().run(askQuestion)) #Class Code import os from langchain.chains import RetrievalQA, ConversationalRetrievalChain from langchain.chat_models import AzureChatOpenAI from langchain.document_loaders import Docx2txtLoader, PyPDFLoader, CSVLoader, UnstructuredFileLoader class Model_LLM: def __init__(self, deployment_name): self.model = AzureChatOpenAI(deployment_name=deployment_name) class FileLoader: def __init__(self, file, text_splitter): self.file = file self.text_splitter = text_splitter self._ext = os.path.splitext(self.file)[-1].lower() def load_file(self): if self._ext in ['.docx', '.doc']: return self._call_file_loader(Docx2txtLoader) elif self._ext == '.pdf': return self._call_file_loader(PyPDFLoader) elif self._ext in ['.csv']: return self._call_file_loader(CSVLoader) #elif self._ext in ['.json']: #return self._call_file_loader(JSONLoader) elif self._ext in ['.txt', '.json']: return self._call_file_loader(UnstructuredFileLoader) else: return [] def _call_file_loader(self, loader_class): loader = loader_class(self.file) _text = loader.load_and_split(text_splitter=self.text_splitter) #documents = loader.load() #_text = self.text_splitter.split_documents(documents) return _text class RetrievalEngine: def __init__(self, llm, retriever, chain_type='stuff', max_tokens=500): self.llm = llm self.retriever = retriever self.chain_type = chain_type self.max_tokens = max_tokens def initialize_qa_engine(self): return RetrievalQA.from_chain_type(llm=self.llm, chain_type=self.chain_type, retriever=self.retriever, return_source_documents=False) def initialize_chat_engine(self): return ConversationalRetrievalChain.from_llm(self.llm, retriever=self.retriever, max_tokens_limit=self.max_tokens) ``` ### Who can help? _No response_ ### Information - [ ] The official example notebooks/scripts - [ ] My own modified scripts ### Related Components - [X] LLMs/Chat Models - [X] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [ ] Output Parsers - [X] Document Loaders - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ``` Traceback (most recent call last): File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\main.py", line 13, in <module> vectorstore = Chroma.from_documents(documents=text,embedding=OpenAIEmbeddings()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\vectorstores\chroma.py", line 578, in from_documents return cls.from_texts( ^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\vectorstores\chroma.py", line 542, in from_texts chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids) File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\vectorstores\chroma.py", line 175, in add_texts embeddings = self._embedding_function.embed_documents(list(texts)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\embeddings\openai.py", line 508, in embed_documents return self._get_len_safe_embeddings(texts, engine=self.deployment) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\embeddings\openai.py", line 358, in _get_len_safe_embeddings response = embed_with_retry( ^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\embeddings\openai.py", line 107, in embed_with_retry return _embed_with_retry(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\tenacity\__init__.py", line 289, in wrapped_f return self(f, *args, **kw) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\tenacity\__init__.py", line 379, in __call__ do = self.iter(retry_state=retry_state) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\tenacity\__init__.py", line 314, in iter return fut.result() ^^^^^^^^^^^^ File "C:\Users\spate246\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\_base.py", line 449, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result raise self._exception File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\tenacity\__init__.py", line 382, in __call__ result = fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\langchain\embeddings\openai.py", line 104, in _embed_with_retry response = embeddings.client.create(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\openai\api_resources\embedding.py", line 33, in create response = super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 149, in create ) = cls.__prepare_create_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\spate246\source\repos\Assay-Development\Azure_OpenAI\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 83, in __prepare_create_request raise error.InvalidRequestError( openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'> ``` ### Expected behavior I would expect it not have this issue because it has worked before. It would run the while loop and the user can ask the questions.
Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'>
https://api.github.com/repos/langchain-ai/langchain/issues/8190/comments
7
2023-07-24T17:47:03Z
2023-12-08T16:10:32Z
https://github.com/langchain-ai/langchain/issues/8190
1,818,861,918
8,190
[ "hwchase17", "langchain" ]
### System Info langchain == 0.0.240 Python 3.10.9 ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction from langchain.chains import RetrievalQA from langchain.indexes import VectorstoreIndexCreator from langchain.text_splitter import CharacterTextSplitter from langchain.embeddings import OpenAIEmbeddings from langchain.llms import OpenAI from langchain.document_loaders import PyPDFLoader import os from langchain.vectorstores.redis import Redis loader = PyPDFLoader("test.pdf") documents = loader.load() text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) texts = text_splitter.split_documents(documents) embeddings = OpenAIEmbeddings( deployment="text-embedding-ada-002",model="text-embedding-ada-002",chunk_size=1) db = Redis.from_documents( texts, embeddings, redis_url="redis://localhost:6379", index_name="link" ) retriever = db.as_retriever(search_type="similarity", search_kwargs={"k":2}) qa = RetrievalQA.from_chain_type( llm=OpenAI(), chain_type="stuff", retriever=retriever, return_source_documents=True) query = "What is Compilance" result = qa({"query": query}) print(result) ### Expected behavior Getting the result of the query but having error at as_retriver() like AttributeError: 'Redis' object has no attribute '_Redis__get_retriever_tags'. Did you mean: '_VectorStore__get_retriever_tags'?
AttributeError: 'Redis' object has no attribute '_Redis__get_retriever_tags'. Did you mean: '_VectorStore__get_retriever_tags'?
https://api.github.com/repos/langchain-ai/langchain/issues/8185/comments
7
2023-07-24T16:43:01Z
2023-11-06T16:06:35Z
https://github.com/langchain-ai/langchain/issues/8185
1,818,775,624
8,185
[ "hwchase17", "langchain" ]
null
AttributeError: 'Redis' object has no attribute '_Redis__get_retriever_tags'. Did you mean: '_VectorStore__get_retriever_tags'?
https://api.github.com/repos/langchain-ai/langchain/issues/8184/comments
0
2023-07-24T15:55:00Z
2023-07-24T16:39:27Z
https://github.com/langchain-ai/langchain/issues/8184
1,818,702,146
8,184
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Hi there, I've been trying to come up with a system that can do the following: 1. take in a string as input (much longer len than the 512 token limit of the flan-t5-large model I'm using) 2. Use vector db (currently using FAISS) + langchain to index and query for relevant chunks 3. Use a model I've deployed at a HF endpoint to get inference for a question I have relating to the data I've been able to achieve this just fine using the Huggingfacehub() class to create the LLM for the chain, but this uses the HF free inference endpoint, which of course has rate limits and is slow, which is why I'd like to use my own endpoint. I have not been able to find a way to use my endpoint in place of the free endpoint, and I've looked everywhere. I'm hoping it's something simple I've overlooked but any help would be greatly appreciated. It would amazing I could see a specific Python example. Thanks in advance. ### Suggestion: _No response_
Issue: Using HuggingFace Inference Endpoint as LLM in QA Chain
https://api.github.com/repos/langchain-ai/langchain/issues/8181/comments
4
2023-07-24T14:21:40Z
2023-10-31T16:05:25Z
https://github.com/langchain-ai/langchain/issues/8181
1,818,532,496
8,181
[ "hwchase17", "langchain" ]
### Issue with current documentation: Hi, The integration document for langchain with AWS sagemaker has been removed. Do we have an updated doc for that. [https://python.langchain.com/docs/modules/model_io/models/llms/integrations/sagemaker.html](url) ### Idea or request for content: _No response_
DOC: Langchain integration with sagemaker missing
https://api.github.com/repos/langchain-ai/langchain/issues/8178/comments
2
2023-07-24T12:20:04Z
2023-07-25T01:55:26Z
https://github.com/langchain-ai/langchain/issues/8178
1,818,312,666
8,178
[ "hwchase17", "langchain" ]
### System Info python = 3.10 langchain = 0.0.222 ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Not sure how to give you all the steps but here attached a screenshot of the debugger run at line `vectorstores.redis` 338 and as you can see it goes from the lowest to the highest. You can see the `vector_score` on the right <img width="1030" alt="Screenshot 2023-07-24 at 13 40 28" src="https://github.com/langchain-ai/langchain/assets/15908060/d9e5002e-8f31-4c68-acaf-f3e05ea1db63"> ### Expected behavior I think it should return from highest to lowest
Redis scores seems to be sorted from lowest to highest (with cosine)
https://api.github.com/repos/langchain-ai/langchain/issues/8177/comments
7
2023-07-24T11:40:47Z
2023-12-19T09:02:13Z
https://github.com/langchain-ai/langchain/issues/8177
1,818,244,391
8,177
[ "hwchase17", "langchain" ]
### Feature request Provide a way to use instructor-based embeddings with dynamic instructions. ### Motivation Currently HuggingFaceInstructEmbeddings initialized with instruction. This create problems with using multiple instructions, because this basically force you to initialize different instance for each instruction you need. This is not a limitation of a model, you don't need to load it with different instructions every time. ### Your contribution I can make a PR with another method, something like `embed_instruction_pairs`, which would take an list of [instruction, query] values, but want to discuss it first.
Dynamic instruction for instructor embeddings
https://api.github.com/repos/langchain-ai/langchain/issues/8176/comments
1
2023-07-24T11:30:33Z
2023-10-30T16:04:53Z
https://github.com/langchain-ai/langchain/issues/8176
1,818,227,516
8,176
[ "hwchase17", "langchain" ]
### System Info [Basic Langchain Q&A use case example](https://python.langchain.com/docs/use_cases/question_answering/) throws ValueError when `<html>` tag of website doesn't set `lang` attribute. In particular, `WebBaseLoader` parses the website soup metadata with: ``` def _build_metadata(soup: Any, url: str) -> dict: """Build metadata from BeautifulSoup output.""" metadata = {"source": url} if title := soup.find("title"): metadata["title"] = title.get_text() if description := soup.find("meta", attrs={"name": "description"}): metadata["description"] = description.get("content", None) if html := soup.find("html"): metadata["language"] = html.get("lang", None) return metadata ``` thus setting `metadata["language"] = None` if there's no `lang` attribute for the `html` tag. `chromadb` then validates the metadata with: ``` def validate_metadata(metadata: Metadata) -> Metadata: """Validates metadata to ensure it is a dictionary of strings to strings, ints, or floats""" if not isinstance(metadata, dict) and metadata is not None: raise ValueError(f"Expected metadata to be a dict or None, got {metadata}") if metadata is None: return metadata if len(metadata) == 0: raise ValueError(f"Expected metadata to be a non-empty dict, got {metadata}") for key, value in metadata.items(): if not isinstance(key, str): raise ValueError( f"Expected metadata key to be a str, got {key} which is a {type(key)}" ) # isinstance(True, int) evaluates to True, so we need to check for bools separately if not isinstance(value, (str, int, float)) or isinstance(value, bool): raise ValueError( f"Expected metadata value to be a str, int, or float, got {value} which is a {type(value)}" ) return metadata ``` and thus raises a ValueError whenever `metadata is None`. The two obvious solutions: 1) Change the metadata parser to return strings in the event they don't find a metadata tag: ``` def _build_metadata(soup: Any, url: str) -> dict: """Build metadata from BeautifulSoup output.""" metadata = {"source": url} if title := soup.find("title"): metadata["title"] = title.get_text() if description := soup.find("meta", attrs={"name": "description"}): metadata["description"] = description.get("content", "No description found.") if html := soup.find("html"): metadata["language"] = html.get("lang", "No language found.") return metadata ``` 2) Change the metadata validator in `chromadb` to accept metadata objects with of type `None`. Option 2 likely involves a lot of knock-on changes to `chromadb` to handle None-type metadata, so I'd prefer option 1, but defer to the maintainers. Will put up a quick PR for option 1 below for reference. **Full Stack Trace:** ValueError Traceback (most recent call last) Cell In[6], line 1 ----> 1 print(query_site("What is this article about?", "https://www.montyevans.com/sports-betting")) Cell In[5], line 6, in query_site(question, site_url) 4 if site_url not in memo_dict: 5 loader = WebBaseLoader(site_url) ----> 6 index = VectorstoreIndexCreator().from_loaders([loader]) 7 memo_dict[site_url] = index 9 site_index = memo_dict[site_url] File [/Volumes/git/aipes/langchain/document_qa/langchain/langchain/indexes/vectorstore.py:73](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/document_qa/langchain/langchain/indexes/vectorstore.py:73), in VectorstoreIndexCreator.from_loaders(self, loaders) 71 for loader in loaders: 72 docs.extend(loader.load()) ---> 73 return self.from_documents(docs) File [/Volumes/git/aipes/langchain/document_qa/langchain/langchain/indexes/vectorstore.py:78](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/document_qa/langchain/langchain/indexes/vectorstore.py:78), in VectorstoreIndexCreator.from_documents(self, documents) 76 """Create a vectorstore index from documents.""" 77 sub_docs = self.text_splitter.split_documents(documents) ---> 78 vectorstore = self.vectorstore_cls.from_documents( 79 sub_docs, self.embedding, **self.vectorstore_kwargs 80 ) 81 return VectorStoreIndexWrapper(vectorstore=vectorstore) File [/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:578](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:578), in Chroma.from_documents(cls, documents, embedding, ids, collection_name, persist_directory, client_settings, client, collection_metadata, **kwargs) 576 texts = [doc.page_content for doc in documents] 577 metadatas = [doc.metadata for doc in documents] --> 578 return cls.from_texts( 579 texts=texts, 580 embedding=embedding, 581 metadatas=metadatas, 582 ids=ids, 583 collection_name=collection_name, 584 persist_directory=persist_directory, 585 client_settings=client_settings, 586 client=client, 587 collection_metadata=collection_metadata, 588 **kwargs, 589 ) File [/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:542](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:542), in Chroma.from_texts(cls, texts, embedding, metadatas, ids, collection_name, persist_directory, client_settings, client, collection_metadata, **kwargs) 514 """Create a Chroma vectorstore from a raw documents. 515 516 If a persist_directory is specified, the collection will be persisted there. (...) 531 Chroma: Chroma vectorstore. 532 """ 533 chroma_collection = cls( 534 collection_name=collection_name, 535 embedding_function=embedding, (...) 540 **kwargs, 541 ) --> 542 chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids) 543 return chroma_collection File [/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:193](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/document_qa/langchain/langchain/vectorstores/chroma.py:193), in Chroma.add_texts(self, texts, metadatas, ids, **kwargs) 189 embeddings_with_metadatas = ( 190 [embeddings[i] for i in non_empty] if embeddings else None 191 ) 192 ids_with_metadata = [ids[i] for i in non_empty] --> 193 self._collection.upsert( 194 metadatas=metadatas, 195 embeddings=embeddings_with_metadatas, 196 documents=texts_with_metadatas, 197 ids=ids_with_metadata, 198 ) 200 texts = [texts[j] for j in empty] 201 embeddings = [embeddings[j] for j in empty] if embeddings else None File [~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/models/Collection.py:298](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/models/Collection.py:298), in Collection.upsert(self, ids, embeddings, metadatas, documents, increment_index) 278 def upsert( 279 self, 280 ids: OneOrMany[ID], (...) 284 increment_index: bool = True, 285 ) -> None: 286 """Update the embeddings, metadatas or documents for provided ids, or create them if they don't exist. 287 288 Args: (...) 295 None 296 """ --> 298 ids, embeddings, metadatas, documents = self._validate_embedding_set( 299 ids, embeddings, metadatas, documents 300 ) 302 self._client._upsert( 303 collection_id=self.id, 304 ids=ids, (...) 308 increment_index=increment_index, 309 ) File [~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/models/Collection.py:357](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/models/Collection.py:357), in Collection._validate_embedding_set(self, ids, embeddings, metadatas, documents, require_embeddings_or_documents) 350 ids = validate_ids(maybe_cast_one_to_many(ids)) 351 embeddings = ( 352 validate_embeddings(maybe_cast_one_to_many(embeddings)) 353 if embeddings is not None 354 else None 355 ) 356 metadatas = ( --> 357 validate_metadatas(maybe_cast_one_to_many(metadatas)) 358 if metadatas is not None 359 else None 360 ) 361 documents = maybe_cast_one_to_many(documents) if documents is not None else None 363 # Check that one of embeddings or documents is provided File [~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/types.py:169](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/types.py:169), in validate_metadatas(metadatas) 167 raise ValueError(f"Expected metadatas to be a list, got {metadatas}") 168 for metadata in metadatas: --> 169 validate_metadata(metadata) 170 return metadatas File [~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/types.py:140](https://file+.vscode-resource.vscode-cdn.net/Volumes/git/aipes/langchain/~/mambaforge/envs/langchain/lib/python3.10/site-packages/chromadb/api/types.py:140), in validate_metadata(metadata) 138 # isinstance(True, int) evaluates to True, so we need to check for bools separately 139 if not isinstance(value, (str, int, float)) or isinstance(value, bool): --> 140 raise ValueError( 141 f"Expected metadata value to be a str, int, or float, got {value} which is a {type(value)}" 142 ) 143 return metadata ### Who can help? @hwchase17 @eyurtsev ### 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 - [X] Document Loaders - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ``` from langchain.document_loaders import WebBaseLoader from langchain.indexes import VectorstoreIndexCreator memo_dict = {} def query_site(question, site_url): if site_url not in memo_dict: loader = WebBaseLoader(site_url) index = VectorstoreIndexCreator().from_loaders([loader]) memo_dict[site_url] = index site_index = memo_dict[site_url] return site_index.query(question) print(query_site("What is this article about?", "https://www.montyevans.com/sports-betting")) ``` ### Expected behavior I expect to see an answer to the question, based on the site content, printed to console; instead ChromaDB raises a ValueError.
Basic Langchain Q&A use case example throws ValueError when `<html>` tag of website doesn't set `lang` attribute.
https://api.github.com/repos/langchain-ai/langchain/issues/8174/comments
2
2023-07-24T11:16:52Z
2023-07-25T11:09:57Z
https://github.com/langchain-ai/langchain/issues/8174
1,818,206,096
8,174
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I am using FAISS vector store for storing the vector embeddings of the documents and retrieving the relevant document with respect to the query. My question is that `FAISS` does not store the embeddings permanently, instead it stores it in RAM and when running the code once again, it simply overwrites on the previous one or simply adds another index for it (I am not sure on this one). What I want is that to store these embeddings, say on `MongoDB` so that it gets stored there for longer period of time and when extracting those embeddings, `FAISS` is the algorithm to be used for similarity search based extraction (as it is best for large documents). Is it possible? ### Suggestion: I tried `MongoDBAtlasVectorSearch` for this and came to know that it does store the vector embeddings in MongoDB database but when extracting the relevant document with respect to a query it does not use `FAISS` based similarity search algorithm (which is, I believe, better than the one used by `MongoDBAtlasVectorSearch`).
How to use MongoDB to store vector embeddings and during extracting the relevant document, using `FAISS` for similarity search based document relevancy?
https://api.github.com/repos/langchain-ai/langchain/issues/8170/comments
11
2023-07-24T08:50:57Z
2024-02-29T10:28:34Z
https://github.com/langchain-ai/langchain/issues/8170
1,817,948,424
8,170
[ "hwchase17", "langchain" ]
### System Info 1. Python 3.10 2. Langchain 0.0.240 3. Mac OSX Monterey Intel Processor ### Who can help? @hwchase17 @ago ### Information - [ ] The official example notebooks/scripts - [X] My own modified scripts ### Related Components - [X] LLMs/Chat Models - [ ] Embedding Models - [X] 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 Hey so I've been trying to use `CombinedMemory` to combine the `VectorStoreRetrieverMemory` and `ConversationSummaryBufferMemory` and set it as the memory of a `ConversationalRetrievalChain`, but I keep running into issues and could not find any examples of this in the documentation. is there an example that could be provided by the documentation
Cannot use CombinedMemory with VectorStoreRetrieverMemory and ConversationBufferMemory for ConversationalRetrievalChain
https://api.github.com/repos/langchain-ai/langchain/issues/8168/comments
0
2023-07-24T08:00:27Z
2023-07-24T10:24:13Z
https://github.com/langchain-ai/langchain/issues/8168
1,817,863,224
8,168
[ "hwchase17", "langchain" ]
### Feature request There might be scenarios where transformations and joins will need to be applied on tables from different schemas but currently, the code only supports a single schema query structure. ### Motivation I am working on Databricks Unity Catalog Query Assistant feature for a Product and need this change for the same, there are business scenarios where multiple schemas will need to be accessed to make complicated business rules to be applied. ### Your contribution I can make the PR for this change, I have identified the code changes required
Supporting Multiple Schemas for SQL Query Generation in Databricks
https://api.github.com/repos/langchain-ai/langchain/issues/8167/comments
2
2023-07-24T07:42:28Z
2023-11-04T16:05:01Z
https://github.com/langchain-ai/langchain/issues/8167
1,817,835,890
8,167
[ "hwchase17", "langchain" ]
### Feature request Hi langchain team! I'd like to contribute this feature to the langchain document loaders. There are multiple pros for using Adobe API instead of the existing libraries for converting pdf to text and other metadata; e.g, adobe API allows for extraction of tables and figures in pdf documents as separate .csv and .png files, respectively. These are of course in addition to raw text extraction which in my opinion works better most of the time compared to other libraries. Here are a few links to examples and source code: [Adobe python API example](https://developer.adobe.com/document-services/docs/overview/pdf-extract-api/quickstarts/python/) [Adobe SDK](https://github.com/adobe/pdfservices-python-sdk-samples/tree/main/src/extractpdf) ### Motivation I needed to extract the tables in pdf files in a standard format to extract the data in them more carefully. I was also not satisfied by the existing libraries performance on raw text extraction. ### Your contribution I'd like to contribute this feature as a new document loader in langchain. Let me know if I can start working on it. Thanks!
Adding Adobe PDF extraction API as an additional langchain document loader
https://api.github.com/repos/langchain-ai/langchain/issues/8163/comments
4
2023-07-24T05:21:58Z
2024-02-04T17:54:13Z
https://github.com/langchain-ai/langchain/issues/8163
1,817,645,290
8,163
[ "hwchase17", "langchain" ]
### Feature request support for llama models for petals module ### Motivation i'm furstated when i want to use petals (distributed model) for llama2, my gpu is not enough to run all models ### Your contribution -
langchain.llms.Petals doesnt support llama models
https://api.github.com/repos/langchain-ai/langchain/issues/8161/comments
2
2023-07-24T04:56:39Z
2023-11-04T16:05:05Z
https://github.com/langchain-ai/langchain/issues/8161
1,817,621,937
8,161
[ "hwchase17", "langchain" ]
### System Info python = ">=3.9,<3.12" fire = "0.5.0" pandas = "2.0.2" sqlalchemy = "2.0.15" rich = "13.4.1" mysqlclient = "2.1.1" pandera = "0.15.1" openai = "0.27.7" guidance = "0.0.62" langchain = "0.0.221" textual = "^0.29.0" ### Who can help? @hwchase17 @agola11 ### 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 1. Prepare data. In our case, there are 3576 documents. 2. Migrate API before migration: ```python embeddings = OpenAIEmbeddings( model="text-embedding-ada-002", deployment=<MY_DEPLOYMENT_NAME>, chunk_size=1, openai_api_base=os.environ["OPENAI_API_BASE"], openai_api_key=os.environ["OPENAI_API_KEY"], openai_api_type="azure", ) ``` after migration: ```python embeddings = OpenAIEmbeddings( model="text-embedding-ada-002", openai_api_key=os.environ["OPENAI_API_KEY"], openai_api_type="openai", ) ``` 3. Make FAISS DB The code are the same as that of before-migration version. db = FAISS.from_documents(docs, embeddings) 4. Error occurs ``` Traceback (most recent call last): File "/path/make_dataframe.py", line 54, in <module> db = FAISS.from_documents(docs, embeddings) File "/path/.venv/lib/python3.9/site-packages/langchain/vectorstores/base.py", line 337, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) File "/path/.venv/lib/python3.9/site-packages/langchain/vectorstores/faiss.py", line 554, in from_texts return cls.__from( File "/path/.venv/lib/python3.9/site-packages/langchain/vectorstores/faiss.py", line 506, in __from vector = np.array(embeddings, dtype=np.float32) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3576,) + inhomogeneous part. ``` ### Expected behavior Correctly construct FAISS DB without error.
Migration OpenAIEmbedding from Azure to OpenAI reproduce gives an error message "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions."
https://api.github.com/repos/langchain-ai/langchain/issues/8159/comments
2
2023-07-24T03:58:46Z
2023-11-03T16:06:27Z
https://github.com/langchain-ai/langchain/issues/8159
1,817,560,003
8,159
[ "hwchase17", "langchain" ]
### System Info from langchain.agents.chat.output_parser import ChatOutputParser Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/__init__.py", line 6, in <module> from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/__init__.py", line 10, in <module> from langchain.agents.agent_toolkits import ( File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/agent_toolkits/__init__.py", line 6, in <module> from langchain.agents.agent_toolkits.csv.base import create_csv_agent File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/agent_toolkits/csv/base.py", line 4, in <module> from langchain.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/agent_toolkits/pandas/base.py", line 18, in <module> from langchain.agents.types import AgentType File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/types.py", line 5, in <module> from langchain.agents.chat.base import ChatAgent File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/chat/base.py", line 6, in <module> from langchain.agents.chat.output_parser import ChatOutputParser File "/home/ubuntu/chatpdf/Backend/backenv/lib/python3.10/site-packages/langchain/agents/chat/output_parser.py", line 12, in <module> class ChatOutputParser(AgentOutputParser): File "pydantic/main.py", line 229, in pydantic.main.ModelMetaclass.__new__ File "pydantic/fields.py", line 491, in pydantic.fields.ModelField.infer File "pydantic/fields.py", line 421, in pydantic.fields.ModelField.__init__ File "pydantic/fields.py", line 542, in pydantic.fields.ModelField.prepare File "pydantic/fields.py", line 804, in pydantic.fields.ModelField.populate_validators File "pydantic/validators.py", line 723, in find_validators RuntimeError: no validator found for <class 're.Pattern'>, see `arbitrary_types_allowed` in Config ### Who can help? _No response_ ### Information - [X] The official example notebooks/scripts - [ ] My own modified scripts ### Related Components - [ ] LLMs/Chat Models - [ ] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [X] Output Parsers - [ ] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction from langchain.agents.chat.output_parser import ChatOutputParser ### Expected behavior Import corrrectly.
Error when importing ChatOutputParser: no validator found for <class 're.Pattern'>
https://api.github.com/repos/langchain-ai/langchain/issues/8158/comments
9
2023-07-24T02:00:27Z
2024-02-14T16:12:38Z
https://github.com/langchain-ai/langchain/issues/8158
1,817,456,702
8,158
[ "hwchase17", "langchain" ]
### System Info Hi, I'm using version 0.0.105 of langchain (nodejs). I'm using PDFLoader to embed PDF documents, and I've noticed that the extracted documents do not retain the hyperlinks that were present in the files. Is there a way to retain them? I couldn't find it in the document or the PDFLoader class. ### Who can help? @eyurtsev @hwchase17 @agola11 ### Information - [ ] The official example notebooks/scripts - [ ] My own modified scripts ### Related Components - [ ] LLMs/Chat Models - [ ] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [ ] Output Parsers - [X] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction var pdfLoader = new PDFLoader(filePath, { splitPages: false, }); var rawDocs = await pdfLoader.load(); console.log(rawDocs); ### Expected behavior I was expecting PDFLoader to convert the hyperlinks in the PDF to either raw URLs or markdown URL.
Retain links when extracting text using PDFLoader
https://api.github.com/repos/langchain-ai/langchain/issues/8157/comments
3
2023-07-24T01:53:00Z
2023-07-25T02:05:02Z
https://github.com/langchain-ai/langchain/issues/8157
1,817,450,573
8,157
[ "hwchase17", "langchain" ]
### System Info Good day, I'm attempting to use `create_tagging_chain_pydantic` to tag certain markets wherein a product is used. The product can be used across multiple markets. Unfortunately the chain doesn't appear to respect the `enum` values passed to it for a return type of an array of string (it works correctly for a [single] string output). ```python class Tags(BaseModel): market_verticals: List[str] = Field(..., enum=["pharmaceutical", "biotech", "food and beverage", "cosmetic", "industrial", "nutraceuticals", "agriculture", "other"], description="""describes which of the market verticals of the various uses of the product """) def main(): llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613") chain = create_tagging_chain_pydantic(Tags, llm) market_verticals = chain.run( "The product is used in the production of food additives, pharmaceuticals, and cosmetics") ``` Output: ```bash market_verticals=['food additives', 'pharmaceuticals', 'cosmetics'] ``` Amending the prompt, produces the expected output: ```python class Tags(BaseModel): market_verticals: List[str] = Field(..., enum=["pharmaceutical", "biotech", "food and beverage", "cosmetic", "industrial", "nutraceuticals", "agriculture", "other"], description="""describes which of the market verticals of the various uses of the product. Market verticals are: pharmaceutical, biotech, food and beverage, cosmetic, industrial, nutraceuticals, agriculture and other. """) ``` Output: ```bash market_verticals=['food and beverage', 'pharmaceutical', 'cosmetic'] ``` ```bash $ python3 -V Python 3.10.10 $ pip show langchain Name: langchain Version: 0.0.240 Summary: Building applications with LLMs through composability Home-page: https://www.github.com/hwchase17/langchain Author: Author-email: License: MIT Location: /home/tim/Documents/git/ai-magellan/.venv/lib/python3.10/site-packages Requires: aiohttp, async-timeout, dataclasses-json, langsmith, numexpr, numpy, openapi-schema-pydantic, pydantic, PyYAML, requests, SQLAlchemy, tenacity Required-by: kor ``` ### Who can help? _No response_ ### 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 - [ ] Tools / Toolkits - [X] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Write and run the code below: ``` from typing import List from dotenv import load_dotenv from langchain.chat_models import ChatOpenAI from langchain.chains import create_tagging_chain, create_tagging_chain_pydantic from langchain.prompts import ChatPromptTemplate from enum import Enum from pydantic import BaseModel, Field class Tags(BaseModel): # enum doesn't work with array market_verticals: List[str] = Field(..., items={"type": "string"}, enum=["pharmaceutical", "biotech", "food and beverage", "cosmetic", "industrial", "nutraceuticals", "agriculture", "other"], description="""describes which of the market verticals of the various uses of the product """) def main(): llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613", verbose=True) chain = create_tagging_chain_pydantic(Tags, llm, verbose=True) market_verticals = chain.run( "Vitamin B is is used in the production of food additives, pharmaceuticals, and cosmetics") print(market_verticals) if __name__ == "__main__": load_dotenv() main() ``` ### Expected behavior Expected output: ```bash market_verticals=['food and beverage', 'pharmaceuticals', 'cosmetics'] ```
create_tagging_chain returning an array string not respecting enum values
https://api.github.com/repos/langchain-ai/langchain/issues/8156/comments
2
2023-07-24T01:43:31Z
2023-12-18T23:48:57Z
https://github.com/langchain-ai/langchain/issues/8156
1,817,442,875
8,156
[ "hwchase17", "langchain" ]
### Feature request When I testing MultiRetrievalQAChain in synchronous mode, it worked perfectly. It can choose QA from the right retriever. But when I implement MultiRetrievalQAChain into production with streaming, I need mode async. anyone can help me ? TIA ### Motivation I'm quite frustated when I found MultiRetrievalQAChain not yet support mode async. Because the launch time for the product is halted. ### Your contribution yes, I'd love to help testing the new features from langchain.
MultiRetrievalQAChain async mode
https://api.github.com/repos/langchain-ai/langchain/issues/8149/comments
1
2023-07-23T14:24:48Z
2023-10-29T16:04:26Z
https://github.com/langchain-ai/langchain/issues/8149
1,817,148,325
8,149
[ "hwchase17", "langchain" ]
### Feature request Would like to have YoutubeLoader on Nodejs api https://api.python.langchain.com/en/latest/document_loaders/langchain.document_loaders.youtube.YoutubeLoader.html#langchain.document_loaders.youtube.YoutubeLoader ### Motivation The motivation of this is to have the feature to load the transcript of youtube video and summarize it ### Your contribution no
YoutubeLoader for nodejs
https://api.github.com/repos/langchain-ai/langchain/issues/8148/comments
2
2023-07-23T13:09:56Z
2023-11-01T16:06:00Z
https://github.com/langchain-ai/langchain/issues/8148
1,817,123,966
8,148
[ "hwchase17", "langchain" ]
### System Info langchain 0.0.240 ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction 1. Run the following code below: ```python text = """14、中国证券报:今年以来,多个 数字人 民币试点地区开展了丰富多彩的数字人民币促消费活动,活跃消费市场,提振消费需求。不少地方政府向民众发放了数字人民币消费券,拉动居民消费,据记者粗略统计,活动金额超过1.8亿元。业内专家认为,数字人民币与消费券、电商平台等场景结合,可共同促进消费市场加快回暖。&nbsp;15、猫眼专业版:电影《流浪地球2》上映15天,总票房已经破33亿。从综合票房看,《流浪地球2》再次登顶单日票房榜。2月5日单日实时票房超1.3亿元,领先第二名《满江红》近2000万,锁定单日票房冠军。目前,《流浪地球2》的票房占比34.5%,排片场次92126次。&nbsp;二、市场回顾【国内股市】&nbsp;1、2月6日,沪深两市三大指数弱势震荡,沪指跌0.76%, 深证成指 跌1.18%, 创业板 指跌1.4%。盘面上看, ChatGPT概念 持续火爆, 海天瑞声 、 云从科技 涨停6个交易日翻倍; 数字经济 概念盘中发酵, 铜牛信息 涨停;信创、软件股逆市走强, 青 云科技 涨停;八部门适度超前建设充换电基础设施, 充电桩 概念活跃。 白酒 、CRO、新冠 疫苗 、 券商 、 黄金 有色、 保险 、 磷化工 等板块跌幅居前。&nbsp;2、港股低开低走,截至收盘, 恒生指数 跌2.02%,报21222.16点; 国企指数 跌2.68%, 红筹指数 跌1.37%。 恒生科技指数 跌3.65%,万国数据跌8.65%,哔哩哔哩跌5.38%,快手跌5.05%。 黄金股 集体走低, 山东黄金 跌6.01%, 紫金矿业 跌超5%, 招金矿业 跌4.56%。汽车股下跌, 长城汽车 跌超6%,蔚来跌超5%, 零跑汽车 跌4.80%。&nbsp;3、年2月6日, 大智慧 数据中心显示,龙虎榜中营业部净卖出3616.66万元。其中,净买入的个股24只,营业部净买入较多个股分别是 润和软件 、 信达证券 、 川大智胜 等,净买入金额占当日成交额比例达2.95%、80.60%、7.19%。净卖出的个股23只,营业部净卖出居前个股分别为 赛为智能 、 同为股份 、 万里石 等,净卖出金额占当日成交额比例达4.92%、4.32%、11.78%。&nbsp;龙虎榜中机构净卖出1.64亿元。其中,净买入的个股8只,机构净买入较多个股分别是同为股份、 飞龙股份 、赛为智能等,净买入金额占当日成交额比例达0.82%、1.35%、0.48%。净卖出的个股19只,机构净卖出居前个股分别为润和软件、 博睿数据 、 宏景科技 等,净卖出金额占当日成交额比例达0.70%、12.88%、4.76%。&nbsp;4、北向资金2月6日小幅净卖出5.43亿。其中净买入第一位 贵州茅台 5.46亿、 宁德时代 4.69亿紧随其后,净卖出 万科A 3.87亿、 科大讯飞 2.18亿。南向资金今日净流入19.90亿港元。港股通(沪)方面,恒生中国企业、盈富基金净买入居前,分别获净买入7.77亿港元、5.78亿港元。港股通(深)方面,盈富基金、恒生中国企业净买入居前,分别获净买入25.00亿港元、8.67亿港元。&nbsp;【环球市场】&nbsp;1、美股:北京时间7日凌晨,美股周一录得连续第二个交易日收跌。美国国债收益率连续两日大幅攀升令市场情绪紧张。投资者关注美股财报,并等待美联储主席鲍威尔明天将发表的重要讲话。 标普500 指数收跌25.40点,跌幅0.61%,报4111.08点。道指收跌34.99点,跌幅0.10%,报33891.02点。纳指收跌119.50点,跌幅1.00%,报11887.45点。&nbsp;2、欧股:德国DAX 30指数收跌0.84%,报15345.91点。法国CAC 40指数收跌1.34%,报7137.10点。英国富时100指数收跌0.82%,报7836.71点。&nbsp;3、黄金:COMEX 4月黄金期货收涨0.15%,报1879.50美元/盎司。&nbsp;4、 原油 :WTI 3月原油期货收涨0.72美元,涨幅0.98%,报74.11美元/桶。布伦特4月原油期货收涨1.05美元,涨幅1.31%,报80.99美元/桶。&nbsp;【机构策略】&nbsp;对于近日市场走势,银河证券指出,节后市场短期波动原因包括:1)春节前市场情绪高涨,第一波上涨实现后,投资者转而更加关注基本面是否能够兑现,市场出现震荡。2)北向资金节前大幅净流入,但对比美国经济复苏初期,我国目前直接促消费措施力度有限,叠加近期上市公司业绩逐步披露兑现,经济修复仍有部分不确定性因素存在,或与外资对我国经济复苏的节奏判断产生预期差,节后也可以看到北向资金流入短暂放缓,增量资金的支持减弱。3)从已披露2022年报业绩预告来看,受去年四季度受疫情冲击拖累,部分企业开工及居民消费都受到较大影响,预计2022年年报业绩仍处底部区间。4)外围市场来看,美国就业数据大超预期引发投资者对美联储加息预期产生分歧,短期引发市场担忧。&nbsp;该机构认为,虽目前市场短期有一定波动,但中期中国经济企稳增长预期将不断兑现、市场流动性充足支撑、盈利面逐步回暖等对市场形成支撑。同时春节并未带来二次疫情高峰使内资对疫情反复的担忧下降,未来内资或将逐步接棒北向资金。从风格角度看,2022年11月以来,市场春季躁动效应演绎充分,大盘股长势较好。从1月份以来, 中小盘 股开始逐渐举起,行业也从消费切换到科技,风格切换明显,我们认为短期 小盘成长 风格或延续占优:一是成长板块,尤其是TMT板块,整体估值处于历史较低位置,安全垫高,反弹动力强。二是从资金流动的视角,消费板块在经历快速上涨后,目前股价有所回落,成长板块仍是资金配置的最优选择。三是主题风格的演绎催化带动成长板块的上行,行业景气度持续提升,如近期ChatGPT的快速突破也使得 人工智能 产业链备受投资者青睐,未来发展空间广阔。值得注意的是,目前成长板块上涨较快,短期可能面临交易过热或技术位调整的风险,但整体来看,小盘风格占优的趋势仍将延续。四是从投资日历角度来看,2月科技板块胜率较高。&nbsp;【新股申购】&nbsp;一致魔芋证券代码839273,发行价11.38元,发行市盈率15.98倍,主营魔芋及魔芋相关产品。&nbsp;扬州金泉证券代码603307,发行价31.04元,发行市盈率21.61倍,主营帐篷和睡袋。&nbsp;坤泰股份证券代码001260,发行价14.27元,发行市盈率22.98倍,主营汽车地毯、脚垫。&nbsp;三、公司公告和预警&nbsp;【业绩】&nbsp;通化东宝:业绩快报2022年净利同比增21.46%&nbsp;富煌钢构:2022年累计新签销售合同额约49.8亿元 同比下降11%&nbsp;新城控股:1月实现合同销售金额约57.76亿元 比上年同期减少26.54%&nbsp;金地商置:1月合约销售约22.96亿元 同比降59.68%&nbsp;融信中国:1月合约销售约9.95亿元 同比降84.7%&nbsp;新城发展:1月合约销售金额约57.76亿元 同比降24.81%&nbsp;华安证券:业绩快报2022年实现净利11.81亿元 同比降17%&nbsp;恒投证券:预计2022年度股东应占亏损约11.59亿元 同比盈转亏&nbsp;保利置业:1月合同销售金额约49亿元 同比增长105%&nbsp;融创中国:1月合同销售约72.3亿元 同比降74.1%&nbsp;【重大事项】&nbsp;永鼎股份:全资子公司获得12.4亿元线束业务中标确认&nbsp;康跃科技:拟将证券简称变更为&ldquo;长药控股&rdquo;&nbsp;壹网壹创:公司目前已部署AI内容分析&nbsp;奥飞数据:公司为百度AI业务提供算力服务支持&nbsp;晶方科技:&ldquo;MEMS 传感器 芯片先进封装测试平台&rdquo;项目获得立项批复&nbsp;合兴股份:拟公开发行可转债募资不超6.1亿元&nbsp;风语筑:公司已结合AIGC技术在文生文、文生图、文生音视频等领域进行场景应用&nbsp;保利发展:拟打包转让12个与 碧桂园 合作项目公司股权&nbsp;大族激光:目前接近式 光刻机 已投入市场&nbsp;凯立新材:拟定增募资不超过10.75亿元&nbsp;宇通客车:宇通集团等拟要约收购公司股份 要约价为7.89元/股&nbsp;【增减持】&nbsp;天通股份:公司拟减持 亚光科技 不超1%股份&nbsp;隆华新材:新余隆振拟减持不超0.88%&nbsp;海程邦达:股东及董监高拟减持不超1.91%&nbsp;ST开元:实控人拟减持公司不超1.4%股份&nbsp;沃尔德:实际控制人及一致行动人拟合计减持不超4.01%&nbsp;海南高速:拟减持不超 海汽集团 3%股份&nbsp;马云减持约3194万港元,虞锋减持约5728万港元腾盛博药&nbsp;神州数码:股东王晓岩拟减持不超2%股份&nbsp;友邦保险:回购263.08万股 耗资约2.25亿港元&nbsp;【预警】&nbsp;川能动力:公司董事长被立案调查&nbsp;云从科技:未与OpenAI开展合作 ChatGPT的产品和服务未给公司带来业务收入&nbsp;海天瑞声:尚未与OpenAI开展合作 ChatGPT产品和服务尚未给公司带来业务收入&nbsp;新国都:子公司业务暂不涉及ChatGPT文本生成式AIGC领域&nbsp;ST三圣:公司及控股股东潘先文遭证监会立案&nbsp;""" import os from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter text_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n", "。", "&nbsp;"], keep_separator=False, chunk_size=256, chunk_overlap=64) docs = text_splitter.create_documents([text]) docs ``` ### Expected behavior BUG: I get 19 documents. For example, let's see the 2nd and 3rd document. They actually don't have any overlaps. They are exactly cut by `。` in the middle (which I mark it with `||` ) : `2月6日,沪深两市三大指数弱势震荡,沪指跌0.76%, 深证成指 跌1.18%, 创业板 指跌1.4%` `||` `。` `||` `盘面上看, ChatGPT概念 持续火爆, 海天瑞声 、 云从科技 涨停6个交易日翻倍; ` . I put the example below: 1st: ... is ok, have a trunc of overlap 2nd: `2月5日单日实时票房超1.3亿元,领先第二名《满江红》近2000万,锁定单日票房冠军。目前,《流浪地球2》的票房占比34.5%,排片场次92126次。&nbsp;二、市场回顾【国内股市】&nbsp;1、2月6日,沪深两市三大指数弱势震荡,沪指跌0.76%, 深证成指 跌1.18%, 创业板 指跌1.4%` 3rd: `盘面上看, ChatGPT概念 持续火爆, 海天瑞声 、 云从科技 涨停6个交易日翻倍; 数字经济 概念盘中发酵, 铜牛信息 涨停;信创、软件股逆市走强, 青 云科技 涨停;八部门适度超前建设充换电基础设施, 充电桩 概念活跃。 白酒 、CRO、新冠 疫苗 、 券商 、 黄金 有色、 保险 、 磷化工 等板块跌幅居前。&nbsp;2、港股低开低走,截至收盘, 恒生指数 跌2.02%,报21222.16点; 国企指数 跌2.68%, 红筹指数 跌1.37%` There are also a lot of non overlapped documents in these 19 splitted documents. Please have a lot. Thanks!
RecursiveCharacterTextSplitter overlap sometimes does not work
https://api.github.com/repos/langchain-ai/langchain/issues/8142/comments
6
2023-07-23T05:00:58Z
2024-02-14T16:12:43Z
https://github.com/langchain-ai/langchain/issues/8142
1,816,988,798
8,142
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Hi there, I've found many scenarios where ConversationalRetrievalChain's attempt to condense a conversation history into a stand-alone question fails, either because the history is too complex or, for example, if the user simply provides an affirmation. Why do we attempt to condense the conversational history when Open AI's chat API provides a [messages](https://platform.openai.com/docs/api-reference/chat/create#chat/create-messages) field for this purpose? Is there a way to construct a retrieval chain such that the messages field in Open AI's chat API can be used instead of attempting to condense the chat history into a stand-alone question? ### Suggestion: Provide a way to construct a retrieval chain such that Open AI's chat API's messages field can be used instead of attempting to condense the question.
Issue: Why condense the conversational history when Open AI provides a 'messages' field in its API?
https://api.github.com/repos/langchain-ai/langchain/issues/8141/comments
3
2023-07-23T04:01:03Z
2023-10-23T22:41:46Z
https://github.com/langchain-ai/langchain/issues/8141
1,816,978,039
8,141
[ "hwchase17", "langchain" ]
### System Info Langchain version: ```langchain = "^0.0.236"```` Python 3.10.10 MacOSx 13.4.1 (c) (22F770820d) ### 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 - [ ] Agents / Agent Executors - [X] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Mysql 5.7 db. ``` toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0)) agent_executor = create_sql_agent( llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613"), toolkit=toolkit, verbose=False, agent_type=AgentType.OPENAI_FUNCTIONS, ) response = agent_executor.run(question) ``` Error message: ```none is not an allowed value (type=type_error.none.not_allowed)``` Note: It does work with `AgentType.ZERO_SHOT_REACT_DESCRIPTION` ### Expected behavior I would expect a response from the agent Observed: ```none is not an allowed value (type=type_error.none.not_allowed)```
create_sql_aqent not working with `AgentType.OPENAI_FUNCTIONS`
https://api.github.com/repos/langchain-ai/langchain/issues/8132/comments
5
2023-07-22T16:35:34Z
2023-10-29T16:04:36Z
https://github.com/langchain-ai/langchain/issues/8132
1,816,823,556
8,132
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Unable to use metadata filtering of a collection qdrant and then use it in as_retriever function. ### Suggestion: Qdrant.from_documents should include a filtering method as well to filer on the collection with payload (metadata)
Issue: Using qdrant.as_retriver() to use the filtered data of a collection (filtered on the basis of payload data)
https://api.github.com/repos/langchain-ai/langchain/issues/8126/comments
5
2023-07-22T14:09:54Z
2023-11-03T16:06:32Z
https://github.com/langchain-ai/langchain/issues/8126
1,816,778,695
8,126
[ "hwchase17", "langchain" ]
### System Info Langchain 0.0.238 System: WSL - Ubuntu ### Who can help? @hwchase17 ### Information - [ ] The official example notebooks/scripts - [X] My own modified scripts ### Related Components - [X] LLMs/Chat Models - [ ] Embedding Models - [X] Prompts / Prompt Templates / Prompt Selectors - [ ] Output Parsers - [ ] Document Loaders - [ ] Vector Stores / Retrievers - [X] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Use the ConversationBufferMemory and Prompt Templates. if you have the template ```python """ Human: Ask question Assistant: """ ``` The prompt passed to GPT4AllModel is again templated by gpt4all.py to avoid which results in the following prompt which is passed to the model ```python """ ### Human Human: Ask question Assistant: ### Assistant: """ ``` This leads to incorrect answers where models are trying to talk to them self as human and assistant if we directly call GPT4AllModel.model.prompt_model_streaming we are giving the prompt the user indented. ### Expected behavior That the prompt Template is used that the user/developer gives the Chain
call directly the prompt of GPT4All Model
https://api.github.com/repos/langchain-ai/langchain/issues/8125/comments
2
2023-07-22T13:43:02Z
2023-07-25T08:29:19Z
https://github.com/langchain-ai/langchain/issues/8125
1,816,770,103
8,125
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. How I can change the value of "retriever.llm_chain.prompt" accordingly for specific task to achieve better and accurate results as self Query retrieval isn't working with Open source LLMs it raises following error and there is an issue related to this error that's not yet resolved as well. OutputParserException: Parsing text { "query": "simon josu", "filter": "and(eq(\"from\", \"Simon assistant app Josu\"), geq(\"date_received\", \"2020-12-14T00:00:00Z\"))" } raised following error: Received unrecognized function geq. Valid functions are [<Operator.AND: 'and'>, <Operator.OR: 'or'>, <Operator.NOT: 'not'>, <Comparator.EQ: 'eq'>, <Comparator.GT: 'gt'>, <Comparator.GTE: 'gte'>, <Comparator.LT: 'lt'>, <Comparator.LTE: 'lte'>] ### Suggestion: _No response_
Issue: Rewrite SelfQueryRetriever llm prompt for better results
https://api.github.com/repos/langchain-ai/langchain/issues/8123/comments
1
2023-07-22T11:23:10Z
2023-10-28T16:04:20Z
https://github.com/langchain-ai/langchain/issues/8123
1,816,729,475
8,123
[ "hwchase17", "langchain" ]
### System Info at line 250, self.semantic_hybrid_search function only pass two parameters, query and k. it missing "**kwargs " 241 def similarity_search( 242 self, query: str, k: int = 4, **kwargs: Any 243 ) -> List[Document]: 244 search_type = kwargs.get("search_type", self.search_type) 245 if search_type == "similarity": 246 docs = self.vector_search(query, k=k) 247 elif search_type == "hybrid": 248 docs = self.hybrid_search(query, k=k) 249 elif search_type == "semantic_hybrid": 250 # docs = self.semantic_hybrid_search(query, k=k) 251 docs = self.semantic_hybrid_search(query, k=k ,**kwargs ) 252 else: 253 raise ValueError(f"search_type of {search_type} not allowed.") 254 return docs ### Who can help? _No response_ ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction without passing "**kwargs ", filter won't work ### Expected behavior docs = vector_store.similarity_search( query=query, k=3, search_type="semantic_hybrid", searchFields='content_vector', filters="mrn eq '04c3a6bcfcc821d7b7ac722713f4bf7c'", ) return doc with filtered by filter condition
missing parameter in similarity_search function in azuresearch.py
https://api.github.com/repos/langchain-ai/langchain/issues/8122/comments
2
2023-07-22T10:43:30Z
2023-10-28T16:04:25Z
https://github.com/langchain-ai/langchain/issues/8122
1,816,718,804
8,122
[ "hwchase17", "langchain" ]
### Issue with current documentation: The hyperlink which should navigate to the Python guide for Prompts seems to be broken. Affected link -> https://docs.langchain.com/docs/components/prompts/ Click on the `Python Guide` link under the `info` section. It leads to `Page Not Found`. ![image](https://github.com/hwchase17/langchain/assets/50095990/6a008b08-60a1-4736-b45d-ee37f38e1664) ### Idea or request for content: _No response_
DOC: Link broken for Python Guide on Prompts Page
https://api.github.com/repos/langchain-ai/langchain/issues/8105/comments
3
2023-07-22T01:09:31Z
2023-07-31T09:12:19Z
https://github.com/langchain-ai/langchain/issues/8105
1,816,522,282
8,105
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. How can i use Human Tool along with the websocket. As we cannot use async with tool.Can anyone please provide the solution for this. def please_take_test(): score = 0 for i, data in enumerate(questions): print(ask_for_info(data["question"], data["options"])) provided_answer = str(input()) score += check_answer(provided_answer, data["answer"]) first_prompt = ChatPromptTemplate.from_template( """You are the assisant to greet the user on the basis of score """ ) info_gathering_chain = LLMChain(llm=llm, prompt=first_prompt) ai_chat = info_gathering_chain.run(score = score) return ai_chat Here I need this input() should be directly taken from the user interface ### Suggestion: _No response_
Human Tool with websocket
https://api.github.com/repos/langchain-ai/langchain/issues/8095/comments
5
2023-07-21T19:47:10Z
2023-11-06T18:11:00Z
https://github.com/langchain-ai/langchain/issues/8095
1,816,308,692
8,095
[ "hwchase17", "langchain" ]
### Feature request parse the text in a pdf to determine whether it contains header fields such as From:, To:, Date: etc which make it likely that the original data was an email. if so, return the contents of those fields as Document metadata which can, for example, be used as metadata in a database. ### Motivation Sometimes it as important to know who said what to whom when as it is to determine what actual facts are. Investigative reporting is one example. There are adequate tools to retrieve email and its metadata from Gmail or Exchange. A similar tool for email which has been saved as a collection of PDFs which parses and retrieves the metadata will make these document collections more accessible and useful. ### Your contribution I have created a pdf to email tool in the proper format to incorporated with existing langchain document loaders. It's at [https://github.com/tevslin/emailai](https://github.com/tevslin/emailai). If there's interest I will do the linting etc to submit as a pr.
retrieve email metadata from email stored as pdf
https://api.github.com/repos/langchain-ai/langchain/issues/8094/comments
2
2023-07-21T19:40:54Z
2023-10-27T16:04:53Z
https://github.com/langchain-ai/langchain/issues/8094
1,816,302,776
8,094
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Painless scripting shows an example scoring function here https://opensearch.org/docs/latest/search-plugins/knn/painless-functions/#get-started-with-k-nns-painless-scripting-functions You can see that they reference the query vector by `params.query_value`. This is better, in my opinion than simply pasting it in as we do here https://github.com/hwchase17/langchain/blob/17c06ee45634cafb9aa8fcd06848a4213b2d58e2/libs/langchain/langchain/vectorstores/opensearch_vector_search.py#L246 ### Suggestion: _No response_
Issue: OpenSearch painless scripting scoring function could be improved
https://api.github.com/repos/langchain-ai/langchain/issues/8089/comments
1
2023-07-21T18:19:26Z
2023-10-27T16:04:59Z
https://github.com/langchain-ai/langchain/issues/8089
1,816,206,936
8,089
[ "hwchase17", "langchain" ]
### Feature request Currently, The YoutubeLoader class loads transcripts and converts all of them into a single large piece of text loosing all the information regarding when it was said in the video to be able to reference it later. I understand we cannot have very small/ unpridictable lengths of transcripts, which is why it would be great to chunk them according to a input duration by user and retain some information regarding when its said. which get the best of both worlds by having large enough data and also retaining context ### Motivation I was trying to make a vedio qa retriever, Then I noticed how the transcripts were being loaded, I have also noticed this issue with other transcript loaders such as VTT, then I had to make my custom function to load the transcripts in chunks of duration that made sense to me, which lead me to making this issue ### Your contribution I already have the code for chunking the transcripts, would love to submit a PR.
YoutubeLoader to load documents from transcripts as chunks
https://api.github.com/repos/langchain-ai/langchain/issues/8087/comments
4
2023-07-21T18:16:32Z
2023-10-28T16:04:30Z
https://github.com/langchain-ai/langchain/issues/8087
1,816,203,822
8,087
[ "hwchase17", "langchain" ]
### System Info Langchain version 0.0.225 M1 Mac Python 3.11.3 ### Who can help? @naveentatikonda ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ``` from langchain.embeddings import HuggingFaceEmbeddings from langchain.vectorstores import OpenSearchVectorSearch from opensearchpy import RequestsHttpConnection from requests_aws4auth import AWS4Auth import os aws_auth = AWS4Auth( os.environ["AWS_ACCESS_KEY"], os.environ["AWS_SECRET_KEY"], "us-east-1", "es" ) embeddings = HuggingFaceEmbeddings( model_name="sentence-transformers/distiluse-base-multilingual-cased-v2", model_kwargs={'device': 'cpu'} ) opensearch_vector_search = OpenSearchVectorSearch( os.environ["OPENSEARCH_URL"], "testindex", embeddings, http_auth=aws_auth, connection_class=RequestsHttpConnection, ) texts = [] for i in range(1, 41): texts.append(f"This is document {i}") opensearch_vector_search.add_texts(texts) query = "This is a document" search_result = opensearch_vector_search._raw_similarity_search_with_score( query, k=30, metadata_field="*", search_type="script_scoring" ) print("Number of docs in response: ", len(search_result)) ``` Output: ``` Number of docs in response: 10 ``` When using script_scoring, the code does not pass a "size=k" option to the client query, so it returns a maximum of 10 hits by default. Therefore, the user cannot receive more than 10 results regardless of the value of k. I believe all that is necessary it to add a `size=k` parameter to line 537 in `opensearch_vector_search.py`, and then the `[:k]` in line 539 is superfluous. ### Expected behavior The above code should produce 30 results, not 10.
OpenSearchVectorStore's similarity search functions can't handle k>10 with script_scoring
https://api.github.com/repos/langchain-ai/langchain/issues/8081/comments
6
2023-07-21T16:16:32Z
2023-10-27T16:05:09Z
https://github.com/langchain-ai/langchain/issues/8081
1,816,067,589
8,081
[ "hwchase17", "langchain" ]
### System Info langchain version 0.0.238 openai version 0.27.8 ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Set up your Open AI keys in your .env file then run this python script: ```py from dotenv import load_dotenv from langchain.agents import initialize_agent, AgentType from langchain.chat_models import ChatOpenAI load_dotenv() llm = ChatOpenAI(model_name="gpt-3.5-turbo") agent = initialize_agent( tools=[], llm=llm, agent=AgentType.OPENAI_FUNCTIONS ) agent.run("Hello World!") ``` ### Expected behavior The agent should be run successfully and just not be able to use any tools if none are provided. This does happen if the functions parameter is not passed to the openai interface when its empty. So should be an easy fix: 1. Detect if the tools list is empty 2. Only pass the function parameter to the openai interface if its not empty The interface call in question (`langchain/chat_models/openai.py` in line 319): ```py @retry_decorator def _completion_with_retry(**kwargs: Any) -> Any: return self.client.create(**kwargs) # <-- HERE, just filter out key functions if empty ```
Calling the OpenAI Functions agent with an empty tool list crashes
https://api.github.com/repos/langchain-ai/langchain/issues/8080/comments
2
2023-07-21T15:52:04Z
2023-11-01T16:06:10Z
https://github.com/langchain-ai/langchain/issues/8080
1,816,034,824
8,080
[ "hwchase17", "langchain" ]
Can be fixed by carrying over openapi enum definitions to new `enum` field here: https://github.com/hwchase17/langchain/blob/95e369b38dfc8fcb55c8d1ac435ad40e326e653d/langchain/chains/openai_functions/openapi.py#L85
Missing Enum support in OpenAI Functions
https://api.github.com/repos/langchain-ai/langchain/issues/8079/comments
1
2023-07-21T15:15:39Z
2023-10-27T16:05:19Z
https://github.com/langchain-ai/langchain/issues/8079
1,815,982,077
8,079
[ "hwchase17", "langchain" ]
### Issue with current documentation: https://python.langchain.com/docs/modules/model_io/models/llms/integrations/google_vertex_ai_palm - a few things are already outdated. ### Idea or request for content: _No response_
DOC: Fix issues related to Vertex AI LLMs
https://api.github.com/repos/langchain-ai/langchain/issues/8074/comments
0
2023-07-21T13:44:36Z
2023-08-18T05:56:11Z
https://github.com/langchain-ai/langchain/issues/8074
1,815,838,663
8,074
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. This is that the documentation has to be improved from langchain.indexes.vectorstore import VectorstoreIndexWrapper to from langchain.indexes.vectorstore import VectorStoreIndexWrapper <img width="762" alt="image" src="https://github.com/hwchase17/langchain/assets/32350453/7ef0656c-69ca-4f09-bc49-fb4230eaf93a"> ### Suggestion: edit this **from langchain.indexes.vectorstore import VectorstoreIndexWrapper** to **from langchain.indexes.vectorstore import VectorStoreIndexWrapper**
Issue: <Please write a comprehensive title after the 'Issue: ' prefix>
https://api.github.com/repos/langchain-ai/langchain/issues/8072/comments
2
2023-07-21T13:24:57Z
2024-03-18T16:57:29Z
https://github.com/langchain-ai/langchain/issues/8072
1,815,807,402
8,072
[ "hwchase17", "langchain" ]
### System Info I am using langchain 0.0.238, I want to use ConversationBufferMemory with sql-agent-toolkit. Please support in this regard. I changed prompt : # flake8: noqa SQL_PREFIX = """You are an agent designed to interact with a SQL database. Given an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer. Unless the user specifies a specific number of examples they wish to obtain, else fetch all results then fetch all results donot use 'LIMIT'. When you are using 'WHERE' clause to fetch specific data, you have to apply 'WHERE' clause in several ways like exact matchusing '=' or substring match using 'LIKE'. You can order the results by a relevant column to return the most interesting examples in the database. Never query for all the columns from a specific table, only ask for the relevant columns given the question. If you did notfind the column asked by the user, then return "data for the specified column doesnot exists." as the answer. You have access to tools for interacting with the database. Only use the below tools. Only use the information returned by the below tools to construct your final answer. You MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again. DO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database. If the question does not seem related to the database, just return "I don't know" as the answer. This reminds you of your past memory and events:{chat_history} Know that only the "Question" ("HumanMessage") and "Final answer" ("AIMessage") to each previous question are available inthe past memory section above. Hence, always include enough detail in the Final answer so that you can answer subsequent questions. If you believe any of the data computed to answer a question is likely to be useful in answering a possible follow-on question. """ SQL_SUFFIX = """Begin! Question: {input} Thought: I should look at the tables in the database to see what I can query. Then I should query the schema of the most relevant tables. {agent_scratchpad}""" SQL_FUNCTIONS_SUFFIX = """I should look at the tables in the database to see what I can query. Then I should query the schema of the most relevant tables.""" And changed base.py: """SQL agent.""" from typing import Any, Dict, List, Optional from langchain.agents.agent import AgentExecutor, BaseSingleActionAgent #from sql_agent_toolkits.sql.prompt import ( SQL_FUNCTIONS_SUFFIX,SQL_PREFIX,SQL_SUFFIX,) from langchain.agents.agent_toolkits.sql.prompt import ( SQL_FUNCTIONS_SUFFIX, SQL_PREFIX, SQL_SUFFIX, ) from langchain.agents.agent_toolkits.sql.toolkit import SQLDatabaseToolkit from langchain.agents.agent_types import AgentType from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain from langchain.prompts.chat import ( ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, ) from langchain.schema.language_model import BaseLanguageModel from langchain.schema.messages import AIMessage, SystemMessage from langchain.memory import ConversationBufferMemory global memory memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) def create_sql_agent( llm: BaseLanguageModel, toolkit: SQLDatabaseToolkit, agent_type: AgentType = AgentType.ZERO_SHOT_REACT_DESCRIPTION, callback_manager: Optional[BaseCallbackManager] = None, prefix: str = SQL_PREFIX, suffix: Optional[str] = SQL_SUFFIX, format_instructions: str = FORMAT_INSTRUCTIONS, input_variables: Optional[List[str]] = None, top_k: int = 10, max_iterations: Optional[int] = 15, max_execution_time: Optional[float] = None, early_stopping_method: str = "force", verbose: bool = False, agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Dict[str, Any], ) -> AgentExecutor: """Construct an SQL agent from an LLM and tools.""" tools = toolkit.get_tools() #prefix = prefix.format(dialect=toolkit.dialect, top_k=top_k) #print("prefix", prefix) if input_variables is None: input_variables = ["dialect", "input", "agent_scratchpad"] agent: BaseSingleActionAgent print("input_variables", input_variables) if agent_type == AgentType.ZERO_SHOT_REACT_DESCRIPTION: prompt = ZeroShotAgent.create_prompt( tools, prefix=prefix, suffix=suffix or SQL_SUFFIX, format_instructions=format_instructions, input_variables=input_variables, ) llm_chain = LLMChain( llm=llm, prompt=prompt, callback_manager=callback_manager, ) tool_names = [tool.name for tool in tools] agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs) # memory = ConversationBufferMemory(memory_key="chat_history") elif agent_type == AgentType.OPENAI_FUNCTIONS: messages = [ SystemMessage(content=prefix), HumanMessagePromptTemplate.from_template("{input}"), AIMessage(content=suffix or SQL_FUNCTIONS_SUFFIX), MessagesPlaceholder(variable_name="agent_scratchpad"), ] input_variables = ["input", "agent_scratchpad"] _prompt = ChatPromptTemplate(input_variables=input_variables, messages=messages) agent = OpenAIFunctionsAgent( llm=llm, prompt=_prompt, tools=tools, callback_manager=callback_manager, **kwargs, ) else: raise ValueError(f"Agent type {agent_type} not supported at the moment.") return AgentExecutor.from_agent_and_tools( agent=agent, tools=tools, callback_manager=callback_manager, verbose=verbose, max_iterations=max_iterations, max_execution_time=max_execution_time, early_stopping_method=early_stopping_method, memory=memory, **(agent_executor_kwargs or {}), ) ### 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 - [X] Memory - [X] Agents / Agent Executors - [X] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction I have changed Prompt.py and base.py to provide chat_history as input but I am running into errors from create_prompt method using ZeroShotAgent or from LLMChain(expecting inputs in dictionary) Error: input_variables ['dialect', 'input', 'agent_scratchpad'] input_variables from /opt/miniconda/lib/python3.10/site-packages/langchain/agents/mrkl/ ['dialect', 'input', 'agent_scratchpad'] --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[1], line 2 1 from tools.db_llm_with_memory import * ----> 2 db_llm_with_memory("which all enzymes have urate as substrate") File ~/notebooks/atossa-usecase/atossa_usecase/tools/db_llm_with_memory.py:42, in db_llm_with_memory(query) 35 agent = create_sql_agent( 36 llm=ChatOpenAI(temperature=0), 37 toolkit=toolkit, 38 verbose=True, 39 agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,memory=memory 40 ) 41 # agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=toolkit, verbose=True, memory=memory) ---> 42 agent.run(query) File /opt/miniconda/lib/python3.10/site-packages/langchain/chains/base.py:440, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs) 438 if len(args) != 1: 439 raise ValueError("`run` supports only one positional argument.") --> 440 return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[ 441 _output_key 442 ] 444 if kwargs and not args: 445 return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[ 446 _output_key 447 ] File /opt/miniconda/lib/python3.10/site-packages/langchain/chains/base.py:220, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info) 185 def __call__( 186 self, 187 inputs: Union[Dict[str, Any], Any], (...) 193 include_run_info: bool = False, 194 ) -> Dict[str, Any]: 195 """Execute the chain. 196 197 Args: (...) 218 `Chain.output_keys`. 219 """ --> 220 inputs = self.prep_inputs(inputs) 221 callback_manager = CallbackManager.configure( 222 callbacks, 223 self.callbacks, (...) 228 self.metadata, 229 ) 230 new_arg_supported = inspect.signature(self._call).parameters.get("run_manager") File /opt/miniconda/lib/python3.10/site-packages/langchain/chains/base.py:364, in Chain.prep_inputs(self, inputs) 362 _input_keys = _input_keys.difference(self.memory.memory_variables) 363 if len(_input_keys) != 1: --> 364 raise ValueError( 365 f"A single string input was passed in, but this chain expects " 366 f"multiple inputs ({_input_keys}). When a chain expects " 367 f"multiple inputs, please call it by passing in a dictionary, " 368 "eg `chain({'foo': 1, 'bar': 2})`" 369 ) 370 inputs = {list(_input_keys)[0]: inputs} 371 if self.memory is not None: ValueError: A single string input was passed in, but this chain expects multiple inputs ({'dialect', 'input'}). When a chain expects multiple inputs, please call it by passing in a dictionary, eg `chain({'foo': 1, 'bar': 2})` ### Expected behavior Please provide some simple addon behaviour to use memory with sql agent
unable to implement memory with sql agent toolkit
https://api.github.com/repos/langchain-ai/langchain/issues/8069/comments
7
2023-07-21T12:12:30Z
2023-10-29T16:04:52Z
https://github.com/langchain-ai/langchain/issues/8069
1,815,703,682
8,069
[ "hwchase17", "langchain" ]
### 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.
Integration test on BingSearchAPIWrapper
https://api.github.com/repos/langchain-ai/langchain/issues/8068/comments
2
2023-07-21T11:36:16Z
2023-10-27T16:05:34Z
https://github.com/langchain-ai/langchain/issues/8068
1,815,656,226
8,068
[ "hwchase17", "langchain" ]
### 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.
Handle simpler tool input schemas for structured tools
https://api.github.com/repos/langchain-ai/langchain/issues/8066/comments
10
2023-07-21T09:36:30Z
2023-11-05T16:05:35Z
https://github.com/langchain-ai/langchain/issues/8066
1,815,491,917
8,066
[ "hwchase17", "langchain" ]
### Feature request Support async functions with the `@tool` decorator (and `StructuredTool.from_function`, I guess). ### Motivation The API provided by `@tool` is really nice, but using the decorator on an async function currently doesn't work. ### Your contribution None so far but happy to help if I can.
Async @tool functions
https://api.github.com/repos/langchain-ai/langchain/issues/8065/comments
1
2023-07-21T09:33:16Z
2023-10-27T16:05:38Z
https://github.com/langchain-ai/langchain/issues/8065
1,815,487,097
8,065
[ "hwchase17", "langchain" ]
### 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_
Issue:in the multiprompt chain connecting sqldatabasechain
https://api.github.com/repos/langchain-ai/langchain/issues/8062/comments
2
2023-07-21T08:43:59Z
2023-10-27T16:05:43Z
https://github.com/langchain-ai/langchain/issues/8062
1,815,411,509
8,062
[ "hwchase17", "langchain" ]
### 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
Bug: Chroma().add_texts() return empty ids list when metadata is not None
https://api.github.com/repos/langchain-ai/langchain/issues/8061/comments
3
2023-07-21T08:17:06Z
2023-07-24T01:18:49Z
https://github.com/langchain-ai/langchain/issues/8061
1,815,375,116
8,061
[ "hwchase17", "langchain" ]
### 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_
DOC: Unable to Pass HuggingFace Access Token via Huggingface TextGen Inference for large language model hosted in HuggingFace Inference Endpoint in protected mode.
https://api.github.com/repos/langchain-ai/langchain/issues/8060/comments
7
2023-07-21T08:10:05Z
2023-11-14T16:07:00Z
https://github.com/langchain-ai/langchain/issues/8060
1,815,365,924
8,060
[ "hwchase17", "langchain" ]
### 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.
Issue: using Fine-tuning model with Langchain
https://api.github.com/repos/langchain-ai/langchain/issues/8057/comments
1
2023-07-21T06:51:49Z
2023-10-27T16:05:48Z
https://github.com/langchain-ai/langchain/issues/8057
1,815,254,507
8,057
[ "hwchase17", "langchain" ]
### 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_
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>
https://api.github.com/repos/langchain-ai/langchain/issues/8056/comments
2
2023-07-21T06:45:54Z
2023-10-27T16:05:53Z
https://github.com/langchain-ai/langchain/issues/8056
1,815,248,073
8,056
[ "hwchase17", "langchain" ]
### System Info ### I'm not sure what exactly is causing the issue. Is it langchain, TGI, or streamlit generate() got multiple keyword arguments for 'stop_sequences' upon running the script along with streamlit ``` TypeError: generate() got multiple values for keyword argument 'stop_sequences' Traceback: File "/usr/local/lib/python3.8/dist-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script exec(code, module.dict) File "/workspace/app.py", line 154, in main() File "/workspace/app.py", line 109, in main handle_userinput(user_question) File "/workspace/app.py", line 79, in handle_userinput response = st.session_state.conversation({'question': user_question}) File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 243, in call raise e File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 237, in call self._call(inputs, run_manager=run_manager) File "/usr/local/lib/python3.8/dist-packages/langchain/chains/conversational_retrieval/base.py", line 142, in _call answer = self.combine_docs_chain.run( File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 445, in run return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[ File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 243, in call raise e File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 237, in call self._call(inputs, run_manager=run_manager) File "/usr/local/lib/python3.8/dist-packages/langchain/chains/combine_documents/base.py", line 106, in _call output, extra_return_dict = self.combine_docs( File "/usr/local/lib/python3.8/dist-packages/langchain/chains/combine_documents/stuff.py", line 165, in combine_docs return self.llm_chain.predict(callbacks=callbacks, **inputs), {} File "/usr/local/lib/python3.8/dist-packages/langchain/chains/llm.py", line 252, in predict return self(kwargs, callbacks=callbacks)[self.output_key] File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 243, in call raise e File "/usr/local/lib/python3.8/dist-packages/langchain/chains/base.py", line 237, in call self._call(inputs, run_manager=run_manager) File "/usr/local/lib/python3.8/dist-packages/langchain/chains/llm.py", line 92, in _call response = self.generate([inputs], run_manager=run_manager) File "/usr/local/lib/python3.8/dist-packages/langchain/chains/llm.py", line 102, in generate return self.llm.generate_prompt( File "/usr/local/lib/python3.8/dist-packages/langchain/llms/base.py", line 188, in generate_prompt return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs) File "/workspace/app.py", line 18, in generate super().generate(*args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/langchain/llms/base.py", line 281, in generate output = self._generate_helper( File "/usr/local/lib/python3.8/dist-packages/langchain/llms/base.py", line 225, in _generate_helper raise e File "/usr/local/lib/python3.8/dist-packages/langchain/llms/base.py", line 212, in _generate_helper self._generate( File "/usr/local/lib/python3.8/dist-packages/langchain/llms/base.py", line 604, in _generate self._call(prompt, stop=stop, run_manager=run_manager, **kwargs) File "/usr/local/lib/python3.8/dist-packages/langchain/llms/huggingface_text_gen_inference.py", line 156, in _call res = self.client.generate( ``` ``` from langchain.llms.huggingface_text_gen_inference import HuggingFaceTextGenInference from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler llm = HuggingFaceTextGenInference( inference_server_url='http://127.0.0.1:8080', max_new_tokens=512, top_k=10, top_p=0.95, typical_p=0.95, temperature=0.85, stop_sequences=['</s>'], repetition_penalty=1.03, stream=True ) print(llm("What is a proctor?", callbacks=[StreamingStdOutCallbackHandler()])) ``` the above script works properly but while using it with chainlit I run into the `generate() got multiple keyword arguments for 'stop_sequences'` ### Who can help? @hwchase17 @baskaryan ### 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 - [ ] Async ### Reproduction ``` from langchain.llms.huggingface_text_gen_inference import HuggingFaceTextGenInference from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler llm = HuggingFaceTextGenInference( inference_server_url='http://127.0.0.1:8080', max_new_tokens=512, top_k=10, top_p=0.95, typical_p=0.95, temperature=0.85, stop_sequences=['</s>'], repetition_penalty=1.03, stream=True ) print(llm("What is a proctor?", callbacks=[StreamingStdOutCallbackHandler()])) ``` the above script works properly but while using it with chainlit I run into the `generate() got multiple keyword arguments for 'stop_sequences'` ### Expected behavior generate normally
generate() got multiple keyword arguments for 'stop_sequences' while generating using hf TGI
https://api.github.com/repos/langchain-ai/langchain/issues/8055/comments
2
2023-07-21T06:36:26Z
2023-07-21T15:24:11Z
https://github.com/langchain-ai/langchain/issues/8055
1,815,238,276
8,055
[ "hwchase17", "langchain" ]
### Feature request How does Alibaba Cloud's Tongyi Qianwen Big Model combine with Langchain? langchain如何与阿里云的通义千问大模型结合起来 ### Motivation Alibaba Cloud's Tongyi Qianwen ### Your contribution none
Langchain support Alibaba Cloud's Tongyi Qianwen model?
https://api.github.com/repos/langchain-ai/langchain/issues/8054/comments
16
2023-07-21T06:00:26Z
2023-12-19T00:49:48Z
https://github.com/langchain-ai/langchain/issues/8054
1,815,202,873
8,054
[ "hwchase17", "langchain" ]
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.
Issue: Langsmith running using local docker containers, roadmap, local model support?
https://api.github.com/repos/langchain-ai/langchain/issues/8052/comments
5
2023-07-21T05:13:57Z
2023-12-01T16:08:58Z
https://github.com/langchain-ai/langchain/issues/8052
1,815,166,208
8,052
[ "hwchase17", "langchain" ]
### 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>
CallbackManager _handle_event consumes Exceptions
https://api.github.com/repos/langchain-ai/langchain/issues/8051/comments
1
2023-07-21T05:09:22Z
2023-10-27T16:05:59Z
https://github.com/langchain-ai/langchain/issues/8051
1,815,162,839
8,051
[ "hwchase17", "langchain" ]
### 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_
Issue: Tool is always called with a string parameter instead of Model despite using OPENAI_FUNCTIONS agent
https://api.github.com/repos/langchain-ai/langchain/issues/8042/comments
2
2023-07-20T23:54:50Z
2023-07-25T14:25:43Z
https://github.com/langchain-ai/langchain/issues/8042
1,814,957,380
8,042
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Hello everyone, I am trying to make a mcq tool but that tools need input for that particular question everytime what that quiz tool is called. Any approach which i can try ### Suggestion: _No response_
can it be possible to take input in custom tool
https://api.github.com/repos/langchain-ai/langchain/issues/8039/comments
3
2023-07-20T23:07:26Z
2023-10-27T16:06:04Z
https://github.com/langchain-ai/langchain/issues/8039
1,814,917,699
8,039
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. hey there, I am facing problem for streaming responses in fastapi can i get some info that how to use websockets to stream the response ### Suggestion: _No response_
how to deploy langchain bot using fastapi with streaming responses
https://api.github.com/repos/langchain-ai/langchain/issues/8029/comments
2
2023-07-20T21:02:55Z
2023-10-26T16:04:48Z
https://github.com/langchain-ai/langchain/issues/8029
1,814,794,951
8,029
[ "hwchase17", "langchain" ]
### Feature request Update `TextGen` to include `streaming` support for Oobabooga. ### Motivation Oobabooga provides a streaming API that will be very helpful. [TextGen](https://github.com/hwchase17/langchain/pull/5997) already supports the regular API. ### Your contribution :)
Streaming support for Oobabooga API?
https://api.github.com/repos/langchain-ai/langchain/issues/8028/comments
4
2023-07-20T20:54:55Z
2023-11-20T16:05:42Z
https://github.com/langchain-ai/langchain/issues/8028
1,814,786,549
8,028
[ "hwchase17", "langchain" ]
### Feature request This probably needs more refinement but how but there are a lot of components floating around that overlaps with one another. As per my understanding, the broader categorization should be: Chains: Simple scenarios - steps are hardcoded Agent Executors: Complex scenarios - steps are determined on runtime Agent Executor internally uses an agent to plan the next step. In that sense, the agents can probably be renamed to just planners, and agent executors can then be simply called agents(?) Both the chains and agents can use tools (or toolkits) to execute steps in their chain. This simplifies the overall architecture and makes the components intuitive. ### Motivation As a beginner, I'm struggling with all the components floating around, and reducing the overall components in the core architecture reduces the learning curve of devs. ### Your contribution Yes, I can to work on the PR if this change gets approval.
Agents and agent executor are 2 different concepts and shouldn't be placed in the same bucket
https://api.github.com/repos/langchain-ai/langchain/issues/8024/comments
1
2023-07-20T19:46:36Z
2023-10-26T16:04:53Z
https://github.com/langchain-ai/langchain/issues/8024
1,814,693,973
8,024
[ "hwchase17", "langchain" ]
### Feature request E.g., it would be great if ``` m = AIMessage(content="Hi!") print(m) ``` returned something like "AI: Hi!" ### Motivation It would make representation of message history (e.g., for debugging or serialization into a json) a little bit easier. ### Your contribution yes, I'm happy to do it.
Add a str representation for the Message
https://api.github.com/repos/langchain-ai/langchain/issues/8023/comments
2
2023-07-20T18:59:28Z
2023-10-26T16:04:58Z
https://github.com/langchain-ai/langchain/issues/8023
1,814,626,098
8,023
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I am trying to use create_csv_agent with memory in order to make the model answer based on previous answers so this was the code I used to achieve such task, mostly from issue #5611 with a few adjustments ``` def csv_extractor(json_request: str): ''' Useful for extracting data from a csv file. Takes a JSON dictionary as input in the form: { "prompt":"<question>", "path":"<file_name>" } Example: { "prompt":"Find the maximum age in xyz.csv", "path":"xyz.csv" } Args: request (str): The JSON dictionary input string. Returns: The required information from csv file. ''' arguments_dictionary = json.loads(json_request) question = arguments_dictionary["prompt"] file_name = arguments_dictionary["path"] csv_agent = create_csv_agent(llm=OpenAI(),path=path_to_file,verbose=True) return csv_agent(question) request_format = '{{"prompt":"<question>","path":"<file_name>"}}' description = f'Useful for working with a csv file. Input should be JSON in the following format: {request_format}' csv_extractor_tool = Tool( name="csv_extractor", func=csv_extractor, description=description, verbose=True, ) ``` ``` tools = [csv_extractor_tool] # Adding memory to our agent from langchain.agents import ZeroShotAgent from langchain.memory import ConversationBufferMemory prefix = """Have a conversation with a human, Answer step by step and the history of the messages is critical and very important to use. The user is expected to ask you questions that you will need to use the information you had from the previous answers. For example if the user asked you about the name of the a person, he may asks you another question on that person based on the information you have so take care. You have access to the following tools:""" suffix = """Begin!" {chat_history} Question: {input} {agent_scratchpad}""" prompt = ZeroShotAgent.create_prompt( tools=tools, prefix=prefix, suffix=suffix, input_variables=["input", "chat_history", "agent_scratchpad"] ) memory = ConversationBufferWindowMemory( memory_key='chat_history', k=5, return_messages=True ) # Creating our agent from langchain.chains import LLMChain from langchain.llms import OpenAI from langchain.agents import AgentExecutor import json llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt) agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True) agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory) ``` I am querying a CSVs containing names and dates of birth using my agent, so when I send the prompt like this ``` data = {"input": {"prompt": "give me the longest name", "path": "file.csv"}} json_data = json.dumps(data) result = agent_chain(json_data) ``` It returns the correct answer, let this answer be "Medjedovic" now when I ask the model to give me the date of birth of this name by asking 'What is his birth date'? It identifies correctly in the first chain observation that I want the birth date of Medjedovic which most probably mean that the name is in the memory as it should be. However, it retrieves a different and incorrect birth date in the second chain this is the code ``` data = {"input": {"prompt": "what is his birth date?", "path": "file.csv"}} json_data = json.dumps(data) result = agent_chain(json_data) ``` the output is like this: > Entering new AgentExecutor chain... Thought: I need to look up the birth date of Medjedovic Action: csv_extractor Action Input: {"prompt":"what is his birth date?","path":"file.csv"} > Entering new AgentExecutor chain... Thought: I need to find the birth_date column in the dataframe Action: python_repl_ast Action Input: df['birth_date'] Observation: 0 2/10/2000 then Final Answer: Medjedovic's date of birth is 2/10/2000. it returned a wrong birth date of a different person which is the first person in the dataset, I want it to use the name it identified in the answer of first question and the observation in the first chain of the second question to give the right answer How this could be solved or maintained? I am using gpt-3.5-turbo model API. I have used different prefixes also and neither of them worked. ### Suggestion: _No response_
Issue:Using memory with agents gives wrong results
https://api.github.com/repos/langchain-ai/langchain/issues/8020/comments
4
2023-07-20T17:59:43Z
2023-10-28T16:04:45Z
https://github.com/langchain-ai/langchain/issues/8020
1,814,527,905
8,020
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. How do you extract the last thought process from an agent? The final answer from the agent is too summarized for my liking. However the 'Final Thought' process is great with all the details. I am having some difficulties extracting that information event with `return_immediate_steps=True`. Is there anyway I can get that final thought information as part of the Final Answer? ### Suggestion: _No response_
Extract Final Thoughts from Agent as part of Final Answer.
https://api.github.com/repos/langchain-ai/langchain/issues/8019/comments
3
2023-07-20T17:53:44Z
2023-08-14T14:47:22Z
https://github.com/langchain-ai/langchain/issues/8019
1,814,519,811
8,019
[ "hwchase17", "langchain" ]
### Feature request I am writing to request an enhancement for the FLARE chain in Langchain. I'm wondering how I can change the class to accept local (fine-tuned) models rather then use OpenAi API. Since FLARE uses a retriever, a question generator, and a response generator, it would be interesting to leverage the strength of newer models, or even custom fine-tuned ones. ### Motivation By doing so, it would give more flexibility to experiment with different models, and not rely on OpenAi, hence making it more open-source. ### Your contribution I would envision the future syntax to look something like this: ``` from langchain.chains import FlareChain flare_chain = FlareChain( question_generator_chain=question_generator, response_chain=response_generator, output_parser=None, # Replace with the output parser if available retriever=retriever, min_prob=0.2, min_token_gap=5, num_pad_tokens=2, max_iter=10, start_with_retrieval=True, ) ``` The models will be imported like so: ``` from transformers import AutoTokenizer, AutoModelForCausalLM from transformers import AutoTokenizer, AutoModelForSeq2SeqLM from langchain.chains import RetrievalQA tokenizer = AutoTokenizer.from_pretrained(model_id) response_generator = AutoModelForCausalLM.from_pretrained(model_id, device_map='auto') tokenizer = AutoTokenizer.from_pretrained("model_id_1") question_generator = AutoModelForSeq2SeqLM.from_pretrained("model_id_1") retriever= RetrievalQA.from_chain_type(llm=model, chain_type="stuff", retriever=docsearch.as_retriever()) ```
FLARE Implementation with Local Fine-Tuned Models
https://api.github.com/repos/langchain-ai/langchain/issues/8015/comments
3
2023-07-20T16:36:17Z
2024-04-23T07:00:46Z
https://github.com/langchain-ai/langchain/issues/8015
1,814,401,030
8,015
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I was looking up the documentation as well. However, from the documentation it seems as if both types of agents are doing the same thing. Even when I looked at the backend code, both agent codes seemed almost identical. I am not so sure what I am missing in terms of my understanding. Any leads would be appreciated. ### Suggestion: Documentation between the two types can be made more clear.
What is the difference between OpenAI Function and OpenAI Multi Functions Agent
https://api.github.com/repos/langchain-ai/langchain/issues/8011/comments
4
2023-07-20T15:07:47Z
2023-12-16T21:51:12Z
https://github.com/langchain-ai/langchain/issues/8011
1,814,224,911
8,011
[ "hwchase17", "langchain" ]
### Issue with current documentation: Hello every one! I am following the tutorial of the use of agents. Specifically, now I am exploring the type [OpenAIFunctions. ](https://python.langchain.com/docs/modules/agents/agent_types/openai_functions_agent). I am following the exact same tutorial and I get some error when I want to use the agent to solve some math problems or connect to my SQL Data base which are tools that the agents have available. The error that I have is the following: ```python ValidationError: 1 validation error for AIMessage content none is not an allowed value (type=type_error.none.not_allowed) ``` Does any one know what is causing this error? Best regards, Orlando
Error in OpenAI Functions Agent
https://api.github.com/repos/langchain-ai/langchain/issues/8009/comments
5
2023-07-20T14:47:06Z
2023-07-20T18:25:10Z
https://github.com/langchain-ai/langchain/issues/8009
1,814,175,432
8,009
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Hi Everyone, I am trying to use `llama-2-70b-chat` with the LlamaCpp() as described here : https://python.langchain.com/docs/modules/model_io/models/llms/integrations/llamacpp#metal My system specs are MacBook Pro, M1 Chip, 16GB, 500GB SSD Here is my code using LlamaCpp: ``` DEFAULT_CHAT_MODEL_LLAMA = '/Volumes/Gargantua/LLAA2/llama-2-70b-chat/ggml-model-q4_0.bin' class HelpprBaseLLAMAV2(LlamaCpp): model_path = DEFAULT_CHAT_MODEL_LLAMA callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]) verbose = True input = {"temperature": 0.75, "top_p": 1, "max_length": 2048} n_gpu_layers = 1 n_batch = 512 f16_kv = True ``` Whenever I call `llm = HelpprBaseLLAMAV2()` via the following: ``` (venv) tapanjain@MacBook-Pro-2 helppr % python main.py ``` I get the following error: ``` zsh: illegal hardware instruction python main.py ``` Can anyone help me what exactly is the reason here? Is langchain right now not supported for llama 2? ### Suggestion: _No response_
Issue: Using "llama-2-70b-chat/ggml-model-q4_0.bin" with LlamaCpp()
https://api.github.com/repos/langchain-ai/langchain/issues/8004/comments
12
2023-07-20T13:52:10Z
2023-11-15T16:07:27Z
https://github.com/langchain-ai/langchain/issues/8004
1,814,051,785
8,004
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I came to know that there are two methods to keep memory in **ConversationalRetrievalChain** 1. Method -1 Using **ConversationBufferMemory** ``` from langchain.chains import ConversationalRetrievalChain from langchain.memory import ConversationBufferMemory memory = ConversationBufferMemory( memory_key="chat_history", return_messages=True ) qa= ConversationalRetrievalChain.from_llm( llm, retriever=retriever), memory=memory ) ``` 3. Method -2 Using **chat_history** parameter ``` from langchain.chains import ConversationalRetrievalChain qa= ConversationalRetrievalChain.from_llm( llm, retriever=retriever) ) chat_history = [] result = qa({"question": question, "chat_history": chat_history}) ``` What is the exact difference between the above two methods? When should use one over another and why? ### Suggestion: _No response_
Difference between ConversationBufferMemory and chat_history parameter
https://api.github.com/repos/langchain-ai/langchain/issues/8002/comments
5
2023-07-20T13:40:25Z
2024-07-02T12:21:04Z
https://github.com/langchain-ai/langchain/issues/8002
1,814,025,506
8,002
[ "hwchase17", "langchain" ]
### System Info Langchain Version== 0.0.237 Platform == Google Colaboratory ### Who can help? @eyurtsev ### Information - [X] The official example notebooks/scripts - [X] My own modified scripts ### Related Components - [ ] LLMs/Chat Models - [ ] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [ ] Output Parsers - [X] Document Loaders - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction Step 1: Import packages Step 2: Use APIfy dataset loader loader = ApifyDatasetLoader( dataset_id="KCoOphOr1tQmmUhsS", dataset_mapping_function=lambda item: Document( page_content=item["description"] or "name", metadata={"id": item["id"]} ), ) Step 3: Attempt to create a vector store index from langchain.indexes import VectorstoreIndexCreator index = VectorstoreIndexCreator().from_loaders([loader]) ### Expected behavior It should create the index from the data loader provided, but the loader does not produce the attribute "page content" when loading APIfy datasets. <img width="919" alt="Screenshot 2023-07-19 at 12 24 02" src="https://github.com/hwchase17/langchain/assets/63857960/11aee742-c513-4cc6-863e-56c5e10a43db">
APIfy dataset loader does not provide the attribute "page_content" in the loaded documents
https://api.github.com/repos/langchain-ai/langchain/issues/7999/comments
5
2023-07-20T12:32:18Z
2023-10-28T16:04:50Z
https://github.com/langchain-ai/langchain/issues/7999
1,813,895,614
7,999
[ "hwchase17", "langchain" ]
### System Info `langchain 0.0.235` I wrote my own callback handler `class ChatHandler(BaseCallbackHandler):` which includes the function ``` def on_tool_end(self, output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) -> Any: """Run when tool ends running.""" if observation_prefix is not None: print("OBSERVATION: "+str(output)) if llm_prefix is not None: print("llm_prefix: "+str(output)) ``` as inspired by the source of the file callback handler https://api.python.langchain.com/en/latest/_modules/langchain/callbacks/file.html#FileCallbackHandler . I have a STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION agent. My goal is to capture the observation, it seems not to call the function. The handler works fine for other functions. I attach the handler like this: ``` cHandler = chatHandler.ChatHandler() cManager = manager.BaseCallbackManager(handlers=[cHandler]) initialize_agent(tools,llm, callback_manager=cManager, ... ``` Am I using the wrong callback manager? ### Who can help? @agola11 @hwchase17 ### 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 - [ ] Tools / Toolkits - [ ] Chains - [X] Callbacks/Tracing - [ ] Async ### Reproduction ``` import os from langchain.agents import initialize_agent from langchain.callbacks import manager from langchain.chat_models import AzureChatOpenAI from langchain.agents import AgentType from langchain.callbacks.base import BaseCallbackHandler from langchain.schema import AgentAction from typing import Any, Dict, List, Optional # ENVIRONMENT KEYS; OPENAI_API_KEY import json vals = json.load(open("../local.settings.json"))['Values'] for k in vals.keys(): os.environ[k] = vals[k] from langchain.agents import Tool def a(b): print('tool used wow') return "frogimage.png" t = Tool( name="Search things online", #search location by vague name func=a, description="Use this tool to search and find things online.", return_direct=False ) BASE_URL = "https://XXX.openai.azure.com" DEPLOYMENT_NAME = "gpt-35-turbo-16k" model = AzureChatOpenAI( openai_api_base=BASE_URL, openai_api_version="2023-05-15", deployment_name=DEPLOYMENT_NAME, openai_api_key=os.environ["OPENAI_API_KEY"], openai_api_type="azure", temperature=0.0 ) class TestHandler(BaseCallbackHandler): def on_tool_end(self, output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) -> Any: """Run when tool ends running.""" print("on_tool_end") def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: """Run on agent action.""" print("on_agent_action") cHandler = TestHandler() cManager = manager.BaseCallbackManager(handlers=[cHandler]) agent_chain = initialize_agent([t],model, callback_manager=cManager, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent_chain("search frog images online") ``` outputs: > > Entering new AgentExecutor chain... > on_agent_action > Action: > ``` > { > "action": "Search things online", > "action_input": "frog images" > } > ```tool used wow > > Observation: frogimage.png > Thought:I found an image of a frog. Here it is: > Action: > ``` > { > "action": "Final Answer", > "action_input": "frogimage.png" > } > ``` > > > > Finished chain. > {'input': 'search frog images online', 'output': 'frogimage.png'} ### Expected behavior The function on_tool_end is called when the agent has used a tool, printing on_tool_end, but only on_agent_action is printed.
custom BaseCallbackHandler in STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION agent not calling on_tool_end
https://api.github.com/repos/langchain-ai/langchain/issues/7998/comments
3
2023-07-20T11:16:38Z
2023-07-25T14:15:21Z
https://github.com/langchain-ai/langchain/issues/7998
1,813,748,887
7,998
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I've been stuck on a task that I was working on, not knowing how to exactly proceed with it. Where I need to combine different type of chain in the routes of an Agent. So I have managed to build the following pipeline using an Agent. I receive a query and according to the context of the query it gets routed either to any of the different LLM Chains defined (answering Greetings, Goodbyes, Unrelated Questions) or it gets routed to a RetrievalQA that searches for the answer in a VectorStore when the input query is related to the context in question. Now what I noticed, and have been trying to fix was that sometimes, despite adding memory to my agent, I can receive a follow-up question that will not be routed to the VectorStore as it would labeled as "Unrelated". Example: Supposedly the first question was : "Am I allowed to work remotely on Fridays?". This is related for exampled and the model will reply with no from the VectorStore. Now, if I follow it up with: "How about Mondays?" the model will identify the input query as unrelated as it is not tackling the subject of "Work". Ideally, I would want it to reformulate the question to: "How about working remotely on Monday?" and to route it accordingly to the VectorStore as it is tackling the subject of "work". I made my research and found that CoversationalRetrievalChains should be part of my solution, but I do not know how to put it exactly in my architecture. The main issue is that LLM Chains expect a certain type of input ('input':x) while ConversationalRelationChain expect another ('question':x, 'chat_history':y). I tried using LOTR (Lord of all Retrievers) but apparently it hasn't been working as well. I only have 1 retriever (1 VectorStore) and the rest are simple LLMChains. Yet even when I tried LOTR with CoversationalRetrievalChains in order to combine retrievers I am getting the following error: "NotImplementedError: Saving not supported for this chain type." In short I want to be able to pass the same input, regardless of the route in my Agent, whether it's a LLM Chain or a CoversationalRetrievalChains. I'm a bit lost and would love some help on the subject. ### Suggestion: _No response_
Issue: <Combining LLMChain and ConversationalRelationChain in an agent's routes>
https://api.github.com/repos/langchain-ai/langchain/issues/7997/comments
5
2023-07-20T11:01:40Z
2024-01-12T05:24:25Z
https://github.com/langchain-ai/langchain/issues/7997
1,813,722,288
7,997
[ "hwchase17", "langchain" ]
### System Info langchain==0.0.230 MacOS ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction I do not know how exactly to reproduce this, but I would like to know if someone had the same error using GPT-3.5-turbo with this agent, tool, and prompts: Agent: LLMSingleActionAgent Tool and prompt: ``` template_hello = """You are a chatbot, answer to this {input} Previous conversation history: {history} """ prompt_hello = PromptTemplate(input_variables=["input", "history"], template=template_hello) hello_chain = LLMChain( llm=ChatOpenAI(model='gpt-3.5-turbo', prompt=prompt_hello, verbose=True, memory=self.memory ) ``` Memory: ``` from langchain.memory import ConversationTokenBufferMemory self.memory = ConversationTokenBufferMemory(llm=ChatOpenAI(temperature=0, max_tokens=500, model='gpt-3.5-turbo'), memory_key="history", max_token_limit=500) ``` When I run the agent with gpt-4 it can access to the memory, if I change the agent model to gtp-3.5-turbo I have this error: > I don't have access to the short-term memory ### Expected behavior Answer based on the memory
I don't have access to the short-term memory using Agent with gpt-3.5-turbo
https://api.github.com/repos/langchain-ai/langchain/issues/7996/comments
2
2023-07-20T10:46:50Z
2023-10-26T16:05:28Z
https://github.com/langchain-ai/langchain/issues/7996
1,813,694,849
7,996
[ "hwchase17", "langchain" ]
### System Info python 3.9 langchain 0.0.234 qdrant-client 1.1.7 ### Who can help? _No response_ ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction `client = qdrant_client.QdrantClient(self.qdrant_url, port=6333)` `qdrant = Qdrant( client=client, collection_name=self.collection_name, embeddings=embeddings, )` ### Expected behavior I'm getting this error since i upgrade my langchain to 0.0.234 from 0.0.233 <AioRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:6334: Failed to connect to remote host: Connection refused" debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:6334: Failed to connect to remote host: Connection refused {grpc_status:14, created_time:"2023-07-20T18:17:20.830536+08:00"}" I didn't change any code in my project. Is there any setting change? it seems that it connect to 6334 port of Qdrant
Can't connect to Qdrant since 0.0.234
https://api.github.com/repos/langchain-ai/langchain/issues/7995/comments
7
2023-07-20T10:30:28Z
2023-11-23T16:07:15Z
https://github.com/langchain-ai/langchain/issues/7995
1,813,665,397
7,995
[ "hwchase17", "langchain" ]
### System Info I am using the below code to make an agent that decides, upon the question, whether to use semantic search or pandas agent to answer the question about a dataset of employees ### 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 - [x] Tools / Toolkits - [x] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ``` semantic_retrieval_chain = RetrievalQA.from_llm( OpenAI(temperature=0), retriever=vectorstore.as_retriever(), return_source_documents=True, # memory=memory ) agg_df = pd.read_csv(TMP_FILE_PATH, index_col=0).iloc[:, :-1] aggregation_agent = create_pandas_dataframe_agent( OpenAI(temperature=0), agg_df, verbose=True, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION, include_df_in_prompt=True, # handle_parse_errors=True, # suffix="Assistant also handles parsing errors.", ) tools = [ Tool( name = "Semantic Search", func=semantic_retrieval_chain, description="""useful for retrieving employees similar to a given query specifications and answering questions not involving aggregations and operations over more than one employee""" ), Tool( name = "Aggregation Agent", func=aggregation_agent.run, description="useful for answering questions involving aggregations and descriptive statistics over more than one employee" ), ] llm=OpenAI(temperature=0) agent_chain = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, return_intermediate_steps=True, # memory=memory ) ``` I was able to successfully get the documents retrieved by the semantic search tool, but when I set the return_intermediate_step to True for the aggregation agent, I had the following error: **NotImplementedError: Saving not supported for this chain type.** ### Expected behavior I want to get the code for the pandas agent (aggregation_agent above) whenever it is invoked. I am extremely in need for this feature to be able to display the rows (if any) from the appropriate dataframe. Thanks in advance for any help.
Get the code applied by the pandas agent
https://api.github.com/repos/langchain-ai/langchain/issues/7994/comments
1
2023-07-20T10:19:46Z
2023-07-30T06:05:42Z
https://github.com/langchain-ai/langchain/issues/7994
1,813,647,909
7,994
[ "hwchase17", "langchain" ]
### System Info Langchain 0.0.237. Python 3.11 Mac OS X M1 ### Who can help? _No response_ ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction make start. INFO: Uvicorn running on http://127.0.0.1:9002 (Press CTRL+C to quit) INFO: Started reloader process [80851] using StatReload INFO: Started server process [80855] INFO: Waiting for application startup. in startup_event AttributeError: Can't get attribute '_default_relevance_score_fn' ### Expected behavior Load the chat. Note: the faiss wrapper seems updated back in May to from _default_relevance_score_fn to relevance_score_fn
ChatLangChain requesting _default_relevance_score_fn' on <module 'langchain.vectorstores.faiss> on init
https://api.github.com/repos/langchain-ai/langchain/issues/7992/comments
6
2023-07-20T09:32:36Z
2023-11-05T16:05:39Z
https://github.com/langchain-ai/langchain/issues/7992
1,813,565,399
7,992
[ "hwchase17", "langchain" ]
null
Does it support 文心一言?
https://api.github.com/repos/langchain-ai/langchain/issues/7990/comments
15
2023-07-20T08:59:25Z
2023-12-18T23:49:08Z
https://github.com/langchain-ai/langchain/issues/7990
1,813,507,242
7,990
[ "hwchase17", "langchain" ]
### System Info LangChain Python v0.0.237 Based on this code snippet it appears that OutputFixingParser doesn't support async flows. https://github.com/hwchase17/langchain/blob/df84e1bb64d96377f909651f696f310c43c2f2c5/langchain/output_parsers/fix.py#L46-L52 It's calling the run function and not arun ### Who can help? _No response_ ### Information - [ ] The official example notebooks/scripts - [X] My own modified scripts ### Related Components - [ ] LLMs/Chat Models - [ ] Embedding Models - [ ] Prompts / Prompt Templates / Prompt Selectors - [X] Output Parsers - [ ] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [X] Async ### Reproduction 1. Define async callback handler 2. Make LLM return output that is unparsable (invalid JSON or 2 code blocks) 3. OutputFixingParser will fail parsing the output and throw an exception, which will call the LLM via the run function which doesn't await on coroutines. Python will give the following error: ``` RuntimeWarning: coroutine 'AsyncCallbackHandler.on_chat_model_start' was never awaited ``` ### Expected behavior 1. Should work with coroutines as expected
OutputFixingParser is not async
https://api.github.com/repos/langchain-ai/langchain/issues/7989/comments
2
2023-07-20T08:29:12Z
2023-10-26T16:05:33Z
https://github.com/langchain-ai/langchain/issues/7989
1,813,454,976
7,989
[ "hwchase17", "langchain" ]
### System Info langchain==0.0.237 python==3.8.16 ### 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 - [X] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [X] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction same issue as https://github.com/hwchase17/langchain/issues/6984 but for Redis, but the proposed fix does not work llm = OpenAI(temperature=0.1) question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT) doc_chain = load_qa_with_sources_chain(llm, chain_type="stuff") retriever = db.as_retriever(search_kwargs={"k": 10}) chain = ConversationalRetrievalChain( retriever=retriever, #redis retriever question_generator=question_generator, combine_docs_chain=doc_chain, return_source_documents=True, ) ### Expected behavior query = "who slayed Karna in the battle?" result = chain({"question": query}) print(len(result['source_documents'])) #ouput: 4 but should be 10
Redis does not use the parameters passed in by Redis.as_retriever()
https://api.github.com/repos/langchain-ai/langchain/issues/7986/comments
2
2023-07-20T07:57:13Z
2023-12-09T16:42:25Z
https://github.com/langchain-ai/langchain/issues/7986
1,813,396,450
7,986
[ "hwchase17", "langchain" ]
### Feature request Almost all the chains offered in langchain framework support Verbose option which helps the developers understand what prompt is being applied under the hood and plan their work accordingly. It immensely help while debugging. create_extraction_chain is a very helpful one and I found this is not accepting verbose attribute. ### Motivation For many developers who are just following the langchain official documentation and not looking at the code used under the hood, this error will sound odd. Supporting this attribute will help in keeping things consistent and improve debugging feature of this chain ### Your contribution I can raise the PR for this ![Screenshot 2023-07-20 at 12 34 55 PM](https://github.com/hwchase17/langchain/assets/8801972/18b248df-1a7c-49cf-a9b1-3101e6928631)
TypeError: create_extraction_chain() got an unexpected keyword argument 'verbose'
https://api.github.com/repos/langchain-ai/langchain/issues/7982/comments
0
2023-07-20T06:39:12Z
2023-07-20T13:52:15Z
https://github.com/langchain-ai/langchain/issues/7982
1,813,275,803
7,982
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. How do you increase the max_tokens for the agent? I am using gpt35turbo16k. I notice that the model is only using ~4096 tokens. Is there a way to override this? The reason I am asking is I am ingesting large text in the prompt and the final answer I am getting is so short that does not have any meeting. Thanks! ### Suggestion: _No response_
Agent does not use max_tokens parameter from ChatOpenAI
https://api.github.com/repos/langchain-ai/langchain/issues/7981/comments
1
2023-07-20T05:58:45Z
2023-08-14T14:47:00Z
https://github.com/langchain-ai/langchain/issues/7981
1,813,216,875
7,981
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. ![image](https://github.com/hwchase17/langchain/assets/49942750/e6cf4a3a-da28-4133-9f3e-9b9998d0adb2) In Milvus, we are able to create databases and create collections within the database itself. Hence i will be able to create a collection with the same name in different databases. How can we specify the specific database and collection to use, currently the parameters only accept collection_name and not db_name like in pymilvus. ### Suggestion: _No response_
Issue: How to pass in database name parameter into Milvus
https://api.github.com/repos/langchain-ai/langchain/issues/7979/comments
14
2023-07-20T05:32:27Z
2024-08-05T08:13:51Z
https://github.com/langchain-ai/langchain/issues/7979
1,813,191,448
7,979
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. Hi, I'm trying to use some LLM model from huggingface, for example "model_name=lmsys/vicuna-13b-v1.3", in the chain `load_qa_chain`. The LLM model could be fetched through AutoModelForCausalLM.from_pretrained, e.g. ``` model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.bfloat16, device_map={"": 0}, ) ``` What's the best way (memory efficient) to wrap the model for integration with load_qa_chain? ### Suggestion: _No response_
Issue: integrate local LLM (from huggingface) into load_qa_chain
https://api.github.com/repos/langchain-ai/langchain/issues/7975/comments
2
2023-07-20T02:37:21Z
2023-10-26T16:05:38Z
https://github.com/langchain-ai/langchain/issues/7975
1,813,037,695
7,975
[ "hwchase17", "langchain" ]
### Issue you'd like to raise. I have a valid serpapi API key that I can use in the serpapi playground and with direct calls using python requests, but when I use it with Langchain I get an error saying that the key is invalid. I have my key set as environment variable, but I continue to get this error: ValueError: Got error from SerpAPI: Invalid API key. Your API key should be here: https://serpapi.com/manage-api-key I have even got a new API key with the same results. I have tried Pydroid3 for Android, Ubuntu in Termux for Android (64 bit), and Ubuntu in AWS ec2, with the same result. ### Suggestion: _No response_
Serpapi API key not working with Langchain
https://api.github.com/repos/langchain-ai/langchain/issues/7971/comments
5
2023-07-19T23:53:59Z
2024-05-12T16:22:03Z
https://github.com/langchain-ai/langchain/issues/7971
1,812,900,999
7,971
[ "hwchase17", "langchain" ]
### System Info LangChain version is the latest one - 0.0.237 ### 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 - [X] Document Loaders - [ ] Vector Stores / Retrievers - [ ] Memory - [ ] Agents / Agent Executors - [ ] Tools / Toolkits - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction ```python def text_split(documents): text_splitter = SpacyTextSplitter(chunk_size=1000, chunk_overlap=10, separator='\n') texts = [] for document in documents: texts.extend(text_splitter.split_documents(document.load())) return texts ``` Using this simple code, I get this error: ``` Traceback (most recent call last): ... File "/opt/project/main/genie.py", line 41, in text_split texts.extend(text_splitter.split_documents(document.load())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 131, in split_documents return self.create_documents(texts, metadatas=metadatas) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 116, in create_documents for chunk in self.split_text(text): ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain/text_splitter.py", line 1047, in split_text splits = (s.text for s in self._tokenizer(text).sents) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1030, in __call__ doc = self._ensure_doc(text) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1121, in _ensure_doc return self.make_doc(doc_like) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1113, in make_doc return self.tokenizer(text) ^^^^^^^^^^^^^^^^^^^^ TypeError: Argument 'string' has incorrect type (expected str, got lxml.etree._ElementUnicodeResult) ``` I've also tried approach with alternative `split_text` method, but still getting the same error. ### Expected behavior If I put a breakpoint at [langchain/text_splitter.py:116](https://github.com/hwchase17/langchain/blob/master/langchain/text_splitter.py#L116) and execute `text = str(text)` and resume the process, only then it works.
Argument 'string' has incorrect type (expected str, got lxml.etree._ElementUnicodeResult)
https://api.github.com/repos/langchain-ai/langchain/issues/7968/comments
4
2023-07-19T22:23:56Z
2023-10-28T16:04:55Z
https://github.com/langchain-ai/langchain/issues/7968
1,812,815,863
7,968
[ "hwchase17", "langchain" ]
### System Info Mac M2 Max 32GB ### Who can help? @rlancemartin ### 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 - [ ] Chains - [ ] Callbacks/Tracing - [ ] Async ### Reproduction We pass docs into a prompt, and pass prompt to an LLM chain: ``` # Prompt prompt = PromptTemplate.from_template( "Human: Summarize the main themes in these retrieved docs: {docs} Assistant: " ) # Chain llm_chain = LLMChain(llm=llm, prompt=prompt) # Run question = "What are the approaches to Task Decomposition?" docs = vectorstore.similarity_search(question) result = llm_chain(docs) ``` The doc metadata gets formatted w/ prompt and passed to LLM. This can cause hallucination (relative to intended doc page_content) if metadata contain irrelevant information. It also chews up tokens potentially with redundant information. See good example here: https://smith.langchain.com/public/9af32e5b-2ca9-41d9-a5a6-8243b218208a/r ### Expected behavior Only pass `page_content` from retrieved documents into the prompt.
Doc metadata can get passed into prompt unexpectedly
https://api.github.com/repos/langchain-ai/langchain/issues/7967/comments
1
2023-07-19T21:57:17Z
2023-10-25T16:05:37Z
https://github.com/langchain-ai/langchain/issues/7967
1,812,789,717
7,967