Skip to content

Commit

Permalink
1.1.0 Beta Release
Browse files Browse the repository at this point in the history
  • Loading branch information
chrlesur committed Sep 29, 2024
1 parent 6a73a26 commit 57aeef9
Show file tree
Hide file tree
Showing 8 changed files with 1,127 additions and 7 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Translator

Translator est un outil en ligne de commande puissant pour traduire des documents texte, principalement en format Markdown, en utilisant différents moteurs d'IA tels que Claude, GPT-4, ou Ollama.
Translator est un outil en ligne de commande puissant pour traduire des documents texte, principalement en format Markdown, en utilisant différents moteurs d'IA tels que Claude, GPT-4, Ollama, ou AI.YOU.

## Version actuelle

Version : 1.1.0 Beta

## Caractéristiques

- Support de multiples moteurs d'IA : Anthropic Claude, OpenAI GPT, et Ollama
- Support de multiples moteurs d'IA : Anthropic Claude, OpenAI GPT, Ollama, et AI.YOU
- Traduction de fichiers entiers ou mode interactif pour des traductions rapides
- Préservation du formatage, y compris les sauts de ligne et l'espacement
- Gestion intelligente des lots pour optimiser les performances et respecter les limites des API
Expand Down Expand Up @@ -81,6 +85,15 @@ Pour mettre à jour Translator vers la dernière version, naviguez dans le répe
git pull
go install ./cmd/translator
```
## Configuration

Créez un fichier `.env` à la racine du projet avec les informations d'authentification nécessaires :
```
CLAUDE_API_KEY=votre_clé_claude
OPENAI_API_KEY=votre_clé_openai
AIYOU_EMAIL=votre_email_aiyou
AIYOU_PASSWORD=votre_mot_de_passe_aiyou
```

### Utilisation sans installation

Expand All @@ -105,6 +118,12 @@ Cette méthode créera un exécutable nommé `translator` (ou `translator.exe` s
```
translator translate input.md EN --engine "anthropic" --model "claude-3-sonnet-20240229"
```
### Utilisation d'AI.YOU

Pour utiliser AI.YOU, **vous devez spécifier l'ID de l'assistant lors de l'exécution de la commande** :
```
translator translate input.md EN --engine aiyou -A votre_id_assistant
```

### Mode interactif

Expand All @@ -125,10 +144,13 @@ translator test-api --engine "anthropic" --model "claude-3-5-sonnet-20240620"
- `-t, --threads` : Nombre de threads pour le traitement parallèle (défaut: 4)
- `-s, --source-lang` : Langue source du texte à traduire (défaut: français)
- `-i, --instruction` : Instruction complémentaire pour la traduction
- `-e, --engine` : Moteur de traduction (anthropic, openai, ollama)
- `-e, --engine` : Moteur de traduction (anthropic, openai, ollama, aiyou)
- `-m, --model` : Modèle spécifique à utiliser pour le moteur choisi
- `-A, --aiyou-assistant-id` : ID de l'assistant AI.YOU (requis pour le moteur aiyou)
- `--ollama-host` : Hôte Ollama (défaut: localhost)
- `--ollama-port` : Port Ollama (défaut: 11434)
- `-c, --context-size` : Taille du contexte pour le modèle (0 pour utiliser la valeur par défaut)


## Configuration

Expand Down
Binary file added bin/translator-1.1.0-beta-x86_64.exe
Binary file not shown.
29 changes: 25 additions & 4 deletions cmd/translator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

const VERSION = "1.0.0"
const VERSION = "1.1.0-Beta"

var (
debug bool
Expand All @@ -25,6 +25,7 @@ var (
ollamaHost string
ollamaPort string
contextSize int
aiyouAssistantID string
)

func init() {
Expand All @@ -33,11 +34,12 @@ func init() {
rootCmd.PersistentFlags().IntVarP(&numThreads, "threads", "t", 4, "Nombre de threads pour le traitement parallèle")
rootCmd.PersistentFlags().StringVarP(&sourceLang, "source-lang", "s", "français", "Langue source du texte à traduire")
rootCmd.PersistentFlags().StringVarP(&additionalInstruction, "instruction", "i", "", "Instruction complémentaire pour la traduction")
rootCmd.PersistentFlags().StringVarP(&engine, "engine", "e", "anthropic", "Moteur de traduction (anthropic, openai, ollama)")
rootCmd.PersistentFlags().StringVarP(&engine, "engine", "e", "anthropic", "Moteur de traduction (anthropic, openai, ollama, aiyou)")
rootCmd.PersistentFlags().StringVarP(&model, "model", "m", "claude-3-5-sonnet-20240620", "Modèle spécifique à utiliser pour le moteur choisi")
rootCmd.PersistentFlags().StringVar(&ollamaHost, "ollama-host", "localhost", "Hôte Ollama")
rootCmd.PersistentFlags().StringVar(&ollamaPort, "ollama-port", "11434", "Port Ollama")
rootCmd.PersistentFlags().IntVarP(&contextSize, "context-size", "c", 0, "Taille du contexte pour le modèle (0 pour utiliser la valeur par défaut)")
rootCmd.PersistentFlags().StringVarP(&aiyouAssistantID, "aiyou-assistant-id", "A", "", "ID de l'assistant AI.YOU")

rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(translateCmd)
Expand All @@ -49,7 +51,7 @@ var rootCmd = &cobra.Command{
Use: "translator",
Short: "Translator est un outil de traduction de documents utilisant divers moteurs d'IA",
Long: `Translator est un outil en ligne de commande pour traduire des documents texte,
principalement en format Markdown, en utilisant différents moteurs d'IA comme Claude, GPT-4, ou Ollama.`,
principalement en format Markdown, en utilisant différents moteurs d'IA comme Claude, GPT-4, Ollama ou AI.YOU.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logger.SetDebugMode(debug)
logger.Info(fmt.Sprintf("Translator version %s", VERSION))
Expand Down Expand Up @@ -151,6 +153,25 @@ func getTranslationClient() translation.TranslationClient {
case "ollama":
logger.Debug(fmt.Sprintf("Utilisation d'Ollama avec l'hôte %s et le port %s", ollamaHost, ollamaPort))
return api.NewOllamaClient(ollamaHost, ollamaPort, model, debug, getContextSize("ollama"))
case "aiyou":
aiyouEmail := os.Getenv("AIYOU_EMAIL")
aiyouPassword := os.Getenv("AIYOU_PASSWORD")
if aiyouEmail == "" || aiyouPassword == "" {
logger.Error("L'email ou le mot de passe AI.YOU n'est pas défini dans le fichier .env")
return nil
}
if aiyouAssistantID == "" {
logger.Error("L'ID de l'assistant AI.YOU n'est pas spécifié")
return nil
}
logger.Debug(fmt.Sprintf("Utilisation du moteur AI.YOU avec l'email : %s", aiyouEmail))
client := api.NewAIYOUClient(aiyouAssistantID, debug)
err := client.Login(aiyouEmail, aiyouPassword)
if err != nil {
logger.Error(fmt.Sprintf("Erreur lors de la connexion à AI.YOU : %v", err))
return nil
}
return client
default:
logger.Error(fmt.Sprintf("Moteur non reconnu : %s", engine))
return nil
Expand All @@ -164,7 +185,7 @@ func getContextSize(engineType string) int {
switch engineType {
case "anthropic", "openai":
return 4000
case "ollama":
case "ollama", "aiyou":
return 2000
default:
return 2000
Expand Down
135 changes: 135 additions & 0 deletions docs/aiyou.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Module AI.YOU

Ce module contient l'implémentation du client AI.YOU pour le projet Translator.

## Fichier

### aiyou.go

Ce fichier implémente le client pour l'API AI.YOU.

Principales fonctionnalités :
- Initialisation du client avec l'ID de l'assistant et le mode debug
- Authentification avec email et mot de passe
- Méthode `Translate` pour envoyer des requêtes de traduction à l'API AI.YOU
- Gestion des threads et des runs pour le processus de traduction
- Gestion des erreurs et des tentatives de reconnexion

## Structure principale

### AIYOUClient

```go
type AIYOUClient struct {
Token string
AssistantID string
Debug bool
Timeout time.Duration
}
```

- `Token` : Token d'authentification pour l'API AI.YOU
- `AssistantID` : ID de l'assistant AI.YOU à utiliser
- `Debug` : Active ou désactive le mode debug
- `Timeout` : Durée maximale d'attente pour les requêtes API

## Fonctions principales

### NewAIYOUClient

```go
func NewAIYOUClient(assistantID string, debug bool) *AIYOUClient
```

Crée une nouvelle instance du client AI.YOU.

### Login

```go
func (c *AIYOUClient) Login(email, password string) error
```

Authentifie le client avec l'email et le mot de passe fournis.

### Translate

```go
func (c *AIYOUClient) Translate(content, sourceLang, targetLang, additionalInstruction string) (string, error)
```

Traduit le contenu donné de la langue source vers la langue cible.

## Fonctions internes

### createThread

```go
func (c *AIYOUClient) createThread() (string, error)
```

Crée un nouveau thread de conversation.

### addMessage

```go
func (c *AIYOUClient) addMessage(threadID, content string) error
```

Ajoute un message au thread spécifié.

### createRun

```go
func (c *AIYOUClient) createRun(threadID string) (string, error)
```

Crée un nouveau run pour le thread spécifié.

### retrieveRun

```go
func (c *AIYOUClient) retrieveRun(threadID, runID string) (map[string]interface{}, error)
```

Récupère le statut d'un run en cours.

### waitForCompletion

```go
func (c *AIYOUClient) waitForCompletion(threadID, runID string) (*map[string]interface{}, error)
```

Attend la fin d'un run et retourne le résultat.

### makeAPICall

```go
func (c *AIYOUClient) makeAPICall(endpoint, method string, data []byte) ([]byte, error)
```

Effectue un appel à l'API AI.YOU avec gestion des erreurs et logging.

## Utilisation

Pour utiliser le client AI.YOU :

1. Créez une instance de `AIYOUClient` avec `NewAIYOUClient`
2. Appelez `Login` pour authentifier le client
3. Utilisez `Translate` pour effectuer des traductions

Exemple :

```go
client := api.NewAIYOUClient("assistant_id", true)
err := client.Login("[email protected]", "password")
if err != nil {
log.Fatal(err)
}
translation, err := client.Translate("Bonjour", "français", "anglais", "")
if err != nil {
log.Fatal(err)
}
fmt.Println(translation)
```

Note : Assurez-vous d'avoir configuré les variables d'environnement `AIYOU_EMAIL` et `AIYOU_PASSWORD` dans votre fichier `.env` avant d'utiliser ce client.
Loading

0 comments on commit 57aeef9

Please sign in to comment.