Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAIEmbeddings #13082

Closed
5 of 14 tasks
paritoshk opened this issue Nov 8, 2023 · 4 comments
Closed
5 of 14 tasks

OpenAIEmbeddings #13082

paritoshk opened this issue Nov 8, 2023 · 4 comments
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: embeddings Related to text embedding models module Ɑ: models Related to LLMs or chat model modules

Comments

@paritoshk
Copy link

System Info

Traceback:
File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.dict)
File "/app/demo-chatbot/updatedapp.py", line 351, in
asyncio.run(main())
File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "/app/demo-chatbot/updatedapp.py", line 214, in main
vectors = file.get_vector()
File "/app/demo-chatbot/file.py", line 39, in get_vector
self.save_vector()
File "/app/demo-chatbot/file.py", line 30, in save_vector
embeddings = OpenAIEmbeddings(openai_api_key=st.secrets["OPEN_AI_KEY"])
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.init
File "pydantic/main.py", line 1102, in pydantic.main.validate_model
File "/home/appuser/venv/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 166, in validate_environment
values["client"] = openai.Embedding

Who can help?

@agola11 OpenAI changed the code https://platform.openai.com/docs/guides/embeddings/what-are-embeddings

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

Just follow a funciton similar to

def save_vector(self):
    self.create_images()
    self.extract_text()
    loader = TextLoader(f"{self.dir}/info.txt")
    documents = loader.load()
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
    documents = text_splitter.split_documents(documents)
    embeddings = OpenAIEmbeddings()
    vectors = FAISS.from_documents(documents, embeddings)

Expected behavior

No traceback adding .create

Copy link

dosubot bot commented Nov 8, 2023

🤖

Hello @paritoshk,

Nice to meet you! I'm a bot designed to assist with issues related to the LangChain repository. While we're waiting for a human maintainer, I'm here to help you troubleshoot bugs, answer any questions you have, and even guide you on how to contribute to the project. I'm currently reviewing the issue you've posted and will provide a comprehensive response shortly. Thanks for your patience!

@dosubot dosubot bot added Ɑ: agent Related to agents module Ɑ: embeddings Related to text embedding models module Ɑ: models Related to LLMs or chat model modules 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Nov 8, 2023
Copy link

dosubot bot commented Nov 8, 2023

🤖

Based on the traceback you provided, it seems like the error is occurring when you're trying to initialize the OpenAIEmbeddings class. The error message suggests that there might be an issue with the openai_api_key you're using.

From the context provided, it appears that there have been similar issues in the past where the OpenAI API key was not correctly set or the OpenAI Python package was not available. The OpenAIEmbeddings class in the LangChain codebase validates the environment to ensure that the OpenAI API key and the OpenAI Python package are available. If these are not set correctly, it could lead to the error you're experiencing.

Here are a few things you could check:

  1. OpenAI API Key: Make sure that the openai_api_key you're using is correct and has the necessary permissions. You can check this in your OpenAI account.

  2. OpenAI Python Package: Ensure that the OpenAI Python package is installed in your environment. You can do this by running pip show openai in your terminal. If it's not installed, you can install it using pip install openai.

  3. Environment Variables: If you're using environment variables to set the openai_api_key, make sure that they are being correctly loaded in your environment.

If you've checked all of these and the issue still persists, it would be helpful if you could provide more information about your environment and the exact steps you're following when the error occurs. This would help in diagnosing the issue further.

As for the changes in the OpenAI API, I wasn't able to find specific information about this in the LangChain repository. However, you mentioned that OpenAI has changed the code. Could you provide more details about these changes? This could help in understanding if they are related to the issue you're experiencing.

Regarding the save_vector function you provided, it seems to be using the OpenAIEmbeddings class correctly. However, without more context, it's hard to say if there might be an issue with how it's being used in your specific case. If you could provide more details about how you're using this function and the context in which it's being used, it would be helpful.

I hope this helps! Let me know if you have any other questions or if there's anything else I can do to assist you.

Sources


This response is meant to be useful and save you time. 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.

If you want to continue the conversation, start your reply with @dosu-bot.

@baskaryan
Copy link
Collaborator

@paritoshk do you still see this with langchain==0.0.333

Copy link

dosubot bot commented Feb 8, 2024

Hi, @paritoshk,

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you raised an issue regarding a traceback error in the OpenAIEmbeddings module and sought assistance from @agola11. There have been responses from @dosubot and @baskaryan, with troubleshooting suggestions and a query about the error persisting with a specific version of LangChain.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, kindly let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 8, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: embeddings Related to text embedding models module Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests

2 participants