https://pantsbuild.org/ logo
#general
Title
# general
l

loud-spring-35539

03/22/2023, 10:37 PM
Do I need to specify a module_mapping (or something else) to get the following import to work?
from langchain.llms import BaseLLM, OpenAI
1
e

enough-analyst-54434

03/22/2023, 10:38 PM
If the PyPI project name is not equal to the root package name the answer is always yes. That's the algorithm.
Is it
langchain
on PyPI?
l

loud-spring-35539

03/22/2023, 10:39 PM
yeah, it's langchain on pypi
e

enough-analyst-54434

03/22/2023, 10:40 PM
So something more complex is going on.
l

loud-spring-35539

03/22/2023, 10:40 PM
The error received: `Could not import openai python package. Please it install it with
pip install openai
. (type=value_error)`
which makes no sense for that import
r

refined-addition-53644

03/22/2023, 10:42 PM
It’s optional so you need
langchain[openai]
https://github.com/hwchase17/langchain/blob/master/pyproject.toml#L43
l

loud-spring-35539

03/22/2023, 10:43 PM
I do have the
openai
package installed, but not
langchain[openai]
. I can give that a shot
e

enough-analyst-54434

03/22/2023, 10:43 PM
Thanks @refined-addition-53644. @loud-spring-35539 full command lines and output is always best going forward. That missing bit you added was crucial.
l

loud-spring-35539

03/22/2023, 10:45 PM
Copy code
15:43:41.74 [WARN] Pants cannot infer owners for the following imports in the target libs/compose/compose_model.py:

  * langchain.chains.LLMChain (line: 3)
  * langchain.llms.BaseLLM (line: 4)
  * langchain.llms.OpenAI (line: 4)
  * langchain.prompts.PromptTemplate (line: 5)
Imports
Copy code
from langchain.chains import LLMChain
from langchain.llms import BaseLLM, OpenAI
from langchain.prompts import PromptTemplate
r

refined-addition-53644

03/22/2023, 10:50 PM
How are you defining your python requirements?
requirements.txt
should look like
Copy code
langchain[openai]
# or
langchain[openai] == <required_version>
l

loud-spring-35539

03/22/2023, 10:50 PM
Copy code
python-liquid==1.8.*
openai
langchain
langchain[openai]
e

enough-analyst-54434

03/22/2023, 10:51 PM
Oh, langchain is you!
I thought it was 3rd party
Or is it not you?
l

loud-spring-35539

03/22/2023, 10:52 PM
it's third party
that's from my requirements.txt
r

refined-addition-53644

03/22/2023, 10:52 PM
I don’t think both
langchain
and
langchain[openai]
should be in there. Just use the extra one. Unless you’re explicitly importing
openai
somewhere in your code, you should also remove
openai
. Pants doesn’t play well with duplicate entries.
l

loud-spring-35539

03/22/2023, 10:55 PM
we do import openai explicitly in other files
👍 1
r

refined-addition-53644

03/22/2023, 10:55 PM
ok then keep that.
3 Views