prompt-llm 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ build/*
2
+ mycli/*
3
+ __pycache__
4
+ dist
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.3
2
+ Name: prompt_llm
3
+ Version: 0.1.0
4
+ Summary: A CLI tool to prompt LLMs
5
+ Project-URL: Homepage, https://github.com/reego-software/prompt_llm
6
+ Project-URL: Issues, https://github.com/reego-software/prompt_llm/issues
7
+ Author-email: Hasan YILMAZ <yilmazhasan111@gmail.com>
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.8
12
+ Requires-Dist: langchain-core
13
+ Requires-Dist: langchain-mistralai
14
+ Requires-Dist: langchain-openai
15
+ Requires-Dist: typer
16
+ Description-Content-Type: text/markdown
17
+
18
+ # prompt_llm
19
+
20
+ ## Version
21
+ 0.1.0
22
+
23
+ - Prompt LLMs via cli
24
+
25
+ ## Installation
26
+
27
+ 1. Clone the repo
28
+
29
+ 2. Install
30
+ - Local:
31
+ - `pip install --editable .`
32
+ - PyPi:
33
+ - `pip install prompt_llm`
34
+
35
+ 3. Install auto-completion:
36
+ - `prompt_llm --install-completion`
37
+ - `source ~/.bashrc`
38
+
39
+ ## Config:
40
+ - Supported configs: `--system`, `--temperature`, `--api-key`
41
+
42
+ ### Set Config
43
+ - `add_config --api-key "<api_key>" --system "<system_messgae>" --temperature <temperature>`
44
+
45
+ ### Remove Config:
46
+
47
+ - `prompt_llm rm-config temperature`
48
+
49
+ ## Run cli
50
+ - `prompt_llm openai "Tell me something"`
51
+
@@ -0,0 +1,34 @@
1
+ # prompt_llm
2
+
3
+ ## Version
4
+ 0.1.0
5
+
6
+ - Prompt LLMs via cli
7
+
8
+ ## Installation
9
+
10
+ 1. Clone the repo
11
+
12
+ 2. Install
13
+ - Local:
14
+ - `pip install --editable .`
15
+ - PyPi:
16
+ - `pip install prompt_llm`
17
+
18
+ 3. Install auto-completion:
19
+ - `prompt_llm --install-completion`
20
+ - `source ~/.bashrc`
21
+
22
+ ## Config:
23
+ - Supported configs: `--system`, `--temperature`, `--api-key`
24
+
25
+ ### Set Config
26
+ - `add_config --api-key "<api_key>" --system "<system_messgae>" --temperature <temperature>`
27
+
28
+ ### Remove Config:
29
+
30
+ - `prompt_llm rm-config temperature`
31
+
32
+ ## Run cli
33
+ - `prompt_llm openai "Tell me something"`
34
+
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "prompt_llm"
7
+ dynamic = ["version"]
8
+ dependencies = ["typer", "langchain-core", "langchain-openai", "langchain-mistralai"]
9
+ authors = [
10
+ { name="Hasan YILMAZ", email="yilmazhasan111@gmail.com" },
11
+ ]
12
+ description = "A CLI tool to prompt LLMs"
13
+ readme = "README.md"
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/reego-software/prompt_llm"
23
+ Issues = "https://github.com/reego-software/prompt_llm/issues"
24
+
25
+ [project.scripts]
26
+ prompt_llm = "prompt_llm.cli:app"
27
+
28
+ [tool.hatch.version]
29
+ path = "src/prompt_llm/__init__.py"
@@ -0,0 +1,58 @@
1
+ annotated-types==0.7.0
2
+ anyio==4.7.0
3
+ build==1.2.2.post1
4
+ certifi==2024.8.30
5
+ charset-normalizer==3.4.0
6
+ click==8.1.7
7
+ distro==1.9.0
8
+ docutils==0.21.2
9
+ filelock==3.16.1
10
+ fsspec==2024.10.0
11
+ h11==0.14.0
12
+ httpcore==1.0.7
13
+ httpx==0.28.1
14
+ httpx-sse==0.4.0
15
+ huggingface-hub==0.26.5
16
+ idna==3.10
17
+ jaraco.classes==3.4.0
18
+ jaraco.context==6.0.1
19
+ jaraco.functools==4.1.0
20
+ jiter==0.8.0
21
+ jsonpatch==1.33
22
+ jsonpointer==3.0.0
23
+ keyring==25.5.0
24
+ langchain-core==0.3.22
25
+ langchain-mistralai==0.2.3
26
+ langchain-openai==0.2.11
27
+ langsmith==0.1.147
28
+ markdown-it-py==3.0.0
29
+ mdurl==0.1.2
30
+ more-itertools==10.5.0
31
+ nh3==0.2.19
32
+ openai==1.57.0
33
+ orjson==3.10.12
34
+ packaging==24.2
35
+ pkginfo==1.12.0
36
+ pydantic==2.10.3
37
+ pydantic_core==2.27.1
38
+ Pygments==2.18.0
39
+ pyproject_hooks==1.2.0
40
+ PyYAML==6.0.2
41
+ readme_renderer==44.0
42
+ regex==2024.11.6
43
+ requests==2.32.3
44
+ requests-toolbelt==1.0.0
45
+ rfc3986==2.0.0
46
+ rich==13.9.4
47
+ setuptools==75.1.0
48
+ shellingham==1.5.4
49
+ sniffio==1.3.1
50
+ tenacity==9.0.0
51
+ tiktoken==0.8.0
52
+ tokenizers==0.21.0
53
+ tqdm==4.67.1
54
+ twine==6.0.1
55
+ typer==0.15.1
56
+ typing_extensions==4.12.2
57
+ urllib3==2.2.3
58
+ wheel==0.44.0
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+
3
+ import typer
4
+ import json
5
+ import os
6
+
7
+ from .utils import add_to_config, remove_from_config, load_config
8
+ from .langchain_util import call
9
+
10
+ app = typer.Typer()
11
+
12
+ @app.command()
13
+ def add_config(api_key: str='', system: str = '', temperature:float = None):
14
+ if api_key:
15
+ add_to_config('api_key', api_key)
16
+
17
+ if system:
18
+ add_to_config('system', system)
19
+
20
+ if temperature is not None:
21
+ add_to_config('temperature', temperature)
22
+
23
+ @app.command()
24
+ def rm_config(key: str):
25
+ remove_from_config(key)
26
+
27
+
28
+ @app.command()
29
+ async def mistralai(prompt: str):
30
+ app_config = load_config()
31
+
32
+ if prompt:
33
+ app_config["provider"] = "mistralai"
34
+ app_config["model"] = "mistral-large-latest"
35
+
36
+ response = await call(prompt, app_config)
37
+
38
+ print(response)
39
+
40
+ @app.command()
41
+ def openai(prompt: str):
42
+ """Tool to prompt openai"""
43
+ app_config = load_config()
44
+
45
+ if prompt:
46
+ app_config["provider"] = "openai"
47
+ app_config["model"] = "gpt-4o"
48
+
49
+ response = call(prompt, app_config)
50
+
51
+ print(response.content)
52
+
53
+
54
+ @app.command()
55
+ def version():
56
+ """Retrieve the version from the __init__.py file."""
57
+ package_dir = os.path.dirname(os.path.abspath(__file__))
58
+ init_file = os.path.join(package_dir, '__init__.py')
59
+
60
+ with open(init_file, 'r') as file:
61
+ for line in file:
62
+ if line.startswith('__version__'):
63
+ # Extract version from the line
64
+ version = line.split('=')[-1].strip().strip('"').strip("'")
65
+ print(version)
66
+
67
+ if __name__ == "__main__":
68
+ app()
@@ -0,0 +1,31 @@
1
+ import os
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain_mistralai import ChatMistralAI
4
+ from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
5
+ from .models import Configuration
6
+
7
+ def get_model_to_invoke(config: dict):
8
+ model, api_key, provider = config["model"], config["api_key"], config["provider"]
9
+ model_to_invoke = None
10
+
11
+ if provider == 'openai':
12
+ os.environ["OPENAI_API_KEY"] = api_key
13
+ model_to_invoke = ChatOpenAI(model=model)
14
+ elif provider == 'mistralai':
15
+ os.environ["MISTRAL_API_KEY"] = api_key
16
+ model_to_invoke = ChatMistralAI(model=model)
17
+
18
+ return model_to_invoke
19
+
20
+
21
+ def call(prompt: str, config: dict):
22
+ model_to_invoke = get_model_to_invoke(config)
23
+
24
+ # Messages
25
+ messages_langchain = []
26
+ messages_langchain.append(SystemMessage(content=config["system"]))
27
+ messages_langchain.append(HumanMessage(content=prompt))
28
+
29
+ response = model_to_invoke.invoke(messages_langchain)
30
+
31
+ return response
@@ -0,0 +1,7 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import List, Dict
3
+
4
+ class Configuration(BaseModel):
5
+ api_key: str
6
+ model: str
7
+ provider: str
@@ -0,0 +1,48 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+ config_dir = Path.home() / ".prompt_llm"
5
+ config_file = config_dir / "config.json"
6
+
7
+ def add_to_config(key:str, value: str):
8
+ """Set config such as api_key"""
9
+ # Ensure the directory exists
10
+ config_dir.mkdir(parents=True, exist_ok=True)
11
+
12
+ # Load existing config if it exists
13
+ if config_file.exists():
14
+ with open(config_file, "r") as file:
15
+ config_data = json.load(file)
16
+ else:
17
+ config_data = {}
18
+
19
+ # Add or update the API key
20
+ config_data[key] = value
21
+
22
+ # Save the updated config
23
+ with open(config_file, "w") as file:
24
+ json.dump(config_data, file, indent=4)
25
+
26
+ def remove_from_config(key:str):
27
+ """Remove config such as api_key"""
28
+ # Ensure the directory exists
29
+ config_dir.mkdir(parents=True, exist_ok=True)
30
+
31
+ # Load existing config if it exists
32
+ if config_file.exists():
33
+ with open(config_file, "r") as file:
34
+ config_data = json.load(file)
35
+ if key in config_data:
36
+ del config_data[key]
37
+
38
+ # Save the updated config
39
+ with open(config_file, "w") as file:
40
+ json.dump(config_data, file, indent=4)
41
+
42
+ def load_config():
43
+ # Load existing config if it exists
44
+ if config_file.exists():
45
+ with open(config_file, "r") as file:
46
+ app_config = json.load(file)
47
+
48
+ return app_config