Use Open AI models in xonsh shell.
If you like the idea click ⭐ on the repo and tweet.
To install use pip:
xpip install -U xontrib-openai
# or: xpip install -U git+https://github.com/anki-code/xontrib-openai
$OPENAI_API_KEY = 'abcd1234' # https://platform.openai.com/account/api-keys
# Defaults:
# $OPENAI_MODEL = 'text-davinci-003' # https://platform.openai.com/docs/models/overview
# $OPENAI_MAX_TOKENS = 500
xontrib load openai
ai! hello
# Hello! How are you?
In case you need addon with new model:
aliases['ai4'] = "$OPENAI_MODEL='gpt-4' $OPENAI_MAX_TOKENS=1000 @('ai')"
ai4! hello gpt-4
# Hello human
ai! how to git commit. Give me only command
# git commit -m "Commit message"
ai! how to remove all containers and images in docker. Only commands please
# docker stop $(docker ps -a -q)
# docker rm $(docker ps -a -q)
# docker rmi $(docker images -a -q)
ai! send post request with json data on python
# import requests
# import json
#
# url = 'http://example.com/api/1/users'
# data = {
# "first_name": "John",
# "last_name": "Smith"
# }
#
# headers = {'Content-type': 'application/json'}
# response = requests.post(url, data=json.dumps(data), headers=headers)
ai! give me json where keys are fruits and values are most common fruit color
# {
# "Apple": "Red",
# "Banana": "Yellow",
# "Orange": "Orange",
# "Grape": "Purple",
# "Strawberry": "Red",
# "Lemon": "Yellow",
# "Kiwi": "Green",
# "Cherry": "Red",
# "Watermelon": "Green"
# }
Using the data:
import json
j = json.loads($(ai give me small json))
j
# {'name': 'John', 'age': 25}
To use gpt-4
model join wait list.
This package was created with xontrib template.