anki-code / anki-code/xontrib-openai

Use colors

未关闭
#1 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
6
派生
2
PR 合并指标
30 天内没有已合并 PR

描述

Draft
```python
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter

@aliases.register("ai")
def __ai(args):
import openai
openai.api_key = __xonsh__.env.get('OPENAI_API_KEY', '')
response = openai.Completion.create(**{
'prompt': ' '.join(args),
'engine': __xonsh__.env.get('OPENAI_MODEL', 'text-davinci-003'),
'max_tokens': __xonsh__.env.get('OPENAI_MAX_TOKENS', 100)
})

output = response.choices[0].text.strip()
if 1:
highlighted_code = highlight(output, PythonLexer(), Terminal256Formatter(style='monokai'))
print(f"{highlighted_code.rstrip()}")

else:
print(output)
```

image

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment**

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。