atksh's utils
Project description
atksh-utils
This is my collection of utilities.
Installation
$ pip install atksh-utils
askgpt command
You can use the askgpt command to ask questions to GPT-4.
Examples
$ export OPENAI_API_KEY="YOUR_API_KEY"
$ askgpt
Continue the conversation. To send your reply, please press Enter more than three times.
>>> 以下の式を解け:
>>> - 1 + 1/2 + 1/4 + ...
>>> - x + y = 4, pi * x - e^y = 0.24
>>>
>>> pythonを使っても良い
>>>
>>>
>>>
AI: Thinking...
了解しました。あなたの質問に最善を尽くして答えます。まず、与えられた2つの問題を解決するためのプランを説明します。
1. 数列の和の問題:
- 与えられた数列は無限等比数列です: 1 + 1/2 + 1/4 + ...
- 無限等比数列の和の公式を使用して、この数列の和を求めます。
- 公式は S = a / (1 - r) です。ここで、a は最初の項であり、r は公比です。
2. 連立方程式の問題:
- 与えられた連立方程式は次の通りです: x + y = 4, pi * x - e^y = 0.24
- この連立方程式を解くために、数値解析の手法を使用するか、代数的に解を求めます。
- Pythonの数値計算ライブラリを利用して、この連立方程式の数値解を見つけることができます。
これらの問題を解決するために、Pythonのコードを実行することにします。それでは、まずは数列の和の問題から取り組みます。その後、連立方程式の問題に移ります。無限等比数列 1 + 1/2 + 1/4 + ... の和は 2 です。
次に、連立方程式 x + y = 4, pi * x - e^y = 0.24 を解くために Python を使用します。これは数値解析の問題であり、Python の数値計算ライブラリを用いて解を求めることができます。それでは、Python コードを実行して解を見つけましょう。連立方程式 x + y = 4, pi * x - e^y = 0.24 の解は、x ≈ 2.1338 と y ≈ 1.8662 です。
以上で、与えられた2つの問題の解答を完了しました。最初の無限等比数列の和は 2 であり、二つ目の連立方程式の解は x ≈ 2.1338、y ≈ 1.8662 です。
Continue the conversation. To send your reply, please press Enter more than three times.
>>> ^D
Bye!
$ askgpt --disable-gpt4
>>> 明日の東京の天気は?
>>>
>>>
>>>
AI: Thinking...
明日の東京の天気は曇時々晴で、最高気温は21℃から23℃、最低気温は14℃から6℃となる見込みです。降水確率は10%で、一部では雨や雷雨がありそうです。体調に注意が必要です。また、明け方までは雨や雷雨がありそうです。最高気温は22度前後で、寒暖差で体調を崩さないようにしてください。
Continue the conversation. To send your reply, please press Enter more than three times.
>>> どうやってその情報を得ましたか?
>>>
>>>
>>>
AI: Thinking...
私は、あなたの質問に対する最適な回答を提供するために、functions.quick_searchツールを使用して明日の東京の天気に関する情報を検索しました。その結果、複数の天気予報サイトから明日の天気に関する情報を取得し、それを元に回答を提供しました。
Continue the conversation. To send your reply, please press Enter more than three times.
>>>
>>>
>>>
>>>
Do you want to quit? (y/n): y
Bye!
```bash
$ askgpt -h
usage: askgpt [-h] [--verbose] [--enable-speech] [--use-4o] [--use-4.1]
options:
-h, --help show this help message and exit
--verbose Verbose mode.
--enable-speech Enable speech.
--use-4o Use GPT-4o model.
--use-4.1 Use GPT-4.1 model (otherwise GPT-4.1-mini).
## Development
To install this for development, run the following commands in your terminal:
```bash
python -m pip install -e '.[dev]'
pre-commit install
OpenAI
ai = OpenAI(key, "gpt-4.1-mini")
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
ai.set_function(mul)
ai.set_function(add)
ai.set_function(sub)
ai.set_function(div)
print(ai("Just answer the value of (5243 + 642) x (5314 - 4231) // 100")[1])
# The value of (5243 + 642) x (5314 - 4231) // 100 is 63734.
ai = OpenAI(key, "gpt-4.1-mini")
ai.set_browser_functions()
print(ai("How the weather in Tokyo?")[1])
# The current weather in Tokyo varies depending on the source. According to AccuWeather, it is partly sunny with a temperature of 89°F. BBC Weather predicts thundery showers tonight with a low temperature of 22°C. Timeanddate.com reports an overcast sky with a temperature of 82°F. The Weather Network and The Weather Channel provide forecasts for the next 7 and 13 days respectively. Weather Underground also offers weather conditions for Tokyo and other cities.
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.9.15.tar.gz
(34.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file atksh_utils-0.9.15.tar.gz.
File metadata
- Download URL: atksh_utils-0.9.15.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e5ee7424c31936380c724a03e9a8ac4dfc2f932c746fb8617a00fb56ad05ce
|
|
| MD5 |
ee67120ec3d80c69085f2f812b1f555c
|
|
| BLAKE2b-256 |
a0db679609d6460d249aeb61d55dc9b4e00cdccd5cdebd6b286d278c9bc38a6a
|
File details
Details for the file atksh_utils-0.9.15-py3-none-any.whl.
File metadata
- Download URL: atksh_utils-0.9.15-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb4ef6ed5795081605192e9f40cafa3895cad6188069a1cb7fbf3aca60301a81
|
|
| MD5 |
9a218519cf2ba752e84573dd1b3d09f6
|
|
| BLAKE2b-256 |
1e88b6ad673b3d9c5a71fc3fc71678d2faf9857d32b73189b95c72cd2a794277
|