Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ lite/jupyterlite-icortex/style/icortex.png
lite/jupyterlite-icortex/LICENSE
node_modules/
*.tsbuildinfo
*_backup
1 change: 0 additions & 1 deletion icortex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from icortex.kernel import ICortexKernel, print_help, get_icortex_kernel

# from icortex.cli import set_icortex_service, eval_cli
import icortex.services
import importlib.metadata

Expand Down
13 changes: 2 additions & 11 deletions icortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@
import shlex
import sys
import argparse
from jupyter_console.app import ZMQTerminalIPythonApp
from icortex.services import get_available_services
from icortex.defaults import DEFAULT_ICORTEX_CONFIG_PATH
from icortex.install import is_kernel_installed, main as install_kernel
from icortex.kernel.install import is_kernel_installed, main as install_kernel
from icortex.config import ICortexConfig

# Jupyter devs did not make this easy
# TODO: Make less hacky
class ZMQTerminalICortexApp(ZMQTerminalIPythonApp):
def parse_command_line(self, argv=None):
argv = ["--kernel", "icortex"]
super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
self.build_kernel_argv(self.extra_args)


def get_parser(prog=None):
service_names = get_available_services()
Expand Down Expand Up @@ -150,7 +141,6 @@ def get_parser(prog=None):


# def set_icortex_service(kernel, config_path=DEFAULT_ICORTEX_CONFIG_PATH):

# if kernel is not None:
# return ICortexConfig(DEFAULT_ICORTEX_CONFIG_PATH).set_service()
# return False
Expand Down Expand Up @@ -195,6 +185,7 @@ def main(argv=None, prog=None, kernel=None):
parser.print_help()
elif args.command == "shell" or args.command is None:
from icortex.kernel import get_icortex_kernel
from icortex.kernel.app import ZMQTerminalICortexApp

