langflow icon indicating copy to clipboard operation
langflow copied to clipboard

I want to add new model provider to the list of the components

Open chibexme opened this issue 1 year ago • 10 comments

Title

How to successfully add new model provider to the components list

Type

New Feature

Description

I have looked at the way other model providers were added and replicated same approach but my model provider did not get to display on the component list.

Going through /api/vi/all?force_refresh=false endpoint implementation, i found out that the components are been cached by CacheService.

Setting /api/v1/force_refresh=true did not clear cache

Use Case

No response

Implementation Plan

No response

chibexme avatar Aug 02 '24 11:08 chibexme

Hey @chibexme, have you tried creating a Python file inside the components directory in the backend source code? You can check out the directory structure here

anovazzi1 avatar Aug 05 '24 23:08 anovazzi1

Hi @anovazzi1, yes I did image

I created new model provider component following the whole processes others were created.

But after starting the services through docker compose, my new component doesn't get listed.

During my tracking I found that this endpoint is called fetch all components.

/api/v1/all?force_refresh=false

Going through the codebase in the endpoints.py revealed that CacheService is used in caching the components and the when cache is empty or force_refresh query string is set to true, the cache get recreated

if tried setting force_refresh query string is set to true but nothing changed.

My question is where is cached data store? inside docker container or in a file somewhere?

what steps should i follow to get my new component shown on the frontend?

Thanks in anticipation.

chibexme avatar Aug 06 '24 21:08 chibexme

If you are using docker you might need to rebuild your docker image, you are probably using a version that does not contain your newly created files.

Try something like:

docker compose up --build

vasconceloscezar avatar Aug 06 '24 21:08 vasconceloscezar

Hi @vasconceloscezar, this is the error message I got while trying to run the command

docker-compose up --build [+] Building 1.1s (11/11) FINISHED docker:default => [backend internal] load build definition from build_and_push_backend.Dockerfile 0.0s => => transferring dockerfile: 55B 0.0s => [celeryworker internal] load build definition from build_and_push_backend.Dockerfile 0.0s => => transferring dockerfile: 55B 0.0s => [backend internal] load .dockerignore 0.0s => => transferring context: 34B 0.0s => [flower internal] load build definition from build_and_push_backend.Dockerfile 0.0s => => transferring dockerfile: 55B 0.0s => [celeryworker internal] load .dockerignore 0.0s => => transferring context: 34B 0.0s => [flower internal] load .dockerignore 0.0s => => transferring context: 34B 0.0s => [backend] resolve image config for docker.io/docker/dockerfile:1 0.7s => CACHED [flower] docker-image://docker.io/docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28 0.0s => [celeryworker internal] load build definition from build_and_push_backend.Dockerfile 0.0s => [backend internal] load build definition from build_and_push_backend.Dockerfile 0.0s => [flower internal] load build definition from build_and_push_backend.Dockerfile 0.0s failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = base name ($LANGFLOW_IMAGE) should not be blank

I have LANGFLOW_IMAGE set in the env file

chibexme avatar Aug 08 '24 08:08 chibexme

@vasconceloscezar upgraded my docker compose and was able to build but still my changes didn't reflect. Even, print statements i included in the api/v1/all endpoint are not printing on the terminal.

chibexme avatar Aug 12 '24 12:08 chibexme

I logged in to the backend running container and my custom component is not available there as can be seen in the below image

It may mean that langflow is download official langflow package and ignoring mine.

Screenshot 2024-08-12 154312

chibexme avatar Aug 12 '24 14:08 chibexme

scripts/update_dependencies.py will replace the langflow-base version.

[tool.poetry.dependencies]
python = ">=3.10,<3.13"
langflow-base = { path = "./src/backend/base", develop = true }
def update_pyproject_dependency(pyproject_path, version):
    pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}')
    replacement = f'langflow-base = "^{version}"'
    with open(pyproject_path, "r") as file:
        content = file.read()
    content = pattern.sub(replacement, content)
    with open(pyproject_path, "w") as file:
        file.write(content)

lawnvi avatar Aug 29 '24 09:08 lawnvi

@lawnvi thanks for your observations, but what will it replace it with and how can I stop it? Is there any affect if I remove or comment out that portion of code?

I've struggled with this for a month now, finally got a workaround just yesterday.

From the below screenshot, I noticed that langflow-base which probably contains my customization was uninstalled.

I did listing of the component directory from my copying source and my custom component was there.

Screenshot 2024-08-30 102248

The temporary workaround. Screenshot 2024-08-30 102915

After installation of the required packages, I just copied the directories I made changes on, to the container.

This works for me for now, until I find a better solution or how to not allow langflow-base be replaced.

Thanks.

chibexme avatar Aug 30 '24 09:08 chibexme

@chibexme I remove develop = true before python update_dependencies.py, here is part of my docker file.

RUN  sed -i 's|langflow-base = { path = "./src/backend/base", develop = true }|langflow-base = { path = "./src/backend/base" }|g' pyproject.toml \
    && python -m pip install requests && cd ./scripts && python update_dependencies.py

or just comment out update_pyproject_dependency in update_dependencies.py.

if __name__ == "__main__":
    # Backing up files
    pyproject_path = Path(__file__).resolve().parent / "../pyproject.toml"
    pyproject_path = pyproject_path.resolve()
    with open(pyproject_path, "r") as original, open(pyproject_path.with_name("pyproject.toml.bak"), "w") as backup:
        backup.write(original.read())
    # Now backup poetry.lock
    with open(pyproject_path.with_name("poetry.lock"), "r") as original, open(
        pyproject_path.with_name("poetry.lock.bak"), "w"
    ) as backup:
        backup.write(original.read())

    # Reading version and updating pyproject.toml
    langflow_base_path = Path(__file__).resolve().parent / "../src/backend/base/pyproject.toml"
    version = read_version_from_pyproject(langflow_base_path)
    # if version:
    #     update_pyproject_dependency(pyproject_path, version)
    # else:
    #     print("Error: Version not found.")

lawnvi avatar Aug 30 '24 16:08 lawnvi

@chibexme

Do you need any assistance with this case? If not, please let us know if this issue can be closed.

carlosrcoelho avatar Sep 05 '24 15:09 carlosrcoelho