msoedov / langcorn

⛓️ Serving LangChain LLM apps and agents automagically with FastApi. LLMops
https://langcorn.vercel.app/docs
MIT License
900 stars 67 forks source link

AttributeError: module 'examples.ex4' has no attribute 'chain' #1

Open aodrasa opened 1 year ago

aodrasa commented 1 year ago

Running into this error, any solution to get it running? Still fairly new to this and I'm sure it's straightforward fix.

Cheers 🙏

[INFO] 2023-04-20 11:17:29.78 | api:create_service:75 | Creating service
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/importer.py", line 31, in import_from_string
    instance = getattr(instance, attr_str)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'examples.ex4' has no attribute 'chain'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/langcorn", line 8, in <module>
    sys.exit(entrypoint())
             ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/langcorn/__main__.py", line 17, in entrypoint
    fire.Fire(T())
  File "/usr/local/lib/python3.11/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
                                ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/langcorn/__main__.py", line 9, in server
    app = api.create_service(*lc, auth_token=auth_token)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/langcorn/server/api.py", line 82, in create_service
    chain = import_from_string(lang_app)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/importer.py", line 34, in import_from_string
    raise ImportFromStringError(
uvicorn.importer.ImportFromStringError: Attribute "chain" not found in module "examples.ex4".
msoedov commented 1 year ago

Hi @aodrasa, Thx for asking this question! I believe an incorrectly specified application string caused the issue. It should be

"examples.ex4:sequential_chain"

since it declared as

sequential_chain = SequentialChain(
    chains=[requests_chain, llm_chain],
    input_variables=["query", "url"],
    output_variables=["text"],
    verbose=True,
)