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
653 B
Python
Raw Normal View History

2023-02-09 01:32:50 +00:00
import os
import openai
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
from config import Config
2023-04-15 04:47:09 +00:00
n = module('natural', alias=['nl2c'], developers=['Dianliang233'], desc='{natural.help}')
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-15 04:47:09 +00:00
@n.handle('<text> {{natural.help}}')
2023-02-09 03:10:34 +00:00
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'])