Closed pradeepdev-1995 closed 10 months ago
Answer generated by a 🤖
I understand that you're encountering an error related to the OPENAI_API_KEY
while using the LangChain framework, even though you're not explicitly using an OpenAI model in your code. This could potentially be due to the LangChain framework trying to initialize an OpenAI model in the background.
One potential workaround for this issue could be to set a dummy OPENAI_API_KEY
environment variable before running your code. This might help bypass the error, although it's not a guaranteed solution. Here's how you can do it:
import os
os.environ['OPENAI_API_KEY'] = 'dummy_key'
# Your code here
If you have an OpenAI API key, you could also set it as an environment variable in your terminal:
export OPENAI_API_KEY="your_openai_api_key"
Or you can pass the key in directly via the openai_api_key
named parameter when initiating the OpenAI LLM class:
from langchain.llms import OpenAI
llm = OpenAI(openai_api_key="your_openai_api_key")
However, these are just workarounds and may not address the root cause of the issue. It would be beneficial to check the LangChain documentation or forums for more information on how to disable the OpenAI initialization when you're not using an OpenAI model.
In your shared context, it's mentioned that you can also use the PromptLayerOpenAI
LLM by setting the PROMPTLAYER_API_KEY
and OPENAI_API_KEY
environment variables. If you have access to these keys, you can set them as environment variables and use the PromptLayerOpenAI
LLM as shown:
from getpass import getpass
import os
from langchain.llms import PromptLayerOpenAI
PROMPTLAYER_API_KEY = getpass()
os.environ["PROMPTLAYER_API_KEY"] = PROMPTLAYER_API_KEY
OPENAI_API_KEY = getpass()
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
llm = PromptLayerOpenAI(pl_tags=["langchain"])
llm("I am a cat and I want")
This might help you bypass the error you're encountering. If you find that this is a bug that could impact other users, you might consider contributing a fix via a pull request.
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
The dummy key not working. When I added the dummy key, it shows the error
index = VectorstoreIndexCreator(
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for VectorstoreIndexCreator
embeddings
extra fields not permitted (type=value_error.extra)
Because I need to pass my own embeddings(not openai) SentenceTransformerEmbeddings
Answer generated by a 🤖
I understand that you're encountering a ValidationError
when trying to instantiate the VectorstoreIndexCreator
class in the LangChain framework. This error is occurring because the argument name for the embeddings should be embedding
and not embeddings
.
I suggest modifying your code as follows:
from langchain.indexes import VectorstoreIndexCreator
from langchain.vectorstores import Chroma
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings import SentenceTransformerEmbeddings
from langchain.llms import HuggingFaceHub
from langchain.document_loaders import PyPDFLoader
loader = PyPDFLoader("pdffile.pdf")
embeddings = SentenceTransformerEmbeddings(model_name="paraphrase-MiniLM-L6-v2")
model = HuggingFaceHub(repo_id="facebook/mbart-large-50",
model_kwargs={"temperature": 0, "max_length":200},
huggingfacehub_api_token=HUGGING_FACE_API_KEY)
index = VectorstoreIndexCreator(
embedding=embeddings,
vectorstore_cls=Chroma,
text_splitter=CharacterTextSplitter(chunk_size=100,chunk_overlap=0)
).from_loaders([loader])
result = index.query(llm=model, question=query, chain_type="refine")
Please note the change from embeddings=embeddings
to embedding=embeddings
in the VectorstoreIndexCreator
instantiation. This change should resolve the ValidationError
you're currently experiencing.
However, please keep in mind that while this solution should resolve your current issue, there may be other factors in your code or environment that could potentially cause other issues. If you find this solution helpful and believe it could benefit other users, feel free to contribute to the LangChain community by making a pull request.
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Worked it. Thank you
I'm also facing the same issue. I'm using a open source Llama2 model using HF pipeline, and using all-MiniLM-L6-v2
embeddings.
Posting relevent parts of code:
llm = HuggingFacePipeline(pipeline = pipeline, model_kwargs = {'temperature':0})
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
# create the open-source embedding function
embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
# load it into Chroma
store = Chroma.from_documents(pages, embedding_function, collection_name="property_tax_report")
vectorstore_info = VectorStoreInfo(
name="property_tax_report",
description="Property tax documents for JK",
vectorstore=store,
)
# Convert the document store into a langchain toolkit
toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info)
# Add the toolkit to an end-to-end LC
agent_executor = create_vectorstore_agent(llm=llm, toolkit=toolkit, verbose=True)
prompt = "what is the meaning of residential buildings"
agent_executor.run(prompt)
This wasn't working earlier with error:
Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)
I added a dummy api key as suggested, which is giving the following error:
AuthenticationError Traceback (most recent call last)
[<ipython-input-33-3e460594171e>](https://localhost:8080/#) in <cell line: 2>()
1 prompt = "what is the meaning of residential buildings"
----> 2 agent_executor.run(prompt)
3 # store.similarity_search_with_score(prompt)
4 # print(search[0][0].page_content)
39 frames
[/usr/local/lib/python3.10/dist-packages/openai/api_requestor.py](https://localhost:8080/#) in _interpret_response_line(self, rbody, rcode, rheaders, stream)
761 stream_error = stream and "error" in resp.data
762 if stream_error or not 200 <= rcode < 300:
--> 763 raise self.handle_error_response(
764 rbody, rcode, resp.data, rheaders, stream_error=stream_error
765 )
AuthenticationError: Incorrect API key provided: abcd. You can find your API key at https://platform.openai.com/account/api-keys.
Hi, @pradeepdev-1995! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you encountered an error related to the openai_api_key dependency when running your code with the langchain library. Initially, you tried setting a dummy OPENAI_API_KEY environment variable but encountered a validation error. However, you were able to resolve the issue by changing the argument name for the embeddings from "embeddings" to "embedding" in the VectorstoreIndexCreator instantiation. This solution worked for you.
Another user, abhi40308, also faced a similar issue and provided relevant code snippets. They added a dummy API key as suggested but encountered an AuthenticationError with an incorrect API key.
Now, we would like to know if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your contribution to the LangChain project!
In the following code I'm also getting the error of Error in qdrant_process_pdf_fast: 1 validation error for OpenAIEmbeddings
root
Did not find openai_api_key, please add an environment variable OPENAI_API_KEY
which contains it, or pass openai_api_key
as a named parameter. (type=value_error)
Can someone could help me?
class QdrantHelper: def init(self, collection, client=None, embeddings = None, vectorstore = None, llm=None, openai_api_key=None): self.client = client self.collection = collection self.embeddings = embeddings self.vectorstore = vectorstore self.llm = llm
print(print(OpenAI_key))
if self.embeddings is None:
self.embeddings = OpenAIEmbeddings(openai_api_key=OpenAI_key)
if self.client is None:
self.client = QdrantClient(QDRANT_URL, prefer_grpc= True, api_key=QDRANT_API)
if self.llm is None:
self.llm = OpenAI(temperature=0, openai_api_key=OpenAI_key)
def _initialize_client(self):
client = QdrantClient(QDRANT_URL, api_key=QDRANT_API)
return client
def convert_to_docs(self, loader):
docs = loader.load_and_split()
return docs
def create_db(self, loader, documents=None):
print("hello//////////////////")
if documents is None:
documents = docs = self.convert_to_docs(loader)
vectorstore = Qdrant.from_documents(
documents,
self.embeddings,
url=QDRANT_URL,
prefer_grpc=True,
api_key=QDRANT_API,
collection_name=self.collection,
)
self.vectorstore = vectorstore
return self.vectorstore
def get_ans_fast(self, query , model=None, k=4):
if model:
self.llm = OpenAI(temperature=0, openai_api_key=OpenAI_key, model=model)
if self.vectorstore is None:
self.vectorstore = Qdrant(
client= self.client, collection_name=self.collection,
embeddings= self.embeddings)
qa = VectorDBQA.from_chain_type(
llm=self.llm,
chain_type="stuff",
vectorstore= self.vectorstore,
return_source_documents=False
)
qa.k = k
return qa.run(query)
def get_ans_fast_with_credit(self, query, model=None, k=4):
try:
if model:
if model == "gpt-3.5-turbo":
self.llm = ChatOpenAI(temperature=0, openai_api_key=OpenAI_key, model="gpt-3.5-turbo")
else:
self.llm = OpenAI(temperature=0, openai_api_key=OpenAI_key, model=model)
print("API Key:", self.llm.openai_api_key)
print("API Base:", self.llm.openai_api_base)
print("Proxy:", self.llm.openai_proxy)
if self.vectorstore is None:
self.vectorstore = Qdrant(
client= self.client, collection_name=self.collection,
embeddings= self.embeddings)
qa = VectorDBQA.from_chain_type(
llm=self.llm,
chain_type="stuff",
vectorstore= self.vectorstore,
return_source_documents=False
)
qa.k = k
with get_openai_callback() as cb:
ans = qa.run(query)
return ans, cb
except Exception as e:
print(f"Error in get_ans_fast_with_credit: {e}")
print(e)
raise Exception(e)
def retrieve_db(self):
vectorstore = Qdrant(self.client, self.collection, embeddings=self.embeddings)
self.vectorstore = vectorstore
return vectorstore
def get_ans(self, query):
if self.vectorstore is None:
self.retrieve_db()
docs = self.vectorstore.similarity_search(query)
chain = load_qa_chain(self.llm, chain_type="stuff")
ans = chain.run(input_documents=docs, question=query)
return ans
I am also facing a similar challenge: from crewai import Agent, Task, Crew, Process import os
os.environ["OPENAI_API_KEY"] = "dummy_key"
from langchain_openai import ChatOpenAI from langchain_community.llms import Ollama from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()
llm_lmstudio = ChatOpenAI( openai_api_base="http://localhost:1234/v1", openai_api_key="", model_name="mistral" )
llm_janai = ChatOpenAI( openai_api_base="http://localhost:1337/v1", openai_api_key="", model_name="mistral-ins-7b-q4", )
llm_ollama = Ollama(model="orca2")
llm_textgen = ChatOpenAI( openai_api_base="http://localhost:5001/v1", openai_api_key="", model_name="openhermes", )
researcher = Agent( role="Senior Researcher", goal="Discover groundbreaking technologies", backstory="A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.", verbose=True, tools=[search_tool], allow_delegation=False, llm=llm_lmstudio, )
insight_researcher = Agent( role="Insight Researcher", goal="Discover Key Insights", backstory="You are able to find key insights from the data you are given.", verbose=True, allow_delegation=False, llm=llm_janai, )
writer = Agent( role="Tech Content Strategist", goal="Craft compelling content on tech advancements", backstory="""You are a content strategist known for making complex tech topics interesting and easy to understand.""", verbose=True, allow_delegation=False,
)
formater = Agent( role="Markdown Formater", goal="Format the text in markdown", backstory="You are able to convert the text into markdown format", verbose=True, allow_delegation=False,
)
research_task = Task( description="Identify the next big trend in AI by searching internet", agent=researcher, )
insights_task = Task( description="Identify few key insights from the data in points format. Dont use any tool", agent=insight_researcher, )
writer_task = Task( description="Write a short blog post with sub headings. Dont use any tool", agent=writer, )
format_task = Task( description="Convert the text into markdown format. Dont use any tool", agent=formater, )
tech_crew = Crew( agents=[researcher, insight_researcher, writer, formater], tasks=[research_task, insights_task, writer_task, format_task], process=Process.sequential, # Tasks will be executed one after the other )
result = tech_crew.kickoff() print(result)
here is the results i got:
Entering new CrewAgentExecutor chain... Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\HELLO\Desktop\test.py", line 102, in
Entering new CrewAgentExecutor chain... Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 851, in create_connection raise exceptions[0] File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions yield File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 898, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 915, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request with map_httpcore_exceptions(): File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\HELLO\Desktop\test.py", line 102, in
chunk: Output = context.run(next, iterator) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\runnables\base.py", line 2375, in _transform
for output in final_pipeline:
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\runnables\base.py", line 1035, in transform
for chunk in input:
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\runnables\base.py", line 4145, in transform
yield from self.bound.transform(
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\runnables\base.py", line 1045, in transform
yield from self.stream(final, config, kwargs)
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 250, in stream
raise e
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 234, in stream
for chunk in self._stream(
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\langchain_openai\chat_models\base.py", line 398, in _stream
for chunk in self.client.create(messages=message_dicts, *params):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_utils_utils.py", line 271, in wrapper
return func(args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai\resources\chat\completions.py", line 659, in create
return self._post(
^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 1180, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 869, in request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 922, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 993, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 922, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 993, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\HELLO\anaconda3\envs\myenv\Lib\site-packages\openai_base_client.py", line 932, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
Yep when I create a custom task, this issue appears immediately, it wants an open API key even though Im using my own local LLM, I even tried modifying, overriding the base class, - but somethign else is calling this initializing even when not calling OpenAI anywhere in the code.
I can only confirm that issue still exists. Right now I'm testing crewai framework but it is based on langchain... I wanted to use my azure open ai api key instead of openai api key but it constantly asking for open ai api key. I attempted to change lib files responsible for this issue but I failed. Also I had an idea let add my private openai key (it is not solution for me but let's make something work) and I got an error that my correct open ai api key is... invalid. Which is not true because it is working...I tested separately. Error message similar to what colleagues above have already shared.
I think this fixed it for me:
raw_documents = CSVLoader(file_path="./somedata.csv").load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
documents = text_splitter.split_documents(raw_documents)
db = FAISS.from_documents(documents, OpenAIEmbeddings(openai_api_key="sk-xxxxxx"))
result = db.similarity_search( [query] )
This issue still persists, and im using an OpenAI Model with an OPENAI_API_KEY. But this only occurs in my docker and EC2 instance, but runs fine locally.
System Info
I am trying to build a VectorstoreIndexCreator using the following configuration
embeddings= SentenceTransformerEmbeddings embeddings vectorstore_cls = Chroma llm = HuggingfaceHub Model
Note: I am not using any openai model as llm or embedding purpose
here is the code
But still iam getting the open_ai key dependency error when i run the code
using langchain version: langchain==0.0.219
Who can help?
No response
Information
Related Components
Reproduction
Expected behavior
Dont show any openai error