地球上の他のすべての開発者と同様に、私もここ 1 年ほどで GenAI にどっぷりつかってきました。私もほとんどの人たちと同じようにこれを魅力的だと思っています (ChatGPT で猫関連の変換を何回したか聞いてください)。遊んでいて楽しい一方で、その実用的な側面についてもたくさん考えてきました。特に API と統合を介して。私はまだこれらすべてについて非常に初心者であり、多くの詳細についてはまだかなり曖昧であることを認めますが、Google の LLM、 PaLM 2を使用して感じた最初の印象をいくつか共有したいと思います。
何よりもまず、PaLM API と Web ベースのフロントエンドである MakerSuite には Google ログインが必要であり、少なくとも API 自体はアクセスを要求する必要があることに注意してください。私の場合、これには 24 時間もかかりませんでしたが、Google が待機リストを縮小しているため、この時間はさらに早くなっていると思います。先ほども言いましたが、私はかなり早く承認されましたし、ほとんどの人がそうするだろうと予想していますが、YMMV はそうでした。
MakerSuite をロードすると、API の使用を開始するためのさまざまなプロンプトが表示されます。
最初にここに来たとき、オプションの中で最もシンプルでわかりやすいだろうと考えて、「テキスト プロンプト」オプションを選択しました。すぐに、開始に役立つサンプルを本当にありがたく思いました。
私は次のプロンプトから始めました。
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.
そして得たもの:
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.
これは、ChatGPT や他のサービスに期待されるものとほぼ同等ですが、猫のスペルには少し驚きました。興味のある人にとっては、これはMephistophelesのスペルミスであるように見えますが、「ノミ」をもじったものであれば、それは非常にクールです。
私がすぐに惹かれたのは、「コードを取得」ボタンの上部でした。これをクリックすると、4 つの独自のオプションが表示されます。
奇妙なことにコード内に応答が含まれていましたが、このシンプルさがとても気に入りました。応答を手動で削除した後の JavaScript は次のとおりです。
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)); });
まず、認証がいかに簡単かを見てください。文字通りキーを貼り付ける必要があります。私はこれまで多くの Google API を使用してきましたが、ほぼ毎回、認証が面倒でした。 (これはおそらく完全に私のせいです!) また、サンプル コードのコメントがうまく利用されている点にも注目してください。正直に言うと、コメントを見てもよくわからない部分もありますが、それを除けば、ほぼすぐにローカルで実行できました。
その結果は次のとおりです。
[ { "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 ]
安全性評価の側面が最も魅力的だと思います。これは、自動応答に「ガードレール」を追加する優れた方法であると思われます。
これを試した後、「データ プロンプト」機能を調べました。
私が知る限り、この機能を使用すると、データのサンプル リストを取得し、その入力に基づいてデータの行を追加し、PaLM に対応する 2 番目の列を指定させることができます。最も単純だと思われる「Opposites」サンプルを使用しました。
サンプルを使用して実行すると、期待どおりに動作します。
「Dumb」、「Cold」、「Left」を試してみたところ、次の結果が得られました。
ご覧のとおり、ダムの反対語を見つけることはできませんでしたが、他のものについては正しく機能しました。私が見る限り、このコードは単にプロンプト内の表形式のデータを「フォーマット」しているだけです。
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)); });
ただし、注意すべき点は、プロンプトで変数を使用できることです。これは非常に優れています。これを実行すると、出力 (具体的には JSON でのoutput
値。結果の結果は無視します) は短くて分かりやすいものでした。「そのとおりです。これは素晴らしいことです。」私の推測では、テーブルが複雑で完全であればあるほど、これはうまく機能すると思います。
それで...第一印象 - MakerSuite が Web 上でどれだけうまくテストできるか、そしてどれだけ早くそれをコードに落とし込んで作業を開始できるか、とても興味があります。とても感銘を受けたので、昨日、これを使った「本物の」デモを約 20 分で構築しました。
ここでも公開されています。