atksh's utils
Project description
atksh-utils
This is my collection of utilities.
Development
To install this for development, run the following commands in your terminal:
python -m pip install -e '.[dev]'
pre-commit install
OpenAI
ai = OpenAI(key, "gpt-3.5-turbo-0613")
print(ai("Just answer the value of (5243 + 642) x (5314 - 4231) // 100"))
# The value of the expression (5243 + 642) x (5314 - 4231) // 100 is 7112.
def mul(a: int, b: int) -> int:
"""This is a multiplication function.
:param a: An integer.
:type a: int
:param b: An integer.
:type b: int
:return: The sum of a and b.
:rtype: int
"""
return a * b
def add(a: int, b: int) -> int:
"""This is an addition function.
:param a: An integer.
:type a: int
:param b: An integer.
:type b: int
:return: The sum of a and b.
:rtype: int
"""
return a + b
def sub(a: int, b: int) -> int:
"""This is a subtraction function.
:param a: An integer.
:type a: int
:param b: An integer.
:type b: int
:return: The sum of a and b.
:rtype: int
"""
return a - b
def div(a: int, b: int) -> int:
"""This is a division function.
:param a: An integer.
:type a: int
:param b: An integer.
:type b: int
:return: The sum of a and b.
:rtype: int
"""
return a // b
def exec_python_code(code: str) -> str:
"""This is a function that executes Python code and returns the stdout. Don't forget to print the result.
:param code: A string of Python code.
:type code: str
:return: The result of the execution of the Python code (stdout by print)
:rtype: str
"""
import tempfile
import subprocess
with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
f.write(code)
f.flush()
result = subprocess.check_output(["python", f.name])
result = result.decode("utf-8").strip()
if result == "":
result = "NotPrintedError('The result is not printed.')"
return result
ai.set_function(mul)
ai.set_function(add)
ai.set_function(sub)
ai.set_function(div)
ai.set_function(exec_python_code)
print(ai("Just answer the value of (5243 + 642) x (5314 - 4231) // 100"))
# The value of (5243 + 642) x (5314 - 4231) // 100 is 63734.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
atksh-utils-0.2.0.tar.gz
(13.6 kB
view hashes)
Built Distribution
Close
Hashes for atksh_utils-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45a6ba4ddd1aaef99aee424bf919590ee67f7636a65cd13173cf0a77bbc7fc7a |
|
MD5 | ebeeb0ed05b9eb0df41208128b1402c5 |
|
BLAKE2b-256 | 26bac03160e2e4d74b12f70f798d2155e431c2627797825322d556e92de3c701 |