benman1 / generative_ai_with_langchain

Build large language model (LLM) apps with Python, ChatGPT and other models. This is the companion repository for the book on generative AI with LangChain.
https://amzn.to/43PuIkQ
MIT License
600 stars 242 forks source link

Dependency problems #49

Closed srgonzalezz closed 3 months ago

srgonzalezz commented 3 months ago

Dependency problems Despite having followed all the steps in chapter 3 where it explains how to configure all the dependencies, having taken the conda option and subsequently having checked that I have the versions specified in the requirements file, I am having many problems, which are making it difficult for me to follow the proposed practice.

To Reproduce On a Jupyter Notebook I copy the code block on page 103, under the heading "Basic Prompting".

from langchain_decorators import llm_prompt
@llm_prompt
def summarize(text:str, length="short") -> str:
 """
 Summarize this text in {length} length:
 {text}
 """
 return
summary = summarize(text="let me tell you a boring story from when I was young...")

Expected behavior I was hoping a similar respond to specified on the book: " The speaker is about to share a story from their youth"

Error I have the following error:

{
    "name": "ImportError",
    "message": "cannot import name 'BaseModel' from 'openai' (c:\\Users\\srg30\\anaconda3\\envs\\langchain_ai\\lib\\site-packages\\openai\\__init__.py)",
    "stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from langchain_decorators import llm_prompt
      2 @llm_prompt
      3 def summarize(text:str, length=\"short\") -> str:
      4  \"\"\"
      5  Summarize this text in {length} length:
      6  {text}
      7  \"\"\"

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_decorators\\__init__.py:3
      1 from .common import LogColors, GlobalSettings, print_log, PromptTypes, PromptTypeSettings, LlmSelector
      2 from .schema import OutputWithFunctionCall
----> 3 from .prompt_decorator import PromptDecoratorTemplate
      4 from .streaming_context import StreamingContext
      5 from .prompt_decorator import llm_prompt

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_decorators\\prompt_decorator.py:14
     10 from langchain.schema import BaseOutputParser
     11 from langchain.llms.base import BaseLanguageModel
---> 14 from .chains import LLMDecoratorChainWithFunctionSupport, LLMDecoratorChain, RequestRetry
     15 from .common import *
     16 from .prompt_template import PromptDecoratorTemplate

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_decorators\\chains.py:18
     16 from langchain.prompts.chat import  ChatPromptValue
     17 from langchain.schema import ChatGeneration, BaseMessage, HumanMessage, AIMessage
---> 18 from promptwatch import CachedChatLLM, register_prompt_template
     19 from .common import LlmSelector, print_log, LogColors, PromptTypeSettings, PromptTypes
     20 from .schema import OutputWithFunctionCall

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\promptwatch\\__init__.py:6
      3 from .client import Client
      4 from .data_model import Action, Answer, ChainSequence, LlmPrompt, ParallelPrompt, RetrievedDocuments, Question
----> 6 from .langchain.langchain_support import (
      7     register_prompt_template,
      8     find_and_register_templates_recursive,
      9     find_templates_recursive,
     10     CachedLLM,
     11     CachedChatLLM,
     12 )
     15 __version__ = \"0.4.5\"

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\promptwatch\\langchain\\__init__.py:1
----> 1 from .langchain_support import register_prompt_template, find_templates_recursive, find_and_register_templates_recursive,  CachedLLM, CachedChatLLM, LangChainCallbackHandler
      2 from .caching import CachedLLM, CachedChatLLM

File ~\\AppData\\Roaming\\Python\\Python310\\site-packages\\promptwatch\\langchain\\langchain_support.py:33
     31 from langchain.schema import Document, HumanMessage, LLMResult, SystemMessage
     32 from langchain.tools.base import BaseTool
---> 33 from openai import BaseModel
     35 from ..client import Client
     36 from ..data_model import (Action, Answer, ChainSequence, ChatMessage,
     37                           ChatMessagePromptTemplate, DocumentSnippet,
     38                           LlmPrompt, NamedPromptTemplateDescription,
     39                           ParallelPrompt, PromptTemplateDescription, Question,
     40                           RetrievedDocuments)

ImportError: cannot import name 'BaseModel' from 'openai' (c:\\Users\\srg30\\anaconda3\\envs\\langchain_ai\\lib\\site-packages\\openai\\__init__.py)"
}

Software environment

The list installed packages of the langchain_ai environment with conda:

Package Version ---------------------------------------- --------------- aiofiles 23.2.1 aiohttp 3.9.5 aiohttp-cors 0.7.0 aiosignal 1.3.1 altair 5.3.0 annotated-types 0.7.0 anyio 4.4.0 apify_client 1.7.0 apify_shared 1.1.2 argon2-cffi 23.1.0 argon2-cffi-bindings 21.2.0 arrow 1.3.0 arxiv 2.1.3 asgiref 3.8.1 asttokens 2.4.1 async-lru 2.0.4 async-timeout 4.0.3 attrs 23.2.0 Babel 2.15.0 backoff 2.2.1 backports.tarfile 1.2.0 bcrypt 4.1.3 beautifulsoup4 4.12.3 bleach 6.1.0 blinker 1.8.2 build 1.2.1 cachetools 5.3.3 certifi 2024.7.4 cffi 1.16.0 chardet 5.2.0 charset-normalizer 3.3.2 chroma-hnswlib 0.7.3 chromadb 0.5.3 click 8.1.7 colorama 0.4.6 coloredlogs 15.0.1 colorful 0.5.6 comm 0.2.2 contourpy 1.2.1 cycler 0.12.1 dataclasses-json 0.5.14 dataclasses-json-speakeasy 0.5.11 debugpy 1.8.2 decorator 5.1.1 defusedxml 0.7.1 Deprecated 1.2.14 distlib 0.3.8 distro 1.9.0 dnspython 2.6.1 docarray 0.32.1 docstring_parser 0.16 duckduckgo_search 6.1.9 email_validator 2.2.0 emoji 2.12.1 exceptiongroup 1.2.1 executing 2.0.1 faiss-cpu 1.8.0.post1 fastapi 0.111.0 fastapi-cli 0.0.4 fastjsonschema 2.20.0 feedparser 6.0.11 ffmpy 0.3.2 filelock 3.15.4 filetype 1.2.0 flatbuffers 24.3.25 fonttools 4.53.1 fqdn 1.5.1 frozenlist 1.4.1 fsspec 2024.6.1 gitdb 4.0.11 GitPython 3.1.43 google-ai-generativelanguage 0.6.6 google-api-core 2.19.1 google-api-python-client 2.136.0 google-auth 2.31.0 google-auth-httplib2 0.2.0 google-cloud-aiplatform 1.58.0 google-cloud-bigquery 3.25.0 google-cloud-core 2.4.1 google-cloud-resource-manager 1.12.3 google-cloud-storage 2.17.0 google-crc32c 1.5.0 google-generativeai 0.7.1 google-resumable-media 2.7.1 googleapis-common-protos 1.63.2 gpt4all 2.7.0 gradio 4.14.0 gradio_client 0.8.0 greenlet 3.0.3 grpc-google-iam-v1 0.13.1 grpcio 1.64.1 grpcio-status 1.62.2 h11 0.14.0 hnswlib 0.8.0 httpcore 1.0.5 httplib2 0.22.0 httptools 0.6.1 httpx 0.27.0 huggingface-hub 0.23.4 humanfriendly 10.0 idna 3.7 importlib_metadata 7.1.0 importlib_resources 6.4.0 intel-openmp 2021.4.0 ipykernel 6.29.5 ipython 8.26.0 ipywidgets 8.1.3 isoduration 20.11.0 jaraco.context 5.3.0 jedi 0.19.1 Jinja2 3.1.4 joblib 1.4.2 json5 0.9.25 jsonpatch 1.33 jsonpath-python 1.0.6 jsonpointer 3.0.0 jsonschema 4.22.0 jsonschema-specifications 2023.12.1 jupyter 1.0.0 jupyter_client 8.6.2 jupyter-console 6.6.3 jupyter_core 5.7.2 jupyter-events 0.10.0 jupyter-lsp 2.2.5 jupyter_server 2.14.1 jupyter_server_terminals 0.5.3 jupyterlab 4.2.3 jupyterlab_pygments 0.3.0 jupyterlab_server 2.27.2 jupyterlab_widgets 3.0.11 kiwisolver 1.4.5 kubernetes 30.1.0 lanarky 0.7.16 langchain 0.0.284 langchain-core 0.0.1 langchain-decorators 0.2.3 langchain-experimental 0.0.25 langchain-text-splitters 0.0.1 langdetect 1.0.9 langsmith 0.0.65 lxml 5.2.2 markdown-it-py 3.0.0 MarkupSafe 2.1.5 marshmallow 3.21.3 matplotlib 3.9.1 matplotlib-inline 0.1.7 mdurl 0.1.2 mistune 3.0.2 mkl 2021.4.0 mmh3 4.1.0 monotonic 1.6 more-itertools 10.3.0 mpmath 1.3.0 msgpack 1.0.8 multidict 6.0.5 mypy-extensions 1.0.0 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 nest-asyncio 1.6.0 networkx 3.3 nltk 3.8.1 notebook 7.2.1 notebook_shim 0.2.4 numexpr 2.10.1 numpy 1.26.4 oauthlib 3.2.2 onnxruntime 1.18.1 openai 0.28.1 opencensus 0.11.4 opencensus-context 0.1.3 opentelemetry-api 1.25.0 opentelemetry-exporter-otlp-proto-common 1.25.0 opentelemetry-exporter-otlp-proto-grpc 1.25.0 opentelemetry-instrumentation 0.46b0 opentelemetry-instrumentation-asgi 0.46b0 opentelemetry-instrumentation-fastapi 0.46b0 opentelemetry-proto 1.25.0 opentelemetry-sdk 1.25.0 opentelemetry-semantic-conventions 0.46b0 opentelemetry-util-http 0.46b0 orjson 3.10.6 overrides 7.7.0 packaging 23.2 pandas 2.2.2 pandoc 2.3 pandocfilters 1.5.1 parso 0.8.4 pillow 10.4.0 pip 23.1.2 platformdirs 4.2.2 plumbum 1.8.3 ply 3.11 posthog 3.5.0 prometheus_client 0.20.0 prompt_toolkit 3.0.47 promptwatch 0.4.5 proto-plus 1.24.0 protobuf 4.25.3 psutil 6.0.0 pure-eval 0.2.2 py-spy 0.3.14 pyarrow 16.1.0 pyasn1 0.6.0 pyasn1_modules 0.4.0 pycparser 2.22 pydantic 2.8.2 pydantic_core 2.20.1 pydeck 0.9.1 pydub 0.25.1 Pygments 2.18.0 pyparsing 3.1.2 pypdf 4.2.0 PyPika 0.48.9 pyproject_hooks 1.1.0 pyreadline 2.1 pyreadline3 3.4.1 pyreqwest_impersonate 0.4.9 python-dateutil 2.9.0.post0 python-dotenv 1.0.1 python-iso639 2024.4.27 python-json-logger 2.0.7 python-magic 0.4.27 python-multipart 0.0.9 pytz 2024.1 pywin32 306 pywinpty 2.0.13 PyYAML 6.0.1 pyzmq 26.0.3 qtconsole 5.5.2 QtPy 2.4.1 rapidfuzz 3.9.4 ray 2.31.0 referencing 0.35.1 regex 2024.5.15 replicate 0.28.0 requests 2.32.3 requests-oauthlib 2.0.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.7.1 rpds-py 0.18.1 rsa 4.9 ruff 0.0.278 safetensors 0.4.3 scikit-learn 1.5.1 scipy 1.14.0 semantic-version 2.10.0 Send2Trash 1.8.3 sentence-transformers 3.0.1 setuptools 67.8.0 sgmllib3k 1.0.0 shapely 2.0.4 shellingham 1.5.4 six 1.16.0 smart-open 7.0.4 smmap 5.0.1 sniffio 1.3.1 soupsieve 2.5 SQLAlchemy 2.0.31 stack-data 0.6.3 starlette 0.37.2 streamlit 1.36.0 sympy 1.12.1 tabulate 0.9.0 tbb 2021.13.0 tenacity 8.5.0 terminado 0.18.1 threadpoolctl 3.5.0 tiktoken 0.7.0 tinycss2 1.3.0 tokenizers 0.19.1 toml 0.10.2 tomli 2.0.1 tomlkit 0.12.0 toolz 0.12.1 torch 2.3.1 tornado 6.4.1 tqdm 4.66.4 traitlets 5.14.3 transformers 4.42.3 typer 0.12.3 types-python-dateutil 2.9.0.20240316 types-requests 2.32.0.20240622 typing_extensions 4.12.2 typing-inspect 0.9.0 tzdata 2024.1 ujson 5.10.0 unstructured 0.14.9 unstructured-client 0.18.0 uri-template 1.3.0 uritemplate 4.1.1 urllib3 2.2.2 uvicorn 0.30.1 virtualenv 20.26.3 watchdog 4.0.1 watchfiles 0.22.0 wcwidth 0.2.13 webcolors 24.6.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 urllib3 2.2.2 uvicorn 0.30.1 virtualenv 20.26.3 watchdog 4.0.1 watchfiles 0.22.0 wcwidth 0.2.13 webcolors 24.6.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 virtualenv 20.26.3 watchdog 4.0.1 watchfiles 0.22.0 wcwidth 0.2.13 webcolors 24.6.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 watchfiles 0.22.0 wcwidth 0.2.13 webcolors 24.6.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 webcolors 24.6.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 websocket-client 1.8.0 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 websockets 11.0.3 wheel 0.38.4 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 widgetsnbextension 4.0.11 wikipedia 1.4.0 wolframalpha 5.1.3 wikipedia 1.4.0 wolframalpha 5.1.3 wolframalpha 5.1.3 wrapt 1.16.0 xmltodict 0.13.0 yarl 1.9.4 zipp 3.19.2

Additional context I have made sure that I have all the dependencies installed in the required versions.

srgonzalezz commented 3 months ago

Hello @benman1,

I deleted the environment in conda and redid the process from the beginning and it seems that the problems I had related to imports and dependencies have been solved.

:facepalm: