지구상의 다른 모든 개발자와 마찬가지로 저도 지난 1년 정도 GenAI에 어느 정도 푹 빠져 있었습니다. 저는 이것이 대부분의 사람들만큼 매력적이라고 생각합니다(ChatGPT를 사용하여 고양이 관련 전환을 경험한 횟수에 대해 저에게 물어보세요). 가지고 놀기도 재미있지만 실용적인 측면에 대해서도 많이 생각해 왔습니다. 특히 API 및 통합을 통해. 저는 아직 이 모든 것에 대해 믿을 수 없을 만큼 낯설고 많은 세부 사항에 대해 여전히 모호 하다는 점을 인정합니다. 하지만 Google의 LLM인 PaLM 2 와 함께 일하면서 느낀 몇 가지 초기 인상을 공유하고 싶습니다.
우선 주의할 점은 PaLM API와 웹 기반 프론트엔드인 MakerSuite는 구글 로그인이 필요하며, 적어도 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 의 철자가 틀린 것처럼 보이지만 "벼룩"에 대한 말장난이라면 꽤 괜찮습니다.
내가 바로 끌린 것은 "코드 받기" 버튼 상단이었습니다. 이것을 클릭하면 네 가지 고유한 옵션이 나타납니다.
이상하게도 코드에 응답이 포함되어 있었지만 이것이 얼마나 간단한지 정말 마음에 들었습니다! 응답을 수동으로 제거한 후의 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이 해당 두 번째 열을 지정하도록 할 수 있습니다. 나는 가장 단순해 보이는 '반대' 샘플을 사용했습니다.
샘플을 실행하면 예상대로 작동합니다.
"Dumb", "Cold" 및 "Left"를 시도한 결과 다음과 같은 결과가 나왔습니다.
보시다시피, dumb의 반대말을 찾는데 실패했지만 다른 것에서는 올바르게 작동했습니다. 내가 볼 수 있듯이 이에 대한 코드는 프롬프트에서 표 형식 데이터를 간단히 '형식화'합니다.
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를 사용하여 웹에서 얼마나 잘 테스트할 수 있는지, 그리고 얼마나 빨리 이를 코드로 가져와 작업을 시작할 수 있는지 정말 궁금합니다. 저는 너무 감동해서 어제 약 20분 만에 이것으로 "진짜" 데모를 만들었습니다.
여기에도 게시되었습니다.