jina-ai / jina

☁️ Build multimodal AI applications with cloud-native stack
https://docs.jina.ai
Apache License 2.0
21k stars 2.22k forks source link

How to import logic from other modules in executor.py ? #6109

Closed that-rahul-guy closed 10 months ago

that-rahul-guy commented 10 months ago

Describe your proposal/problem

Cannot import my custom logic from other modules in executor.py. Here's my executor.py:

from jina import Executor, requests
from docarray import DocList
from docarray.documents import TextDoc
from fake_agent import predict

class MyExecutor(Executor):
    @requests(on='/prompt')
    def promt(self, docs: DocList[TextDoc], **kwargs) -> DocList[TextDoc]:
        print(docs.text)
        docs.text = [predict(a) for a in docs.text]
        # docs[1].text = 'goodbye, world!'
        return docs

This is the project structure:

Project
|   client.py
|   deployment.yml
|   tree.txt
|   
+---executor1
|     |   config.yml
|     |   executor.py
|     |   fake_agent.py
|     |   requirements.txt
|     |   
|     \---__pycache__
|          |  executor.cpython-39.pyc
|           
\---__pycache__
           | client.cpython-39.pyc

I'm serving the executor using jina deployment --uses deployment.yml
But I'm getting ImportError:

ImportError('can not import module from 
       C:\\Users\\Lenovo\\Desktop\\jina-exp\\executor1\\executor.py') during 'WorkerRuntime'
       initialization
        add "--quiet-error" to suppress the exception details
       Traceback (most recent call last):
         File "C:\programs\anaconda\envs\jina_llm\lib\site-packages\jina\importer.py", line 149, in _path_import
           spec.loader.exec_module(module)
         File "<frozen importlib._bootstrap_external>", line 790, in exec_module
         File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
         File "C:\Users\Lenovo\Desktop\jina-exp\executor1\executor.py", line 4, in <module>
           from fake_agent import predict
       ModuleNotFoundError: No module named 'fake_agent'

which eventually is causing

jina.excepts.RuntimeFailToStart

What am I doing wrong? Please guide me to appropriate docs or issues regarding this if exists.


Environment

JoanFM commented 10 months ago

Hey @that-rahul-guy, have u checked this documentarion? I believe you will find it useful.

https://docs.jina.ai/concepts/serving/executor/file-structure/#multiple-python-files-yaml

that-rahul-guy commented 10 months ago

Hi @JoanFM Thanks for guiding me to appropriate doc. I was looking for this only.

This issue can be closed.