Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
that-rahul-guy opened this issue Nov 15, 2023 · 2 comments
Closed

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

that-rahul-guy opened this issue Nov 15, 2023 · 2 comments

Comments

@that-rahul-guy
Copy link

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

  • jina 3.22.4
  • docarray 0.39.1
  • jcloud 0.3
  • jina-hubble-sdk 0.39.0
  • jina-proto 0.1.27
  • protobuf 4.25.0
  • proto-backend upb
  • grpcio 1.47.5
  • pyyaml 6.0.1
  • python 3.9.0
  • platform Windows
  • platform-release 10
  • platform-version 10.0.19041
  • architecture AMD64
  • processor Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
  • uid 273085306477006
  • session-id be030012-83e9-11ee-bc64-f85ea0af99ce
  • uptime 2023-11-16T00:34:02.782899
  • ci-vendor (unset)
  • internal False
  • JINA_DEFAULT_HOST (unset)
  • JINA_DEFAULT_TIMEOUT_CTRL (unset)
  • JINA_DEPLOYMENT_NAME (unset)
  • JINA_DISABLE_UVLOOP (unset)
  • JINA_EARLY_STOP (unset)
  • JINA_FULL_CLI (unset)
  • JINA_GATEWAY_IMAGE (unset)
  • JINA_GRPC_RECV_BYTES (unset)
  • JINA_GRPC_SEND_BYTES (unset)
  • JINA_HUB_NO_IMAGE_REBUILD (unset)
  • JINA_LOG_CONFIG (unset)
  • JINA_LOG_LEVEL (unset)
  • JINA_LOG_NO_COLOR (unset)
  • JINA_MP_START_METHOD (unset)
  • JINA_OPTOUT_TELEMETRY (unset)
  • JINA_RANDOM_PORT_MAX (unset)
  • JINA_RANDOM_PORT_MIN (unset)
  • JINA_LOCKS_ROOT (unset)
  • JINA_K8S_ACCESS_MODES (unset)
  • JINA_K8S_STORAGE_CLASS_NAME (unset)
  • JINA_K8S_STORAGE_CAPACITY (unset)
  • JINA_STREAMER_ARGS (unset)
@JoanFM
Copy link
Member

JoanFM commented Nov 15, 2023

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
Copy link
Author

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

This issue can be closed.

@JoanFM JoanFM closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants