anki-code / anki-code/xontrib-openai
Use colors
- Lingua principale
- Python
- Stelle
- 6
- Fork
- 2
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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**
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.