kernel = get_icortex_kernel()
if kernel is None:
Expand Down
14 changes: 7 additions & 7 deletions icortex/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"metadata": {
"kernelspec": {
"display_name": "ICortex (Python 3)",
"language": "icortex",
"language": "python",
"name": "icortex",
},
"language_info": {
"pygments_lexer": "icortex",
# "codemirror_mode": {"name": "ipython", "version": 3},
"file_extension": ".icx",
"mimetype": "text/x-icortex",
"pygments_lexer": "ipython3",
"codemirror_mode": {"name": "ipython", "version": 3},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "icortex",
# "nbconvert_exporter": "python",
"pygments_lexer": "icortex",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": icortex_version,
"python_version": platform.python_version(),
},
Expand Down
17 changes: 9 additions & 8 deletions icortex/kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
from icortex.services import ServiceBase, ServiceInteraction
from icortex.pypi import install_missing_packages, get_missing_modules
from icortex.defaults import *
import importlib.metadata

__version__ = importlib.metadata.version("icortex")


class ICortexKernel(IPythonKernel, SingletonConfigurable):
implementation = "ICortex"
implementation_version = "0.0.1"
implementation_version = __version__
language = "no-op"
language_version = "0.1"
language_info = {
"name": "any text",
"mimetype": "text/plain",
"name": "icortex",
"mimetype": "text/x-python",
"file_extension": ".py",
"pygments_lexer": "icortex",
"codemirror_mode": "text/plain",
"pygments_lexer": "ipython3",
"codemirror_mode": {"name": "ipython", "version": 3},
}
banner = (
"A prompt-based kernel for interfacing with code-generating language models"
)
banner = "ICortex: Generate Python code from natural language prompts using large language models"

def __init__(self, **kwargs):

Expand Down
2 changes: 1 addition & 1 deletion icortex/kernel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from icortex import ICortexKernel
from icortex.kernel import ICortexKernel
from ipykernel.kernelapp import IPKernelApp

IPKernelApp.launch_instance(kernel_class=ICortexKernel)
10 changes: 10 additions & 0 deletions icortex/kernel/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from jupyter_console.app import ZMQTerminalIPythonApp


# Jupyter devs did not make this easy
# TODO: Make less hacky
class ZMQTerminalICortexApp(ZMQTerminalIPythonApp):
def parse_command_line(self, argv=None):
argv = ["--kernel", "icortex"]
super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
self.build_kernel_argv(self.extra_args)
Binary file added icortex/kernel/icortex/logo-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions icortex/kernel/icortex/logo-svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 41 additions & 5 deletions icortex/install.py → icortex/kernel/install.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
import argparse
import json
import os
import sys
import json
import shutil
import argparse
import pkg_resources

from jupyter_client.kernelspec import KernelSpecManager
from IPython.utils.tempdir import TemporaryDirectory

try:
from jupyter_client.kernelspec import KernelSpecManager

HAVE_JUPYTER = True
except ImportError:
HAVE_JUPYTER = False

kernel_json = {
"argv": [sys.executable, "-m", "icortex.kernel", "-f", "{connection_file}"],
"display_name": "ICortex",
"language": "python",
}

KERNEL_RESOURCES = [
"logo-svg.svg",
"logo-32x32.png",
"logo-64x64.png",
"logo-128x128.png",
"logo-256x256.png",
"logo-512x512.png",
]


def install_my_kernel_spec(user=True, prefix=None, uninstall=False):
if not HAVE_JUPYTER:
print("Could not install Jupyter kernel spec, please install jupyter_client")
return

ksm = KernelSpecManager()
if not uninstall:
with TemporaryDirectory() as td:
os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(os.path.join(td, "kernel.json"), "w") as f:
json.dump(kernel_json, f, sort_keys=True)
# TODO: Copy any resources

# Copy resources such as logos
for resource in KERNEL_RESOURCES:
resource_path = pkg_resources.resource_filename(
"icortex", "kernel/icortex/" + resource
)
shutil.copy(resource_path, td)

print("Installing Jupyter kernel spec")
ksm.install_kernel_spec(td, "icortex", user=user, prefix=prefix)
Expand All @@ -39,6 +66,10 @@ def _is_root():


def is_kernel_installed():
if not HAVE_JUPYTER:
print("Could not install Jupyter kernel spec, please install jupyter_client")
return False

ksm = KernelSpecManager()

paths = ksm.find_kernel_specs()
Expand Down Expand Up @@ -70,7 +101,12 @@ def main(argv=None):
if not args.prefix and not _is_root():
args.user = True

install_my_kernel_spec(user=args.user, prefix=args.prefix, uninstall=args.uninstall)
try:
install_my_kernel_spec(
user=args.user, prefix=args.prefix, uninstall=args.uninstall
)
except:
pass


if __name__ == "__main__":
Expand Down
26 changes: 14 additions & 12 deletions icortex/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import typing as t
from copy import deepcopy
import importlib

from icortex.services.service_base import ServiceBase, ServiceVariable
from icortex.services.echo import EchoService
from icortex.services.textcortex import TextCortexService
from icortex.services.openai import OpenAIService
from icortex.services.huggingface import HuggingFaceAutoService

from icortex.defaults import (
DEFAULT_AUTO_EXECUTE,
Expand All @@ -15,21 +12,26 @@
)

service_dict = {
"echo": EchoService,
"textcortex": TextCortexService,
"openai": OpenAIService,
"huggingface": HuggingFaceAutoService,
"echo": "icortex.services.echo.EchoService",
"textcortex": "icortex.services.textcortex.TextCortexService",
"openai": "icortex.services.openai.OpenAIService",
"huggingface": "icortex.services.huggingface.HuggingFaceAutoService",
}


def get_service(name: str) -> t.Type[ServiceBase]:
return service_dict[name]
path = service_dict[name]
module_path, service_name = path.rsplit(".", 1)
module = importlib.import_module(module_path)
service = module.__dict__[service_name]
return service


def get_available_services() -> t.List[str]:
sorted_services = sorted(
[key for key, val in service_dict.items() if not val.hidden]
)
# sorted_services = sorted(
# [key for key, val in service_dict.items() if not val.hidden]
# )
sorted_services = list(sorted(service_dict.keys()))
sorted_services.remove(DEFAULT_SERVICE)
sorted_services = [DEFAULT_SERVICE] + sorted_services

Expand Down
6 changes: 2 additions & 4 deletions icortex/services/service_base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from abc import ABC, abstractmethod
import os
import argparse
import json

from icortex.defaults import *

import typing as t
from abc import ABC, abstractmethod

from icortex.defaults import DEFAULT_CACHE_PATH
from icortex.helper import prompt_input


Expand Down
3 changes: 0 additions & 3 deletions icortex/services/textcortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ def generate(

return response_dict["generated_text"]
elif response_dict["status"] == "fail":
import ipdb

ipdb.set_trace()
raise Exception(
f"There was an issue with generation: {response_dict['message']}"
)
Loading