anki-code / anki-code/xontrib-openai

Use colors

Đang mở
#1 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
6
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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**

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.