Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/natural/__init__.py

19 lines
645 B
Python
Raw Normal View History

2023-02-09 01:32:50 +00:00
import openai
2023-04-19 07:45:29 +00:00
from config import Config
2023-02-09 01:32:50 +00:00
from core.builtins import Bot
2023-03-04 08:51:56 +00:00
from core.component import module
2023-02-09 01:32:50 +00:00
2023-06-01 17:08:10 +00:00
n = module('natural', alias='nl2c', developers=['Dianliang233'], desc='{natural.help}', required_superuser=True)
2023-02-09 01:32:50 +00:00
# Load your API key from an environment variable or secret management service
openai.api_key = Config('openai_api_key')
2023-02-09 03:10:34 +00:00
model = Config('nl2c_model')
2023-02-09 01:32:50 +00:00
2023-04-30 03:30:59 +00:00
2023-04-15 04:47:09 +00:00
@n.handle('<text> {{natural.help}}')
2023-06-09 10:23:48 +00:00
async def _(msg: Bot.MessageSession, text: str):
2023-02-09 03:10:34 +00:00
response = openai.Completion.create(
2023-06-09 10:23:48 +00:00
model=model, prompt=f'{text}\n\n###\n\n', temperature=0, max_tokens=256, stop=['\n'])
2023-02-09 03:10:34 +00:00
await msg.finish(response['choices'][0]['text'])