studio
latest
false
Important :
La localisation du contenu nouvellement publié peut prendre 1 à 2 semaines avant d’être disponible.
UiPath logo, featuring letters U and I in white

Guide de l’utilisateur de Studio

Dernière mise à jour 29 mai 2025

Intégration d'OpenAI avec des workflows codés

Ce tutoriel vous guide tout au long du processus d’automatisation de la récupération de la description de l’article Wikipedia de UiPath, puis de son envoi au Chat GPT de OpenAI pour le rallonger.
Prérequis
  1. Créez un workflow codé en sélectionnant Nouveau (New), puis Workflow codé (Coded Workflow) à partir du groupe Fichier (File).
  2. Créez une clé API pour OpenAI et enregistrez-la. Ajoutez la clé API en tant que variable d'environnement système. Redémarrez votre machine pour vous assurer que les modifications sont enregistrées.
  3. Dans Studio, avant la méthode Exécuter (Execute), créez une chaîne statique privée en lecture seule pour récupérer la clé API OpenAI à partir des variables d'environnement de votre système à l'aide du code suivant :
    private static readonly string OpenAiApiKey = Environment.GetEnvironmentVariable("OPEN_AI_API_KEY");private static readonly string OpenAiApiKey = Environment.GetEnvironmentVariable("OPEN_AI_API_KEY");
    Remarque : assurez-vous que le nom de la variable de la méthode OpenAiApiKey est le même que celui que vous avez ajouté à votre environnement système.
  4. Récupérez les éléments d'IU que vous devez automatiser à partir de Wikipedia. Accédez à l'onglet Référentiel d'objets (Object Repository) et créez une application nommée Wikipedia.
  5. Créez deux écrans pour l'application Wikipedia :
    1. WikiMainScreen : la page de destination où vous effectuez la recherche. Pour cet écran, créez deux éléments :
      • SearchBar
      • Bouton de recherche
    2. UiPathWikiPage : l'article Wikipedia sur UiPath qui en résulte. Pour cet écran, créez l'élément UiPathDescription, qui indique le premier paragraphe de l'article.


  6. Use the UiAutomation service, along with the Open coded automation API, to open the Wikipedia landing page using the following code:
    var wikiScreen= uiAutomation.Open(ObjectRepository.Descriptors.WikiMainScreen);var wikiScreen= uiAutomation.Open(ObjectRepository.Descriptors.WikiMainScreen);
  7. Search for UiPath in the Wikipedia search, using the Type Into coded automation API.
    wikiScreen.TypeInto(ObjectRepository.Descriptors.WikiMainScreen.SearchBar, "UiPath");wikiScreen.TypeInto(ObjectRepository.Descriptors.WikiMainScreen.SearchBar, "UiPath");
     
  8. Click the search button to perform the search, using the Click coded automation API.
    wikiScreen.Click(ObjectRepository.Descriptors.WikiMainScreen.SearchButton);wikiScreen.Click(ObjectRepository.Descriptors.WikiMainScreen.SearchButton);
  9. Get the description about UiPath from the Wikipedia article, using the Attach and Get Text coded automation APIs. The Attach coded automation API behaves similarly to the Use Application/Browser activity, allowing you to focus on an already open Application/Browser and automate it. Use the following code:
    var uipathWikiPage = uiAutomation.Attach(ObjectRepository.Descriptors.UiPathWikiPage);
    var uipathWikiDescription = uipathWikiPage.GetText(ObjectRepository.Descriptors.UiPathWikiPage.UiPathDescription);
    Log("This is the UiPath's wikipedia description: " + uipathWikiDescription);var uipathWikiPage = uiAutomation.Attach(ObjectRepository.Descriptors.UiPathWikiPage);
    var uipathWikiDescription = uipathWikiPage.GetText(ObjectRepository.Descriptors.UiPathWikiPage.UiPathDescription);
    Log("This is the UiPath's wikipedia description: " + uipathWikiDescription);
    
  10. Envoyer la description à ChatGPT à l'aide de votre compte OpenAI
    1. Créez une variable nommée api pour initialiser votre compte OpenAI auquel vous pouvez accéder à l'aide de la clé API fournie. Utilisez la variable suivante :
      var api = new OpenAIAPI(OpenAiApiKey);var api = new OpenAIAPI(OpenAiApiKey);
    2. Créez une variable nommée chatResult, dans laquelle vous initialisez le nouveau chat et envoyez une invite à ChatGPT. Utilisez le code suivant :
      var chatResult = api.Chat.CreateChatCompletionAsync("Please rewrite the following description about UiPath: '" + uipathWikiDescription + "', and make it longer").Result;var chatResult = api.Chat.CreateChatCompletionAsync("Please rewrite the following description about UiPath: '" + uipathWikiDescription + "', and make it longer").Result;
  11. Affichez la réponse de Chat GPT dans une zone de message, en utilisant l'expression suivante :
    MessageBox.Show(chatResult.Choices[0].Message.Content);MessageBox.Show(chatResult.Choices[0].Message.Content);


Exemple de projet

Pour suivre les étapes et essayer vous-même le tutoriel, téléchargez l’exemple de projet suivant : Intégration d’OpenAI avec des workflows codés (Integrating OpenAI with coded workflows).

Cette page vous a-t-elle été utile ?

Obtenez l'aide dont vous avez besoin
Formation RPA - Cours d'automatisation
Forum de la communauté UiPath
Uipath Logo White