paint-brush
Quelle est la qualité de l'API PaLM de Google ?par@raymondcamden
1,431 lectures
1,431 lectures

Quelle est la qualité de l'API PaLM de Google ?

par Raymond Camden10m2023/10/28
Read on Terminal Reader

Trop long; Pour lire

Comme, je suppose, tous les développeurs de la planète, j'ai été quelque peu inondé de GenAI au cours de la dernière année.
featured image - Quelle est la qualité de l'API PaLM de Google ?
Raymond Camden HackerNoon profile picture
0-item
1-item

Comme tous les autres développeurs de la planète, j'ai été quelque peu inondé de GenAI au cours de la dernière année. Je trouve cela aussi fascinant que la plupart des gens (demandez-moi combien de fois j'ai eu des conversions liées aux chats avec ChatGPT) mais même si c'est amusant de jouer avec, j'ai aussi beaucoup réfléchi aux aspects pratiques , notamment via l'API et les intégrations. Je suis encore incroyablement nouveau dans tout cela et, je l'admets, encore très flou sur de nombreux détails, mais j'ai pensé partager quelques premières impressions que j'ai eues en travaillant avec le LLM de Google, PaLM 2 .


Un aperçu de l'API PaLM de Google



Tout d'abord, notez que l'API PaLM et MakerSuite, qui est une interface Web, nécessitent une connexion Google, et au moins l'API elle-même nécessite une demande d'accès. Pour moi, cela a pris moins de vingt-quatre heures, et je pense que ce temps est encore plus rapide maintenant que Google réduit la liste d'attente. Comme je l'ai dit, j'ai eu une approbation assez rapide et j'espère que c'est ce que la plupart des gens auront, mais YMMV.


E-mail de bienvenue de Google concernant l'accès à l'API PaLM et MakerSuite


Lorsque vous chargez MakerSuite, un ensemble de différentes invites vous est présenté pour commencer à jouer avec l'API :


Site MakerSuite affichant des invites pour le texte, les données et le chat.


Quand je suis arrivé ici, je suis allé directement dans l'option "Invite de texte" car je pensais que ce serait l'option la plus simple et la plus reconnaissable. Tout de suite, j'ai vraiment apprécié les exemples pour aider à démarrer :


Interface utilisateur MakerSuite pour les invites de texte.


J'ai commencé avec cette invite :


 Write a story about a magic cat who can only do magic when speaking in reverse. Also, their magic normally backfires in a humorous and harmless manner. The story should be appropriate for a young child.


Et j'ai obtenu :


 Once upon a time, there was a magic cat named Mr. Mistoffelees. He was a very special cat, because he could only do magic when he spoke in reverse. One day, Mr. Mistoffelees was walking down the street when he saw a little girl crying. "What's wrong?" he asked. "I lost my doll," the little girl said. "I've looked everywhere for it, but I can't find it." Mr. Mistoffelees thought for a moment. "I can help you find your doll," he said. "But I can only do it if you speak in reverse." The little girl was confused, but she agreed. "Okay," she said. "I'll try." "Dolla," the little girl said. "Lose, I did." Mr. Mistoffelees smiled. "Your doll is under the bed," he said. The little girl ran to her house and looked under the bed. Sure enough, there was her doll. She picked it up and hugged it tightly. "Thank you," she said to Mr. Mistoffelees. "You're a very kind cat." "You're welcome," Mr. Mistoffelees said. "I'm always happy to help." Mr. Mistoffelees continued to use his magic to help people. He made lost children find their way home, he helped people find their lost pets, and he even helped people find their lost keys. But sometimes, his magic would backfire in a humorous way. One day, Mr. Mistoffelees was trying to help a woman find her lost car. He said the magic words in reverse, but instead of making the car appear, it made the woman's hair stand on end. The woman laughed so hard that she forgot all about her car. Another time, Mr. Mistoffelees was trying to help a man get a job. He said the magic words in reverse, but instead of getting the man a job, it made the man's tie fall off. The man laughed so hard that he forgot all about his interview. Mr. Mistoffelees' magic was always a lot of fun, and it always made people happy. He was a very special cat, and he used his magic to make the world a better place.


C'est à peu près à égalité avec ce que j'attendrais de ChatGPT et d'autres services, même si j'ai été un peu surpris par l'orthographe du chat. Pour les gens curieux, il semble que ce soit une faute d'orthographe de Méphistophélès , même si c'était un jeu de mots sur "puces", alors c'est plutôt cool.

Ce vers quoi je me suis tout de suite tourné, c'est le bouton "Obtenir le code". En cliquant dessus, quatre options uniques s'affichent :


Exemples de code en cuRL, JavaScript, JSON et Python


