anki-code / anki-code/xontrib-openai

Use colors

Offen
#1 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
6
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.