anki-code / anki-code/xontrib-openai
Use colors
- 主要语言
- 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)
```

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment**
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。