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
2023-06-02 01:08:10 +08:00

19 lines
664 B
Python

import openai
from config import Config
from core.builtins import Bot
from core.component import module
n = module('natural', alias='nl2c', developers=['Dianliang233'], desc='{natural.help}', required_superuser=True)
# Load your API key from an environment variable or secret management service
openai.api_key = Config('openai_api_key')
model = Config('nl2c_model')
@n.handle('<text> {{natural.help}}')
async def _(msg: Bot.MessageSession):
i = msg.parsed_msg['<text>']
response = openai.Completion.create(
model=model, prompt=f'{i}\n\n###\n\n', temperature=0, max_tokens=256, stop=['\n'])
await msg.finish(response['choices'][0]['text'])