Skip to content

Commit

Permalink
Merge pull request #1 from narenaryan/feat/add-working-cli
Browse files Browse the repository at this point in the history
feat: Add working promptml-cli application
  • Loading branch information
narenaryan authored Jun 16, 2024
2 parents 2062e6b + 81ecf36 commit 04aa73d
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 2 deletions.
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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/#use-with-ide
.pdm.toml

# 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/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 N3N
Copyright (c) 2024 Vidura Labs Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
# promptml-cli
A CLI application to parse Prompt Markup Language
A CLI application to run PromptML scripts against LLMs.

## Installation
```bash
pip install --upgrade promptml-cli
```

## Usage
```bash
promptml-cli --help

usage: promptml-cli [-h] -f FILE [-m MODEL] [-s {xml,json,yaml}] [-p {openai,google}]

A Command Line Interface tool to run PromptML files with popular Generative AI models

optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE Path to the PromptML file
-m MODEL, --model MODEL
Model to use for the completion
-s {xml,json,yaml}, --serializer {xml,json,yaml}
Serializer to use for the completion. Default is `xml`
-p {openai,google}, --provider {openai,google}
GenAI provider to use for the completion. Default is `openai`
```

1. Create a PromptML file `character.pml` with the following content:

```promptml
@prompt
@context
You are a millitary general in Roman army.
@end
@objective
Describe a regular day in your life.
@end
@instructions
@step
Be cheeky and sarcastic.
@end
@end
@category
Simulation
@end
@end
```
See PromptML [documentation](https://www.promptml.org/) for more details.

2. Set your OpenAI API key as an environment variable:

```bash
export OPEN_AI_API_KEY=your-openai-api-key
```

3. Run the PromptML file with the following command in terminal:

```bash
promptml-cli -f character.pml -m gpt-4o
```

You will see the respective output on terminal:

```info
Ah, so you want a glimpse into the life of a Roman general, do you? Well, let me spin you a tale, dripping with sarcasm and cheeky remarks, because obviously, my life is a walk in the park. Shall we?
The day usually starts with the soothing sounds of soldiers clanging their swords and shields together at some ungodly hour. Rather than waking up to the gentle cooing of doves, I get to hear the charming war cries of recruits who still can't tell their gladius from their left foot. Delightful, isn't it?
After I drag myself out of what I'm convinced is a sack filled with rocks they call a bed, it's straight to the strategy tent. Here, I enjoy the riveting discussions about which barbarian horde is threatening our borders this week. It's like choosing the lesser of two evils: invasions from the north or mutiny from the ranks. Decisions, decisions!
Next on the agenda is overseeing training. Oh yes, I just love watching greenhorns stumble through basic drills. The way they handle their weapons – you'd think a lopsided stick had suddenly become the deadliest thing in their hands. But hey, a general's got to humor them, right?
Then there's the daily feast of dried meat and stale bread, washed down with wine that's likely been used as paint thinner. Ah, the joys of Roman culinary delights. I'm sure Bacchus himself is weeping with laughter somewhere.
Afternoons are reserved for dealing with the Senate's missives, those beautifully crafted scrolls filled with ‘helpful’ suggestions and veiled threats. It's like mail time with a hint of doomsday. And who can forget the thrill of addressing the legion, trying to maintain morale while standing in armor that weighs more than some of the new recruits?
As evening falls, I get to review the day's progress with my centurions, who conveniently bring me the freshest of problems right before bedtime. If I’m lucky, I'll dodge an assassination attempt or two – keeps life exciting, don’t you think?
Finally, I retire for the night, eager to wake up and do it all over again. Really, what's not to love? So there you have it! Just another average day in the life of a Roman general – a blend of strategy, sarcasm, and just a dash of masochism.
Time taken: 6.006012916564941 seconds
```

## TODO
- Add support for Claude, Cohere & A21 Labs GenAI models
- Add tests
18 changes: 18 additions & 0 deletions character.pml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@prompt
@context
You are a millitary general in Roman army.
@end

@objective
Describe a regular day in your life.
@end

@instructions
@step
Be cheeky and sarcastic.
@end
@end
@category
Simulation
@end
@end
86 changes: 86 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "promptml-cli"
dynamic = ["version"]
description = 'A CLI tool to run PromptML scripts'
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
keywords = [
"artificial-intelligence",
"prompt-engineering",
"dsl",
"language",
"generative-ai",
"promptml",
"promptml-cli",
]
authors = [
{ name = "Vidura Labs Inc.", email = "[email protected]" },
{ name = "Naren Yellavula", email = "[email protected]" },
]

classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

dependencies = [
"promptml==0.6.1",
"openai==1.33.0",
"rich==13.7.1",
"google-generativeai==0.6.0",
]

[project.urls]
Documentation = "https://github.com/narenaryan/promptml-cli/blob/main/README.md"
Issues = "https://github.com/narenaryan/promptml-cli/issues"
Source = "https://github.com/narenaryan/promptml-cli/"

[tool.hatch.version]
path = "src/promptml_cli/__about__.py"

[tool.hatch.envs.default]
dependencies = ["coverage[toml]>=6.5", "pytest"]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = ["- coverage combine", "coverage report"]
cov = ["test-cov", "cov-report"]

[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.types]
dependencies = ["mypy>=1.0.0"]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/promptml_cli tests}"

[tool.coverage.run]
source_pkgs = ["promptml_cli", "tests"]
branch = true
parallel = true
omit = ["src/promptml_cli/__about__.py"]

[tool.coverage.paths]
promptml-cli = ["src/promptml_cli"]
tests = ["tests", "*/promptml_cli/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[project.scripts]
promptml-cli = "promptml_cli.main:run"

[tool.hatch.build.targets.wheel]
packages = ["src/promptml_cli"]
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
promptml==0.6.1
openai==1.33.0
rich==13.7.1
google-generativeai==0.6.0
2 changes: 2 additions & 0 deletions src/promptml_cli/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pylint: disable=invalid-name
version = "0.1.0"
Empty file added src/promptml_cli/__init__.py
Empty file.
Loading

0 comments on commit 04aa73d

Please sign in to comment.