Même si la réponse était curieusement incluse dans le code, j'ai vraiment adoré sa simplicité ! Voici le JavaScript après avoir supprimé manuellement la réponse :


 const { TextServiceClient } = require("@google-ai/generativelanguage"); const { GoogleAuth } = require("google-auth-library"); const MODEL_NAME = "models/text-bison-001"; const API_KEY = "YOUR API KEY"; const client = new TextServiceClient({ authClient: new GoogleAuth().fromAPIKey(API_KEY), }); const promptString = `Write a story about a magic cat who can only do magic when speaking in reverse. Also, their magic normally backfires in a humorous and harmless manner. The story should be appropriate for a young child.`; const stopSequences = []; client.generateText({ // required, which model to use to generate the result model: MODEL_NAME, // optional, 0.0 always uses the highest-probability result temperature: 0.7, // optional, how many candidate results to generate candidateCount: 1, // optional, number of most probable tokens to consider for generation top_k: 40, // optional, for nucleus sampling decoding strategy top_p: 0.95, // optional, maximum number of output tokens to generate max_output_tokens: 1024, // optional, sequences at which to stop model generation stop_sequences: stopSequences, // optional, safety settings safety_settings: [{"category":"HARM_CATEGORY_DEROGATORY","threshold":1},{"category":"HARM_CATEGORY_TOXICITY","threshold":1},{"category":"HARM_CATEGORY_VIOLENCE","threshold":2},{"category":"HARM_CATEGORY_SEXUAL","threshold":2},{"category":"HARM_CATEGORY_MEDICAL","threshold":2},{"category":"HARM_CATEGORY_DANGEROUS","threshold":2}], prompt: { text: promptString, }, }).then(result => { console.log(JSON.stringify(result, null, 2)); });


Tout d’abord, regardez à quel point l’authentification est simple : je dois littéralement coller ma clé. J'ai utilisé beaucoup d'API Google dans le passé, et presque à chaque fois, l'authentification est un problème. (C'est probablement entièrement de ma faute !) Notez également l'utilité des commentaires ici pour l'exemple de code. Je vais être honnête et dire que même avec les commentaires, il y a des choses ici que je ne comprends pas vraiment, mais en dehors de cela, j'ai fait fonctionner cela localement presque immédiatement.


Voici le résultat de cela :


 [ { "candidates": [ { "safetyRatings": [ { "category": "HARM_CATEGORY_DEROGATORY", "probability": "NEGLIGIBLE" }, { "category": "HARM_CATEGORY_TOXICITY", "probability": "NEGLIGIBLE" }, { "category": "HARM_CATEGORY_VIOLENCE", "probability": "NEGLIGIBLE" }, { "category": "HARM_CATEGORY_SEXUAL", "probability": "NEGLIGIBLE" }, { "category": "HARM_CATEGORY_MEDICAL", "probability": "NEGLIGIBLE" }, { "category": "HARM_CATEGORY_DANGEROUS", "probability": "NEGLIGIBLE" } ], "output": "Once upon a time, there was a magic cat named Mr. Mistoffelees. He was a very special cat, because he could only do magic when he spoke in reverse.\n\nOne day, Mr. Mistoffelees was playing in the forest when he saw a little girl who was crying. \"What's wrong?\" he asked.\n\n\"I'm lost,\" the little girl said. \"I can't find my way home.\"\n\nMr. Mistoffelees smiled. \"Don't worry,\" he said. \"I can help you.\"\n\nHe took a deep breath and said, \"Sdrawkcab eht revo spmuj I.\"\n\nSuddenly, the little girl was surrounded by a bright light. When the light faded, she was standing in front of her house.\n\n\"Thank you!\" she said. \"You're a lifesaver!\"\n\nMr. Mistoffelees smiled. \"You're welcome,\" he said. \"Just remember, my magic only works when I speak in reverse.\"\n\nThe little girl nodded. \"I'll remember,\" she said.\n\nThe next day, the little girl was playing in the forest again when she saw a group of boys picking on a smaller boy.\n\n\"Leave him alone!\" she shouted.\n\nThe boys turned to look at her. \"What are you going to do about it?\" one of them asked.\n\nThe little girl took a deep breath and said, \"Sdrawkcab eht revo spmuj I.\"\n\nSuddenly, the boys were surrounded by a bright light. When the light faded, they were all wearing dresses.\n\nThe boys started to laugh. \"What happened to our clothes?\" they asked.\n\n\"That's what you get for picking on a smaller boy,\" the little girl said.\n\nThe boys ran away, laughing.\n\nThe little girl smiled. \"I guess my magic really does work,\" she said.\n\nMr. Mistoffelees was watching from a nearby tree. He smiled. \"I'm glad my magic could help you,\" he said.\n\nThe little girl smiled back. \"Thanks, Mr. Mistoffelees,\" she said. \"You're the best.\"\n\nMr. Mistoffelees purred. \"You're welcome,\" he said. \"I'm always happy to help.\"\n\nThe little girl and Mr. Mistoffelees continued to play in the forest together. They had many more adventures, and Mr. Mistoffelees' magic always helped them out. But even though his magic was powerful, it was also very silly. And it always seemed to backfire in a humorous way.\n\nOne day, Mr. Mistoffelees was trying to help the little girl get a bird out of a tree. He said, \"Sdrawkcab eht revo spmuj I.\"\n\nSuddenly, the bird flew out of the tree and landed on the little girl's head.\n\nThe little girl laughed. \"Thanks, Mr. Mistoffelees,\" she said. \"But I think I would have been able to get the bird out of the tree myself.\"\n\nMr. Mistoffelees purred. \"You're welcome,\" he said. \"I'm just glad I could help.\"\n\nThe little girl and Mr. Mistoffelees continued to play together. They had many more adventures, and Mr. Mistoffelees' magic always helped them out. And even though his magic was silly, it was always kind and helpful." } ], "filters": [], "safetyFeedback": [] }, null, null ]


Je trouve que l'aspect des évaluations de sécurité est le plus fascinant, car il semble être un excellent moyen d'ajouter des « garde-corps » à vos réponses automatisées.


Après avoir joué avec cela, j'ai jeté un œil à la fonctionnalité "Invite de données":


Interface utilisateur d'invite de données


D'après ce que j'ai pu dire, cette fonctionnalité vous permet de prendre un exemple de liste de données et, sur la base de cette entrée, vous pouvez ensuite ajouter des lignes de données supplémentaires et demander à PaLM de spécifier la deuxième colonne correspondante. J'ai utilisé l'exemple « Contraires » car il semblait le plus simple :


Exemples de données tabulaires pour les opposés


L'exécution avec leur exemple fonctionne comme prévu :


Avec des entrées erronées et rapides, vous obtenez des réponses correctes et lentes


J'ai essayé "Dumb", "Cold" et "Left" et j'ai obtenu :


Étant donné stupide, froid et gauche, j'ai eu : Pas de contenu, chaud et juste


Comme vous pouvez le voir, il n’a pas réussi à trouver un opposé à stupide mais a fonctionné correctement pour les autres. Le code pour cela, d'après ce que je peux voir, « formate » simplement les données tabulaires dans une invite :


 const { TextServiceClient } = require("@google-ai/generativelanguage"); const { GoogleAuth } = require("google-auth-library"); const MODEL_NAME = "models/text-bison-001"; const API_KEY = "YOUR API KEY"; const client = new TextServiceClient({ authClient: new GoogleAuth().fromAPIKey(API_KEY), }); const Word = 'Left'; const promptString = `Find a word or phrase with opposite meaning. Word: Strong Opposite: Weak Word: Thick Opposite: Thin Word: Sparse Opposite: Dense Word: Sloppy Opposite: Organized Word: ${Word} Opposite:`; const stopSequences = []; client.generateText({ // required, which model to use to generate the result model: MODEL_NAME, // optional, 0.0 always uses the highest-probability result temperature: 0.7, // optional, how many candidate results to generate candidateCount: 1, // optional, number of most probable tokens to consider for generation top_k: 40, // optional, for nucleus sampling decoding strategy top_p: 0.95, // optional, maximum number of output tokens to generate max_output_tokens: 1024, // optional, sequences at which to stop model generation stop_sequences: stopSequences, // optional, safety settings safety_settings: [{"category":"HARM_CATEGORY_DEROGATORY","threshold":1},{"category":"HARM_CATEGORY_TOXICITY","threshold":1},{"category":"HARM_CATEGORY_VIOLENCE","threshold":2},{"category":"HARM_CATEGORY_SEXUAL","threshold":2},{"category":"HARM_CATEGORY_MEDICAL","threshold":2},{"category":"HARM_CATEGORY_DANGEROUS","threshold":2}], prompt: { text: promptString, }, }).then(result => { console.log(JSON.stringify(result, null, 2)); });


Une chose à noter, cependant, est que les variables sont autorisées dans les invites, ce qui est plutôt cool. Lorsque j'ai exécuté ceci, le résultat (en particulier la valeur output en JSON, j'ignore le résultat) était court et agréable : "Bien", ce qui est bien. Je suppose que plus votre tableau est complexe et complet, mieux cela fonctionnera.


Alors... premières impressions - je cherche vraiment à savoir à quel point MakerSuite me permet de tester sur le Web et à quelle vitesse je suis capable de coder cela et de commencer à travailler. J'ai été tellement impressionné qu'hier, j'ai construit une "vraie" démo avec cela en une vingtaine de minutes.


Également publié ici .