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-03-09 14:08:16 +08:00

18 lines
741 B
Python

import os
import openai
from core.builtins import Bot
from core.component import module
from config import Config
n = module('natural', alias=['nl2c'], developers=['Dianliang233'], desc='使用 InstructGPT 把自然语言转换成小可命令。')
# 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> {使用 InstructGPT 把自然语言转换成小可命令。}')
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'])