diff --git a/support/plugins/mtllm/.devcontainer/devcontainer.json b/support/plugins/mtllm/.devcontainer/devcontainer.json new file mode 100644 index 000000000..c36ef0d6f --- /dev/null +++ b/support/plugins/mtllm/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +{ + "name": "Python 3", + "image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": { + "fisher": true + }, + "ghcr.io/devcontainers/features/conda:1": { + "addCondaForge": true, + "version": "latest" + } + }, + "postCreateCommand": "pip3 install --user -r dev.requirements.txt" +} \ No newline at end of file diff --git a/support/plugins/mtllm/.flake8 b/support/plugins/mtllm/.flake8 new file mode 100644 index 000000000..648663eee --- /dev/null +++ b/support/plugins/mtllm/.flake8 @@ -0,0 +1,5 @@ +[flake8] +exclude = __jac_gen__, build, dist +plugins = flake8_import_order, flake8_docstrings, flake8_comprehensions, flake8_bugbear, flake8_annotations, pep8_naming, flake8_simplify +max-line-length = 120 +ignore = E203, W503, ANN101, ANN102, D401 diff --git a/support/plugins/mtllm/.github/workflows/precommit.yml b/support/plugins/mtllm/.github/workflows/precommit.yml new file mode 100644 index 000000000..1cede323c --- /dev/null +++ b/support/plugins/mtllm/.github/workflows/precommit.yml @@ -0,0 +1,25 @@ +name: Linting and Pre-commit checks + +on: + pull_request: + push: + branches: + - main + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.12 + + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit hooks + run: pre-commit run --all-files \ No newline at end of file diff --git a/support/plugins/mtllm/.github/workflows/release.yml b/support/plugins/mtllm/.github/workflows/release.yml new file mode 100644 index 000000000..de312d73f --- /dev/null +++ b/support/plugins/mtllm/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: PyPI Release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.12' + - name: Install Poetry + run: | + pip install poetry + - name: Build package + run: poetry build + - name: Publish package + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} + poetry publish + continue-on-error: true + - run: pip install githubrelease markdown-to-json + - run: python scripts/gh_release.py + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} \ No newline at end of file diff --git a/support/plugins/mtllm/.github/workflows/test.yml b/support/plugins/mtllm/.github/workflows/test.yml new file mode 100644 index 000000000..b87113669 --- /dev/null +++ b/support/plugins/mtllm/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: tests + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Set up Python 3.12 + uses: actions/setup-python@v2 + with: + python-version: 3.12 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + pip install pytest opencv-python-headless pillow + + - name: Run tests + run: pytest -x diff --git a/support/plugins/mtllm/.gitignore b/support/plugins/mtllm/.gitignore new file mode 100644 index 000000000..fe4b9f00d --- /dev/null +++ b/support/plugins/mtllm/.gitignore @@ -0,0 +1,167 @@ +# Jaclang +__jac_gen__/ +.jac_mypy_cache/ +temp* + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/support/plugins/mtllm/.pre-commit-config.yaml b/support/plugins/mtllm/.pre-commit-config.yaml new file mode 100644 index 000000000..b1fc35509 --- /dev/null +++ b/support/plugins/mtllm/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + args: [--allow-multiple-documents] + - id: check-json + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 24.1.1 + hooks: + - id: black + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: [pep8-naming, flake8_import_order, flake8_docstrings, flake8_comprehensions, flake8_bugbear, flake8_annotations, flake8_simplify] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + additional_dependencies: [types-PyYAML, types-requests] + args: + - --follow-imports=silent + - --ignore-missing-imports \ No newline at end of file diff --git a/support/plugins/mtllm/CHANGELOG.md b/support/plugins/mtllm/CHANGELOG.md new file mode 100644 index 000000000..fa5302f4f --- /dev/null +++ b/support/plugins/mtllm/CHANGELOG.md @@ -0,0 +1,19 @@ +# RELEASES + +## `0.3.1` - 2024-08-20 +- [IMPROVEMENT] Added Self Healing for the ReAct capabilities +- [FEATURE] Added Serper Tools for Search Integration + +## `0.3.0` - 2024-08-14 +- [IMPROVEMENT] Added support for the new `Jaclang` version +- [IMPROVEMENT] Moved all the mtllm related AST capabilities to mtllm repo from jaclang +- [FEATURE] Added ReAct and Tool Calling capabilities + +## `0.2.0` - 2024-07-23 +- [IMPROVEMENT] Seperated the different llms and vision capabilities into extras for the main package + +## `0.1.13` - 2024-06-26 +- [IMPROVEMENT] Added Plugin support for Jaclang + +## `0.1.12` - 2024-06-21 +- [FEATURE] Multi Modal capabilities for the Vision UseCases \ No newline at end of file diff --git a/support/plugins/mtllm/LICENSE b/support/plugins/mtllm/LICENSE new file mode 100644 index 000000000..7d832bf03 --- /dev/null +++ b/support/plugins/mtllm/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Chandra Irugalbandara + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/support/plugins/mtllm/README.md b/support/plugins/mtllm/README.md new file mode 100644 index 000000000..c20d2c49a --- /dev/null +++ b/support/plugins/mtllm/README.md @@ -0,0 +1,53 @@ +# MTLLM API library + +[![PyPI version](https://img.shields.io/pypi/v/mtllm.svg)](https://pypi.org/project/mtllm/) [![tests](https://github.com/Jaseci-Labs/mtllm/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/Jaseci-Labs/mtllm/actions/workflows/test.yml) + +The MTLLM Python library provides convenient access to a large number of easy to use and customizable APIs to be used in Jaseci's [Jaclang](https://github.com/Jaseci-Labs/jaclang) by llm feature. +The Library provides automatic output fixing, output type validation, different prompting techniques, and more. + +## Documentation + +The documentation on how to use this library with Jaseci's Jaclang can be found [here](https://jaseci-labs.github.io/mtllm/). + +## Installation + +> [!IMPORTANT] +> Though this is can be used with python projects, it is primarily intended to be used with Jaseci's Jaclang. + +```sh +# install from PyPI +pip install mtllm +``` + +## Usage + +Refer the Documentation for detailed usage instructions. + +### Using Different LLMs +```py +import:py from mtllm.llms, OpenAI; + +glob llm = OpenAI(); + +can "Translate English to French" +translate(word: "English Word": str) -> "French Word": str by llm(); +``` + +Based on your LLM of choice, make sure to set the `API Key` in the environment variable. For example, for OpenAI: + +```sh +export OPENAI_API_KEY="your-api-key" +``` +### Using Tools +```py +import:py from mtllm.llms, OpenAI; +import:py from mtllm.tools, wikipedia; + +glob llm = OpenAI(); + +can "Answer History Questions" +history_qa(question: "History Question": str) -> "Detailed Answer": str by llm(tools=[wikipedia]); +``` + +## Contributing +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. diff --git a/support/plugins/mtllm/docs/.codedoc/build.ts b/support/plugins/mtllm/docs/.codedoc/build.ts new file mode 100644 index 000000000..80763034e --- /dev/null +++ b/support/plugins/mtllm/docs/.codedoc/build.ts @@ -0,0 +1,15 @@ +import { build } from '@codedoc/core'; + +import { config } from './config'; +import { installTheme$ } from './content/theme'; +import { content } from './content'; + + +build(config, content, installTheme$, { + resolve: { + modules: ['.codedoc/node_modules'] + }, + resolveLoader: { + modules: ['.codedoc/node_modules'] + } +}); diff --git a/support/plugins/mtllm/docs/.codedoc/config.ts b/support/plugins/mtllm/docs/.codedoc/config.ts new file mode 100644 index 000000000..1524e2eb5 --- /dev/null +++ b/support/plugins/mtllm/docs/.codedoc/config.ts @@ -0,0 +1,26 @@ + +import { configuration } from '@codedoc/core'; +import { mermaidPlugin } from 'codedoc-mermaid-plugin' +import { theme } from './theme'; + + +export const config = /*#__PURE__*/configuration({ + theme, // --> add the theme. modify `./theme.ts` for changing the theme. + dest: { + namespace: '/mtllm' // --> your github pages namespace. remove if you are using a custom domain. + }, + page: { + title: { + base: 'MTLLM API Documentation' // --> the base title of your doc pages + } + }, + plugins: [ + mermaidPlugin() // --> make sure you add this section + ], + misc: { + github: { + user: 'Jaseci-Labs', // --> your github username (where your repo is hosted) + repo: 'mtllm', // --> your github repo name + } + }, +}); diff --git a/support/plugins/mtllm/docs/.codedoc/content/footer.tsx b/support/plugins/mtllm/docs/.codedoc/content/footer.tsx new file mode 100644 index 000000000..9922c6697 --- /dev/null +++ b/support/plugins/mtllm/docs/.codedoc/content/footer.tsx @@ -0,0 +1,19 @@ +import { CodedocConfig } from '@codedoc/core'; +import { Footer as _Footer, GitterToggle$, Watermark} from '@codedoc/core/components'; + + +export function Footer(config: CodedocConfig, renderer: any) { + let github$; + if (config.misc?.github) + github$ = GitHub; + + let community$; + if (config.misc?.gitter) + community$ = + + if (github$ && community$) return <_Footer>{github$}
{community$}; + else if (github$) return <_Footer>{github$}; + else if (community$) return <_Footer>{community$}; + else return <_Footer>; +} diff --git a/support/plugins/mtllm/docs/.codedoc/content/header.tsx b/support/plugins/mtllm/docs/.codedoc/content/header.tsx new file mode 100644 index 000000000..8e2446c51 --- /dev/null +++ b/support/plugins/mtllm/docs/.codedoc/content/header.tsx @@ -0,0 +1,20 @@ +import { CodedocConfig } from '@codedoc/core'; +import { Header as _Header, GithubButton} from '@codedoc/core/components'; + + +export function Header(config: CodedocConfig, renderer: any) { + return ( + <_Header>{config.misc?.github ? + + +

+
+ : ''} + + ) +} diff --git a/support/plugins/mtllm/docs/.codedoc/content/index.tsx b/support/plugins/mtllm/docs/.codedoc/content/index.tsx new file mode 100644 index 000000000..f1383ca96 --- /dev/null +++ b/support/plugins/mtllm/docs/.codedoc/content/index.tsx @@ -0,0 +1,39 @@ +import { RendererLike } from '@connectv/html'; +import { File } from 'rxline/fs'; +import { Page, Meta, ContentNav, Fonts, ToC, GithubSearch$ } from '@codedoc/core/components'; + +import { config } from '../config'; +import { Header } from './header'; +import { Footer } from './footer'; + + +export function content(_content: HTMLElement, toc: HTMLElement, renderer: RendererLike, file: File) { + return ( + } + fonts={} + + scripts={config.page.scripts} + stylesheets={config.page.stylesheets} + + header={
} + footer={