Skip to content

Commit

Permalink
feat : add command parser
Browse files Browse the repository at this point in the history
add command parser for text and translate in interactive mode.
give ability to enter command that start with a "/" to modify parameter
  • Loading branch information
LordPax committed Jan 4, 2025
1 parent b38eeb5 commit 0373303
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 79 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Added

* Add command parser in text interactive mode
* Add command parser in translate interactive mode

## [0.6.0] - 2024-10-16

### Changed
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Projet to use ai api to generate text, image, etc.
- claude
- mistral

### Image Generation

- openai

### Translation

- deepl
Expand Down Expand Up @@ -94,10 +98,12 @@ Add the following line to your `.vimrc`:
Plug 'LordPax/vim-aicli'
```

<!--
## Integration with i3
Add the following line to your `~/.config/i3/config`:
```
bindsym $mod+s exec /usr/bin/aicli -c -g speech
```
-->
4 changes: 1 addition & 3 deletions commands/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func textFlags() []cli.Flag {
Category: "history",
Action: func(c *cli.Context, value bool) error {
text := sdk.GetSdkText()
for _, name := range text.GetHistoryNames() {
fmt.Println(name)
}
text.ListHistoryNames()
os.Exit(0)
return nil
},
Expand Down
89 changes: 54 additions & 35 deletions lang/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,58 @@ package lang
import "github.com/LordPax/aicli/utils"

var EN_STRINGS = LangString{
"usage": "CLI toot to use ai model",
"output-desc": "Output directory",
"output-dir-empty": "Output directory is empty",
"silent": "Disable printing log to stdout",
"no-args": "No arguments provided",
"no-command": "No command provided",
"not-implemented": "Feature \"%s\" is not implemented",
"unknown-sdk": "Unknown sdk \"%s\"",
"sdk-model-usage": "Select a model",
"inerte-usage": "Do not make API call",
"text-usage": "Generate text from a prompt",
"sdk-usage": "Select a sdk",
"text-temp-usage": "Set temperature",
"text-system-usage": "Instruction to enter as context (use \"-\" for stdin)",
"text-history-usage": "Select a history",
"text-clear-usage": "Clear history",
"text-file-usage": "Text or image file to use",
"text-input": "(\"exit\" to quit) " + utils.Blue + "user> " + utils.Reset,
"translate-input": "(\"exit\" to quit) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "List history",
"text-list-history-name-usage": "List history names",
"text-url-usage": "URL of a web page",
"type-required": "Type is required",
"api-key-required": "API key is required",
"empty-file": "File \"%s\" is empty",
"empty-history": "History \"%s\" is empty\n",
"translate-usage": "Translate a text",
"translate-source-usage": "Source language",
"translate-target-usage": "Target language",
"translate-target-required": "Target language is required",
"image-usage": "Generate an image from a prompt",
"image-size-usage": "Set the size of the image",
"image-nb-usage": "Set the number of images",
"image-output-usage": "Set the name of the output file",
"image-save": "Image saved under \"%s\"\n",
"unknown-command": "Unknown command \"%s\"",
"text-history-selected": "History selected \"%s\"\n",
"text-history-cleared": "History \"%s\" cleared\n",
"text-command-help-usage": "/help Show help",
"text-command-exit-usage": "/exit, /e Exit the program",
"text-command-sdk-usage": "/sdk, /s [name] Select a sdk",
"text-command-model-usage": "/model, /m [name] Select a model",
"text-command-temp-usage": "/temp, /t [value] Set temperature",
"text-command-history-usage": "/history, /h [name] Select a history",
"text-command-clear-usage": "/clear, /c Clear history",
"text-command-show-usage": "/show, Affiche l'historique",
"usage": "CLI toot to use ai model",
"output-desc": "Output directory",
"output-dir-empty": "Output directory is empty",
"silent": "Disable printing log to stdout",
"no-args": "No arguments provided",
"no-command": "No command provided",
"not-implemented": "Feature \"%s\" is not implemented",
"unknown-sdk": "Unknown sdk \"%s\"",
"sdk-model-usage": "Select a model",
"inerte-usage": "Do not make API call",
"text-usage": "Generate text from a prompt",
"sdk-usage": "Select a sdk",
"text-temp-usage": "Set temperature",
"text-system-usage": "Instruction to enter as context (use \"-\" for stdin)",
"text-history-usage": "Select a history",
"text-clear-usage": "Clear history",
"text-file-usage": "Text or image file to use",
"text-input": "(\"/help\" to show help) " + utils.Blue + "user> " + utils.Reset,
"translate-input": "(\"/help\" to show help) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "List history",
"text-list-history-name-usage": "List history names",
"text-url-usage": "URL of a web page",
"type-required": "Type is required",
"api-key-required": "API key is required",
"empty-file": "File \"%s\" is empty",
"empty-history": "History \"%s\" is empty\n",
"translate-usage": "Translate a text",
"translate-source-usage": "Source language",
"translate-target-usage": "Target language",
"translate-target-required": "Target language is required",
"translate-detect": "Detect source language",
"translate-source-set": "Source language set to \"%s\"",
"translate-target-set": "Target language set to \"%s\"",
"translate-command-help-usage": "/help Show help",
"translate-command-exit-usage": "/exit, /e Exit the program",
"translate-command-sdk-usage": "/sdk, /s [name] Select a sdk",
"translate-command-source-usage": "/source, /so [lang] Set the source language (\"auto\" to detect)",
"translate-command-target-usage": "/target, /ta [lang] Set the target language",
"image-usage": "Generate an image from a prompt",
"image-size-usage": "Set the size of the image",
"image-nb-usage": "Set the number of images",
"image-output-usage": "Set the name of the output file",
"image-save": "Image saved under \"%s\"\n",
}
89 changes: 54 additions & 35 deletions lang/fr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,58 @@ package lang
import "github.com/LordPax/aicli/utils"

var FR_STRINGS = LangString{
"usage": "CLI pour utiliser des modèles d'IA",
"output-desc": "Répertoire de sortie",
"output-dir-empty": "Le répertoire de sortie est vide",
"silent": "Désactiver l'impression du journal sur stdout",
"no-args": "Aucun argument fourni",
"no-command": "Aucune commande fournie",
"not-implemented": "La fonctionnalité \"%s\" n'est pas implémentée",
"unknown-sdk": "Sdk inconnu \"%s\"",
"sdk-model-usage": "Sélectionner un modèle",
"inerte-usage": "N'effectue pas d'appel à l'API",
"text-usage": "Générer du texte à partir d'un prompt",
"sdk-usage": "Sélectionner un sdk",
"text-temp-usage": "Définir la température",
"text-system-usage": "Instruction à entrer comme context (utilisez \"-\" pour stdin)",
"text-history-usage": "Sélectionner un historique",
"text-clear-usage": "Effacer l'historique",
"text-file-usage": "Fichier texte ou image à utiliser",
"text-input": "(\"exit\" pour quitter) " + utils.Blue + "user> " + utils.Reset,
"translate-input": "(\"exit\" pour quitter) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "Lister l'historique",
"text-list-history-name-usage": "Lister les noms d'historique",
"text-url-usage": "URL d'une page web",
"type-required": "Le type est requis",
"api-key-required": "La clé API est requise",
"empty-file": "Le fichier \"%s\" est vide",
"empty-history": "L'historique \"%s\" est vide\n",
"translate-usage": "Traduire un texte",
"translate-source-usage": "Langue source",
"translate-target-usage": "Langue cible",
"translate-target-required": "La langue cible est requise",
"image-usage": "Générer une image à partir d'un prompt",
"image-size-usage": "Définir la taille de l'image",
"image-nb-usage": "Définir le nombre d'images",
"image-output-usage": "Définir le nom du fichier de sortie",
"image-save": "L'image a été enregistrée sous \"%s\"\n",
"unknown-command": "Commande inconnue \"%s\"",
"text-history-selected": "Historique sélectionné \"%s\"\n",
"text-history-cleared": "Historique \"%s\" effacé\n",
"text-command-help-usage": "/help Afficher l'aide",
"text-command-exit-usage": "/exit, /e Quitter le programme",
"text-command-sdk-usage": "/sdk, /s [nom] Sélectionner un sdk",
"text-command-model-usage": "/model, /m [nom] Sélectionner un modèle",
"text-command-temp-usage": "/temp, /t [valeur] Définir la température",
"text-command-history-usage": "/history, /h [nom] Sélectionner un historique et liste les noms d'historique",
"text-command-clear-usage": "/clear, /c Effacer l'historique",
"text-command-show-usage": "/show, Affiche l'historique",
"usage": "CLI pour utiliser des modèles d'IA",
"output-desc": "Répertoire de sortie",
"output-dir-empty": "Le répertoire de sortie est vide",
"silent": "Désactiver l'impression du journal sur stdout",
"no-args": "Aucun argument fourni",
"no-command": "Aucune commande fournie",
"not-implemented": "La fonctionnalité \"%s\" n'est pas implémentée",
"unknown-sdk": "Sdk inconnu \"%s\"",
"sdk-model-usage": "Sélectionner un modèle",
"inerte-usage": "N'effectue pas d'appel à l'API",
"text-usage": "Générer du texte à partir d'un prompt",
"sdk-usage": "Sélectionner un sdk",
"text-temp-usage": "Définir la température",
"text-system-usage": "Instruction à entrer comme context (utilisez \"-\" pour stdin)",
"text-history-usage": "Sélectionner un historique",
"text-clear-usage": "Effacer l'historique",
"text-file-usage": "Fichier texte ou image à utiliser",
"text-input": "(\"/help\" pour afficher l'aide) " + utils.Blue + "user> " + utils.Reset,
"translate-input": "(\"/help\" pour afficher l'aide) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "Lister l'historique",
"text-list-history-name-usage": "Lister les noms d'historique",
"text-url-usage": "URL d'une page web",
"type-required": "Le type est requis",
"api-key-required": "La clé API est requise",
"empty-file": "Le fichier \"%s\" est vide",
"empty-history": "L'historique \"%s\" est vide\n",
"translate-usage": "Traduire un texte",
"translate-source-usage": "Langue source",
"translate-target-usage": "Langue cible",
"translate-target-required": "La langue cible est requise",
"translate-detect": "Détecter la langue source",
"translate-source-set": "Langue source définie sur \"%s\"\n",
"translate-target-set": "Langue cible définie sur \"%s\"\n",
"translate-command-help-usage": "/help Afficher l'aide",
"translate-command-exit-usage": "/exit, /e Quitter le programme",
"translate-command-sdk-usage": "/sdk, /s [nom] Sélectionner un sdk",
"translate-command-source-usage": "/source, /so [lang] Définir la langue source (\"auto\" pour détecter)",
"translate-command-target-usage": "/target, /ta [lang] Définir la langue cible",
"image-usage": "Générer une image à partir d'un prompt",
"image-size-usage": "Définir la taille de l'image",
"image-nb-usage": "Définir le nombre d'images",
"image-output-usage": "Définir le nom du fichier de sortie",
"image-save": "L'image a été enregistrée sous \"%s\"\n",
}
12 changes: 12 additions & 0 deletions sdk/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sdk
import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"path"

Expand All @@ -22,6 +23,7 @@ type ITextHistory interface {
AppendTextMessage(index int, text ...string) Message
AppendImageHistory(role, fileType string, file []byte) error
GetHistoryNames() []string
ListHistoryNames()
}

type TextHistory struct {
Expand Down Expand Up @@ -174,6 +176,16 @@ func (t *TextHistory) GetHistoryNames() []string {
return names
}

func (t *TextHistory) ListHistoryNames() {
for _, name := range t.GetHistoryNames() {
if name == t.GetSelectedHistory() {
fmt.Println(utils.Green + name + utils.Reset)
continue
}
fmt.Println(name)
}
}

func textContent(text ...string) []IContent {
var content []IContent

Expand Down
Loading

0 comments on commit 0373303

Please sign in to comment.