paint-brush
Wie gut ist die PaLM API von Google?von@raymondcamden
1,431 Lesungen
1,431 Lesungen

Wie gut ist die PaLM API von Google?

von Raymond Camden10m2023/10/28
Read on Terminal Reader

Zu lang; Lesen

Ich gehe davon aus, dass jeder einzelne Entwickler auf dem Planeten im letzten Jahr oder so mit GenAI überschwemmt wurde.
featured image - Wie gut ist die PaLM API von Google?
Raymond Camden HackerNoon profile picture
0-item
1-item

Wie jeder andere Entwickler auf dem Planeten wurde ich im letzten Jahr oder so ziemlich mit GenAI überschwemmt. Ich finde es genauso faszinierend wie die meisten Leute (fragen Sie mich, wie oft ich mit ChatGPT Konvertierungen zum Thema Katzen hatte), aber obwohl es Spaß macht, damit zu spielen, habe ich auch viel über die praktischen Aspekte nachgedacht. insbesondere über API und Integrationen. Ich bin immer noch unglaublich neu in diesem Bereich und, ich gebe zu, bei vielen Details noch ziemlich unklar, aber ich dachte, ich würde Ihnen einige erste Eindrücke mitteilen, die ich bei der Arbeit mit Googles LLM, PaLM 2, gewonnen habe.


Ein Blick auf die PaLM-API von Google



Beachten Sie zunächst, dass für die PaLM-API und MakerSuite, bei der es sich um ein webbasiertes Frontend handelt, ein Google-Login erforderlich ist und zumindest für die API selbst eine Zugriffsanfrage erforderlich ist. Bei mir hat das weniger als 24 Stunden gedauert, und ich glaube, diese Zeit geht jetzt sogar noch schneller, da Google die Warteliste schrumpft. Wie gesagt, ich hatte ziemlich schnell eine Zustimmung und ich gehe davon aus, dass die meisten Leute das auch bekommen werden, aber YMMV.


Willkommens-E-Mail von Google bezüglich des Zugriffs auf PaLM API und MakerSuite


Wenn Sie MakerSuite laden, werden Ihnen verschiedene Aufforderungen angezeigt, mit dem Spielen mit der API zu beginnen:


MakerSuite-Website mit Eingabeaufforderungen für Text, Daten und Chat.


Als ich hier ankam, ging ich direkt zur Option „Textaufforderung“, da ich dachte, dass dies die einfachste und bekannteste Option wäre. Die Beispiele, die mir den Einstieg erleichtern, haben mir sofort sehr gefallen:


MakerSuite-Benutzeroberfläche für Textansagen.


Ich begann mit dieser Eingabeaufforderung:


 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.


Und bekam:


 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.


Das entspricht in etwa dem, was ich von ChatGPT und anderen Diensten erwarten würde, obwohl ich von der Schreibweise der Katze etwas überrascht war. Für Neugierige: Es scheint eine falsche Schreibweise von Mephistopheles zu sein, obwohl es ziemlich cool wäre, wenn es sich um ein Wortspiel mit „Flöhen“ handelte.

Was mich sofort anzog, war die Schaltfläche „Code abrufen“ oben. Wenn Sie darauf klicken, werden vier einzigartige Optionen angezeigt:


Codebeispiele in cuRL, JavaScript, JSON und Python


Obwohl die Antwort seltsamerweise im Code enthalten war, fand ich es absolut toll, wie einfach das war! Hier ist das JavaScript, nachdem ich die Antwort manuell entfernt habe:


 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)); });


Schauen Sie sich zunächst an, wie einfach die Authentifizierung ist – ich muss buchstäblich meinen Schlüssel einfügen. Ich habe in der Vergangenheit viele Google-APIs verwendet und fast jedes Mal war die Authentifizierung ein Ärgernis. (Das ist wahrscheinlich völlig meine Schuld!) Beachten Sie auch, wie nützlich es ist, den Beispielcode hier zu kommentieren. Ich bin ehrlich und sage trotz der Kommentare, dass es hier Dinge gibt, die ich nicht ganz verstehe, aber abgesehen davon hatte ich das fast sofort lokal am Laufen.


Hier ist das Ergebnis davon:


 [ { "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 ]


Ich finde den Aspekt der Sicherheitsbewertungen am faszinierendsten, da er eine großartige Möglichkeit zu sein scheint, Ihren automatisierten Antworten „Leitplanken“ hinzuzufügen.


Nachdem ich damit herumgespielt hatte, habe ich mir die Funktion „Datenabfrage“ angeschaut:


Benutzeroberfläche für Dateneingabe


Soweit ich weiß, können Sie mit dieser Funktion eine Beispielliste mit Daten erstellen und auf der Grundlage dieser Eingabe dann zusätzliche Datenzeilen hinzufügen und PaLM die entsprechende zweite Spalte angeben lassen. Ich habe das Beispiel „Gegensätze“ verwendet, da es mir am einfachsten erschien:


Beispieltabellendaten für Gegensätze


Das Ausführen mit ihrem Beispiel funktioniert wie erwartet:


Mit falschen und schnellen Eingaben erhalten Sie richtige und langsame Antworten


Ich habe „Dumm“, „Kalt“ und „Links“ ausprobiert und Folgendes erhalten:


Angesichts von „dumm“, „kalt“ und „links“ bekam ich: „Kein Inhalt“, „heiß“ und „rechts“.


Wie Sie sehen, konnte es kein Gegenteil von dumm finden, funktionierte aber bei den anderen korrekt. Soweit ich sehen kann, „formatiert“ der Code dafür einfach die Tabellendaten in einer Eingabeaufforderung:


 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)); });


Beachten Sie jedoch, dass Variablen in Eingabeaufforderungen zulässig sind, was ziemlich cool ist. Als ich das ausführte, war die Ausgabe (insbesondere der output in JSON, ich ignoriere das Ergebnis des Ergebnisses) kurz und bündig: „Richtig“, was schön ist. Ich vermute, dass dies umso besser funktioniert, je komplexer und vollständiger Ihre Tabelle ist.


Also ... erste Eindrücke – ich finde es wirklich toll, wie gut ich mit MakerSuite Tests im Web durchführen kann und wie schnell ich das in den Code übernehmen und mit der Arbeit beginnen kann. Ich war so beeindruckt, dass ich gestern damit in etwa zwanzig Minuten eine „echte“ Demo erstellt habe.


Auch hier veröffentlicht.