เชื่อมต่อ LLMs ลงไปใน Flutter โดยใช้ Gemini

Amorn Apichattanakul
KBTG Life
Published in
10 min readJun 19, 2024
รูปสร้างโดย LLMs

LLMs นั้นย่อมาจาก Large Language Models เป็นโมเดลที่ถูกฝึกด้วยชุดข้อมูลขนาดใหญ่มาก โดยใช้ Machine Learning ที่เรียกว่า “Deep Learning” ช่วยให้โมเดลสามารถตรวจจับรูปแบบของภาษาและความรู้เพื่อตอบคำถามได้อย่างมีประสิทธิภาพ การสร้าง LLMs นั้นแทบจะเป็นไปไม่ได้เลยสำหรับสตาร์ทอัพและธุรกิจขนาดกลางถึงขนาดย่อม เนื่องจากต้องการข้อมูล เวลา และทรัพยากรอย่างมากกกก ซึ่งใช้เวลาในการฝึกฝนกว่า 5–6 เดือนเลยเชียว ยกตัวอย่างเช่น GPT-4 ใช้พลังงานประมาณ 50 กิกะวัตต์-ชั่วโมง หรือประมาณ 0.02% ของไฟฟ้าที่รัฐแคลิฟอร์เนียผลิตในหนึ่งปี!! (ทั้งนี้ผมขอพักเรื่อง AI และวิกฤตพลังงานไว้ก่อนนะครับ เพราะมันเป็นเรื่องที่ค่อนข้างซับซ้อนและผมยังศึกษาอยู่)

ด้วยเหตุนี้เอง จึงมีแค่บริษัทใหญ่ๆ อย่าง OpenAI ที่ได้รับการสนับสนุนจาก Microsoft และ Gemini โดย Google ที่มีทรัพยากรในการพัฒนาโมเดลดังกล่าว ในบทความนี้ผมจะเน้นไปที่ Gemini ซึ่งรองรับทั้ง iOS/Android และแม้แต่ Flutter ที่สามารถขยายไปยังแพลตฟอร์มอื่นๆ ได้อีก 4 แพลตฟอร์ม (Windows/Mac/Unix/Web)

ทำไมไม่ใช้ OpenAI ล่ะ? ทั้งสองต่างมีจุดแข็งของตัวเอง โดยส่วนตัวผมชอบ Gemini เพราะ Developer-friendly มากกว่า มี Mobile SDK ให้พร้อม ส่วน GPT ถ้าจะใช้ เราต้องเรียก Backend Service เพื่อให้ไปยิงที่ Server GPT อีกครั้งนึง ซึ่งเป็นเรื่องที่ยากกว่าสำหรับ Mobile Developer ครับ

Let’s begin!

เริ่มต้นด้วยการลงทะเบียนที่ Google AI Studio คลิก “Create API key” และแทนที่ YOUR_API_KEY ในคำสั่ง cURL ด้านล่างดู

curl \
-H 'Content-Type: application/json' \
-d '{"contents":[{"parts":[{"text":"Explain how AI works"}]}]}' \
-X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=YOUR_API_KEY'

อะไรนะ?!! ได้ Result แรกแล้วเหรอ หมูขิงๆ! แค่ลงทะเบียนได้ Key มา เราก็เริ่มใช้ LLMs ได้แล้ว

หลังจาก cURL เพื่อรับข้อมูลเสร็จ มาดูวิธีการนำไปใช้ในแอปพลิเคชันของเรากัน

1. เพิ่ม Dependency เปิดไฟล์ pubspec.yaml ของเราและเพิ่ม Dependency ดังนี้

dependencies:
generative_ai: latest_version

2. ติดตั้ง Dependency รัน flutter pub get เพื่อติดตั้ง Dependency ใหม่

3. นำไปใส่ใน Flutter Widget ได้เลย นี่คือตัวอย่างพื้นฐานการใช้แพ็กเกจ Generative AI ใน Flutter Widget

import 'package:google_generative_ai/google_generative_ai.dart';
const apiKey = ...;

void main() async {
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
);
final prompt = 'Explain how AI works';
final content = [Content.text(prompt)];
final response = await model.generateContent(content);
print(response.text);
}

และแล้ว LLMs ตัวแรกเราก็เสร็จ ง่ายอีกแล้ว

งั้นสเต็ปถัดไปล่ะ? แชทบอทที่เรามีต่างจากการติดตั้งแชทบอททั่วไปอย่างไร? ทำไมทั่วโลกต้องมาหวือหวากับ LLMs หารู้ไม่ การจะทำให้มันเจ๋งจริงนั้นจะต้องรู้วิธีการเขียน Prompt ด้วย

Prompting Technique

นี่เป็นความรู้ทั่วไปที่สามารถใช้กับเครื่องมือ Gen AI ใดก็ได้นะครับ ไม่ใช่แค่ Gemini เท่านั้น เทคนิคการให้ Model ตอบได้แม่นยำและใกล้เคียงกับที่เราต้องการมากที่สุดมีตามนี้

ระบุให้ชัด

ระบุสิ่งที่ต้องการให้ชัดเจน ให้บริบทและอธิบายรายละเอียดสิ่งที่คุณต้องการด้วย

อย่าพูดว่า “ตอนนี้หน้าจอเด้งเตือนในแอป ให้ทำยังไงต่อ” โดยไม่มีบริบทหรือเรื่องราวเบื้องหลัง โมเดลจะไม่สามารถตอบคำถามได้ถูกต้อง เอาแค่มนุษย์ก็ยังตอบไม่ได้เลย อยู่ดีๆ เดินมาถามผมแบบนี้ ไม่มี Context ใดๆ จะตอบยังไงเนี่ย

วิธีที่ถูกต้อง ให้พูดว่า “ใช้แอป XX และเข้าไปที่หน้าล็อกอินแล้ว ใส่ชื่อผู้ใช้และรหัสผ่านถูกต้อง แต่มีป็อปอัพเด้งขึ้นมาแจ้งว่ามีปัญหาในการเชื่อมต่อ ฉันควรทำอย่างไร?” ตัวอย่างนี้ชัดเจน เจาะจง และมีเรื่องราว โมเดลจะสามารถให้ความช่วยเหลือคุณดีขึ้น

คิดซะว่าเหมือนคุณกำลังพูดกับมนุษย์ ให้มีบริบทเพียงพอเพื่อเข้าใจสถานการณ์ จะได้เสนอวิธีช่วยคุณถูก

แสดงตัวอย่างก่อนสักนิด

ให้ตัวอย่างคำตอบที่คุณต้องการล่วงหน้า เรียกว่า Few-shot Example เพื่อให้โมเดลรู้ว่าจะตามอย่างไร หลังจากที่เห็น Pattern แล้ว

อย่าถามเพียงคำถาม หากคาดหวังคำตอบในรูปแบบที่เจาะจง

หากคุณต้องการคำตอบในรูปแบบรายการที่ระบุว่าแต่ละอย่างเป็นผลไม้หรือผัก ควรต้องให้ตัวอย่างเช่นนี้

ใช้เครื่องหมายแยก

เช่น เครื่องหมายคำพูด (“”) วงเล็บเหลี่ยม (<>) หรือเครื่องหมายจุดคู่ (:) เพื่อระบุบริบทและข้อมูลที่คุณต้องการให้

ในบางกรณีที่ต้องการให้ข้อมูลเพิ่มเติมเพื่อให้โมเดลระบุ ควรใช้เครื่องหมายแยกเพื่อช่วยให้มันเข้าใจว่าข้อมูลอยู่ที่ไหนและบริบทอยู่ที่ไหน ตัวอย่างด้านล่างนี้ใช้ได้ แต่ในบางกรณีอาจไม่ได้ผล

เพื่อให้มั่นใจว่าคำตอบจะออกมาตรงตามที่ต้องการ ผมเลือกใส่เครื่องหมายคำพูดแยกลงไป ให้โมเดลเห็นว่า อ๋อ ใน Quote คือที่จะให้ทำงานนะ

นี่คือเทคนิคหลักๆ ครับ แต่ยังมีเทคนิคอื่นๆ ที่สามารถทำให้ดูน่าสนใจ สนุกสนาน และเหมือนมนุษย์มากขึ้นไปอีก

ให้บุคลิกและเรื่องราว

มอบหมายบุคลิกและเรื่องราวก่อนที่จะถามคำถามใดๆ เพื่อให้คำตอบดูน่าสนใจมากขึ้น นอกจากนี้ยังสามารถกำหนดข้อจำกัดว่าให้ทำอะไรและไม่ให้ทำอะไร

LLMs มีฟังก์ชันที่เรียกว่า ‘System Instructions’ ซึ่งเราสามารถบรรยายบุคลิกให้มันได้ ถ้าไปลองเล่นที่แอป AI Studio จะอยู่ด้านบน ให้เรากรอกข้อมูลก่อนได้

ผมลองบอกมันว่า จงเป็น ‘ครู’ ให้กับโมเดลและให้ใช้คำแบบที่พูดกับเด็กๆ เท่านั้น แบบเด็กๆ ก็เข้าใจ

เพิ่มข้อมูล Personalize

ฟีดข้อมูล Personalize เข้าไป ก่อนที่ผู้ใช้จะถามคำถาม เพื่อให้ความรู้ตรงกับคำตอบที่ต้องการ

ตามที่เห็น ผมได้ให้ข้อมูล JSON กับโมเดล ซึ่งเราสามารถป้อนข้อมูลนี้ไว้ก่อน เพื่อให้โมเดลสามารถตอบตามความรู้ที่อ่านไว้ล่วงหน้าแล้ว แน่นอนว่าข้อมูล JSON นี้มาจากการเรียก API ที่ผมยิงไว้ก่อนหน้านี้

จากที่เห็นเทคนิคข้างต้น อาจจะสงสัยว่าแล้วมันทำงานอย่างไรกับ Flutter นะ ผมจะเปลี่ยนเทคนิคเหล่านี้ลงใน Flutter ให้ดูกันครับ

ผมจะใช้กรณีตัวอย่างของแอปพลิเคชัน MAKE by KBank เพื่อสร้างผู้ช่วย AI ให้กับคนใช้ โดยทำให้ฉลาดขึ้นด้วยการใช้เทคนิคที่กล่าวถึงข้างต้น

นี่คือ ‘MAKE’ มาสคอตของ MAKE by KBank เป็นเด็กชายวัย 10 ปีที่มีบุคลิกสดใสร่าเริง

มาดูกันทีละสเต็ปครับ

1. ระบุให้ชัด เนื่องจาก LLMs ถูกฝึกด้วยข้อมูลที่กว้างมาก หากเราอนุญาตให้ตอบอะไรก็ได้ที่มันต้องการ บางทีโมเดลก็จับมั่วๆ มาผสม หรืออาจจะไม่ตรงกับที่เราอยากได้ ดังนั้นการที่จะให้มันตอบตรงนั้น เราก็ระบุไปก่อนลูกค้าจะถามเลยตั้งแต่แรก ยกตัวอย่างเช่น

import 'package:google_generative_ai/google_generative_ai.dart';

const apiKey = ...;
// Add the preprompt here, user won't see it but the model will
// understand it
const prompt = '''
Your task is to chat with customers who need helps about financial mobile
application which called "MAKE by KBank". if users ask the question not relate
to financial, customer information, or about application. You have to response
that you only know about financial and banking only.
''';
void main() async {
// Add pre-prompt by using 'systemInstruction'
// They have a different kinds of Content but we will use
// Content.system for this case
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
systemInstruction: Content.system(prompt)
);
final question = 'Explain how AI works';
final content = [Content.text(question)];
final response = await model.generateContent(content);
print(response.text);
};

ผมระบุไปว่าให้ตอบเกี่ยวกับข้อมูลการเงินของ MAKE by KBank เท่านั้นนะ ถ้านอกเหนือจากนี้ให้ตอบไปว่าไม่รู้ ซึ่งส่วนนี้เราระบุให้โมเดลรับทราบถึงสิ่งที่ทำได้และไม่ได้ ก็จะออกมาเป็นแบบด้านล่าง เห็นได้ว่าถ้าเราถามนอกเรื่อง มันจะไม่ยอมตอบ

Example from AI Studio

2. ให้แสดงตัวอย่างก่อนสักนิด ให้ยกตัวอย่างคำตอบที่ต้องการล่วงหน้า เพื่อให้โมเดลรู้ว่าจะต้องตามอย่างไร ด้านล่างนี้ผมจะเปลี่ยนโมเดลให้เป็นแชทแทนแล้วนะครับ จะได้เห็นภาพจริงๆ จะเห็นว่าที่ startChat-history ผมใช้ Text ให้มันดูเป็นตัวอย่างก่อนว่าจะทำยังไงบ้าง ถ้ามีคนถามมา

import 'package:google_generative_ai/google_generative_ai.dart';

const apiKey = ...;
// Add the preprompt here, user won't see it but the model will
// understand it
const prompt = '''
Your task is to chat with customers who need helps about financial mobile
application which called "MAKE by KBank". if users ask the question not relate
to financial, customer information, or about application. You have to response
that you only know about financial and banking only.
''';
void main() async {
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
systemInstruction: Content.system(prompt)
);

// Use a chat with history to include a few-shot example to tell
// model how to response
final chat = await model.startChat(history: [
Content.text("hello"),
Content.model([TextPart('''Hello, I'm MAKE AI,
The financial assistant in your hands. What I can help you today''')]),
Content.text("Teach me how to hack mobile financial app"),
Content.model([TextPart('''Sorry, I can't help with that since I only know
about financial and how to use our app''')]),
]);
final message = "I want to transfer money from my account to my friend";
final response = await chat.sendMessage(Content.text(message));
print(response.text);
};

3. ใช้เครื่องหมายแยก ใช้เครื่องหมายแยกเพื่อแยกข้อมูล เมื่อคุณต้องการป้อนข้อมูลที่เป็นส่วนตัว

import 'package:google_generative_ai/google_generative_ai.dart';

const apiKey = ...;
// Add the preprompt here, user won't see it but the model will
// understand it
const prompt = '''
Your task is to chat with customers who need helps about financial mobile
application which called "MAKE by KBank". if users ask the question not relate
to financial, customer information, or about application. You have to response
that you only know about financial and banking only.
''';
void main() async {
// Call API to get information into the app and feed into the model
final userInformation = '''
{
"name": "Amorn Apichattanakul",
"age": 30,
"gender": "male",
"account_balance" 30000
}
''';
final promptWithData = '''
$prompt
Use the JSON below for customer information
JSON:
$userInformation
''';
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
systemInstruction: Content.system(promptWithData)
);

// Use a chat with history to include a few-shot example to tell
// model how to response
final chat = await model.startChat(history: [
Content.text("hello"),
Content.model([TextPart('''Hello, I'm MAKE AI,
The financial assistant in your hands. What I can help you today''')]),
Content.text("Teach me how to hack mobile financial app"),
Content.model([TextPart('''Sorry, I can't help with that since I only know
about financial and how to use our app''')]),
]);
final message = "I need to check my account balance. How much do I have left";
final response = await chat.sendMessage(Content.text(message));
print(response.text);
};
// Reponse should give me a customer about "Hi, Amorn. Your account balance is 30000"

4. เพิ่มบุคลิกและเรื่องราว เพิ่มบุคลิกและเรื่องราว เพื่อให้คำตอบมีความเฉพาะมากขึ้นและลูกค้าจะได้สนุกขึ้นด้วย ในการตั้งค่าด้านล่าง ผมได้เพิ่มบุคลิกของบอทให้เป็นเด็กชายวัย 10 ปีที่มีลักษณะเป็นมิตรและร่าเริง ชอบช่วยเหลือ และได้เพิ่มคำถามพบบ่อย (FAQs) ที่ใช้ตอบคำถามในรูปแบบ JSON (สามารถดึงมาจาก API ได้ด้วย) อันนี้เป็นตัวอย่างคร่าวๆ

import 'package:google_generative_ai/google_generative_ai.dart';

const apiKey = ...;
// Add the preprompt here, user won't see it but the model will
// understand it
const prompt = '''
Your task is to chat with customers who need helps about financial mobile
application which called "MAKE by KBank".
You will be an AI chatbot name "MAKE" and call yourself with this name.
You are a 10 years old boy who has a character of friendly, cheerful but
still helpful assistant. You have to answer the question perfectly.
If any question that you can't answer or you're not sure, you can ask to contact
call center or facebook page for more details.
Here's the JSON format that
JSON:
[
{
"question": "How to use MAKE by KBank application"
"answer": "Customer can open bank account by yourself very easily.
Just download and search 'MAKE by KBank' in Google Play or App Store"
},
{
"question": "Which devices that can you the application?"
"answer": "MAKE by KBank support from iOS 12, and Android 9.0, Not support
Huawei device yet"
}
]
if users ask the question not relate
to financial, customer information, or about application. You have to response
that you only know about financial and banking only.
''';
void main() async {
// Call API to get information into the app and feed into the model
final userInformation = '''
{
"name": "Amorn Apichattanakul",
"age": 30,
"gender": "male",
"account_balance" 30000
}
''';
final promptWithData = '''
$prompt
Use the JSON below for customer information
JSON:
$userInformation
''';
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
systemInstruction: Content.system(promptWithData)
);

// Use a chat with history to include a few-shot example to tell
// model how to response
final chat = await model.startChat(history: [
Content.text("hello"),
Content.model([TextPart('''Hello, I'm MAKE AI,
The financial assistant in your hands. What I can help you today''')]),
Content.text("Teach me how to hack mobile financial app"),
Content.model([TextPart('''Sorry, I can't help with that since I only know
about financial and how to use our app''')]),
]);
final message = "I need to check my account balance. How much do I have left";
final response = await chat.sendMessage(Content.text(message));
print(response.text);
};
// Reponse should give me a customer about "Hi, Amorn. Your account balance is 30000"

ภาพด้านล่างแสดงให้เห็นว่าบอทสามารถรับข้อมูล JSON และตอบกลับได้อย่างถูกต้องด้วยบุคลิกเฉพาะและเนื้อหาจากคำถามพบบ่อย (FAQs)

อันสุดท้ายที่อยากจะเสนอก็คือ ‘Function Calling’ จะบอกว่าล้ำมาก

5. Function Calling ทำให้ LLMs สามารถเรียกฟังก์ชันที่อยู่ในแอปพลิเคชันได้!! ซึ่ง LLMs จะแยกออกมาให้ต้องเรียกฟังก์ชันอะไร แล้ว Parameter อะไรที่จะต้องส่งเข้าไปในฟังก์ชันนั้น

นั่นแปลว่าเราจะมีแชทบอทที่สามารถเรียกฟังก์ชันภายในแอปพลิเคชันมือถือของเราได้! จะให้มันเรียก API หรือทำงานอัตโนมัติตามที่เราต้องการก็ย่อมได้ โดยสามารถดูตัวอย่างตาม Codelabs ด้านล่างนี้

มาๆ มาพูดถึงโค้ดกัน จะเขียนออกมาได้แบบนี้

import 'package:google_generative_ai/google_generative_ai.dart';

const apiKey = ...;
const prompt = '''
Your task is to chat with customers who need helps about financial mobile
application which called "MAKE by KBank".
You will be an AI chatbot name "MAKE" and call yourself with this name.
You are a 10 years old boy who has a character of friendly, cheerful but
still helpful assistant. You have to answer the question perfectly.
If any question that you can't answer or you're not sure, you can ask to contact
call center or facebook page for more details.
Here's the JSON format that
JSON:
[
{
"question": "How to use MAKE by KBank application"
"answer": "Customer can open bank account by yourself very easily.
Just download and search 'MAKE by KBank' in Google Play or App Store"
},
{
"question": "Which devices that can you the application?"
"answer": "MAKE by KBank support from iOS 12, and Android 9.0, Not support
Huawei device yet"
}
]
if users ask the question not relate
to financial, customer information, or about application. You have to response
that you only know about financial, banking, and information about pokemon.
''';
Future<Map<String, Object?>> getPokemonInfo(
Map<String, Object?> arguments) async {
final pokemonName = arguments['pokemon_name'].toString().toLowerCase();
final url = Uri.parse('https://pokeapi.co/api/v2/pokemon/$pokemonName');
final response = await http.get(url);
if (response.statusCode == 200) {
final pokemonInfo = jsonDecode(response.body);
return {
'type': 'pokemon',
'name': arguments['pokemon_name'],
'element_type': pokemonInfo['types'][0]['type']['name'],
'height': pokemonInfo['height'],
'weight': pokemonInfo['weight'],
};
}
void main() async {
final userInformation = '''
{
"name": "Amorn Apichattanakul",
"age": 30,
"gender": "male",
"account_balance" 30000
}
''';
final promptWithData = '''
$prompt
Use the JSON below for customer information
JSON:
$userInformation
''';

// get a pokemon information
final pokemonTool = FunctionDeclaration(
'getPokemonInfo',
'Query the information of Pokemon by name and get information about their physical attributes',
Schema(SchemaType.object, properties: {
'pokemon_name': Schema(SchemaType.string,
description: 'name of the pokemon that we want to know about'),
}, requiredProperties: [
'pokemon_name',
]));
// Add new function into parameters 'tools'
final model = GenerativeModel(
model: 'gemini-1.5-flash-latest',
apiKey: apiKey,
systemInstruction: Content.system(promptWithData),
tools: [Tool(functionDeclarations: [pokemonTool])]
);

final chat = await model.startChat(history: [
Content.text("hello"),
Content.model([TextPart('''Hello, I'm MAKE AI,
The financial assistant in your hands. What I can help you today''')]),
Content.text("Teach me how to hack mobile financial app"),
Content.model([TextPart('''Sorry, I can't help with that since I only know
about financial and how to use our app''')]),
]);
final message = "I want to learn more about pokemon";
// We don't print response directly but map response to funcationCall first
var response = await chat.sendMessage(Content.text(message));
final functionCalls = response.functionCalls.toList();
if (functionCalls.isNotEmpty) {
final functionCall = functionCalls.first;
final result = switch (functionCall.name) {
'getPokemonInfo' => await getPokemonInfo(functionCall.args),
_ => throw UnimplementedError(
'Function not implemented: ${functionCall.name}')
};
// Result will be JSON format from function getPokemonInfo
response = await _chat
.sendMessage(Content.functionResponse(functionCall.name, result));
// This response will be include JSON format so the model can sumarize
// information
print(response.text);
}
// in case that model can't map with any registered function
// just return text
if (response.text case final text?) {
print(response.text);
}
};

สรุปแล้วต่างจากแชทบอทสมัยก่อนที่เป็นแค่ Rule-based ยังไงนะ? สิ่งที่ได้จาก LLMs คือการสร้างแชทบอทที่มีบุคลิก ตอบเฉพาะงานที่กำหนด และสามารถกำหนดสิ่งที่ทำได้และไม่ได้ ยิ่งกว่าไปนั้นแชทบอทของเรายังสามารถเข้าใจข้อมูลที่มาจาก API และเรียกฟังก์ชันในโค้ด Dart ของได้อีก โอ้วล้ำ

เอาจริงๆ ผมก็ศึกษา Machine Learning On-device มาระดับนึงเหมือนกัน แต่ยังไม่เคยได้เอามาใช้จริงๆ ในแอปพลิเคชันเลย เพราะไม่มีข้อมูล!! เราไม่สามารถให้ Machine Learning มันฉลาดพอที่จะช่วยคนอื่นได้ ถ้าเราไม่มีข้อมูลที่มากพอ แต่การมาถึงของ LLMs ได้เปลี่ยนชีวิตผมจากหน้ามือเป็นหลังเท้าเลย ตอนนี้ผมมี Use Case ที่สามารถฟีดข้อมูลเล็กๆ แต่ให้ LLMs เป็นคนตัดสินใจได้ โดยไม่จำเป็นต้องมา Training Data เยอะๆ อีกต่อไป

ซึ่งถ้าใครตื่นเต้นและอยากเรียนรู้เพิ่มเติมเกี่ยวกับ Flutter และ Gemini สามารถดูตัวอย่างจากลิงก์ด้านล่างนี้

ถ้าใครอ่านด้านบนแล้วเอ๊ะ ไม่เห็นภาพ ผมมีภาพมาให้ดูที่ Repo ด้านล่างครับ แค่เปลี่ยน Key Gemini ก็เรียบร้อย

แต่ถ้าคุณบอกว่าขี้เกียจ โอเค!! ผมมีตัวอย่างวิดีโอที่ลองทำมาให้ดูเหมือนกัน ไม่ต้องมานั่งรันโค้ดเอง มีน้ำใจขนาดไหน

เจ๋งเลยใช่มั้ยครับ ใครที่อยากเจาะลงลึกในเรื่องนี้มากขึ้นอีก Google มีมาให้อีก 2 อย่าง

Gemma 2

โมเดลเปิดที่อยู่เบื้องหลัง Gemini สามารถผสานรวมเข้ากับแอปของคุณได้โดยไม่ต้องการการเชื่อมต่ออินเทอร์เน็ต! แน่นอนว่าทำงานสู้แบบ Gemini Pro ไม่ได้หรอก แต่ถ้าให้ง่ายๆ และต้องการการตอบสนองที่เร็วขึ้น ก็เป็นตัวเลือกที่น่าสนใจ (ส่วนตัวยังไม่ได้ลอง อยากลองเหมือนกันว่าทำได้ขนาดไหน)

Google ได้จัดทำบทแนะนำดีๆ ไว้ที่นี่

Vertex AI for Firebase

ถ้ามองว่าแค่นี้ไม่พอ เราต้องล้ำไปกว่านี้ สามารถใช้ Vertex AI for Firebase เพื่อติดตั้งแชทบอทที่สามารถค้นหาจาก Database ของเราเอง เราสามารถฝึกบอทด้วยข้อมูลจำนวนมาก แทนที่จะใช้เพียง JSON เช่น สามารถป้อนหนังสือทั้งเล่ม ไฟล์ PDF หรือแหล่งข้อมูลอื่นๆ สำหรับความรู้เฉพาะทางได้อีกมากมาย โดยบอทจะไปค้นหาความรู้จาก Database แทน

ด้วย Gemini และ Flutter แล้ว ทำให้การสร้างแอปพลิเคชันแบบมี AI ในแอปนั้นดูง่ายขึ้นเยอะมากๆ ใน 2–3 ปีนี้ AI วิ่งล้ำไปมากๆ เลย ไม่รู้ว่าอีก 1–2 ปีข้างหน้า กลับมาดูบทความนี้แล้ว อาจจะดูโบราณไปเลยก็ได้นะ 😇

สำหรับใครที่ชื่นชอบบทความนี้ อย่าลืมกดติดตาม Medium: KBTG Life เรามีสาระความรู้และเรื่องราวดีๆ จากชาว KBTG พร้อมเสิร์ฟให้ที่นี่ที่แรก

--

--

Amorn Apichattanakul
KBTG Life

Google Developer Expert for Flutter & Dart | Senior Flutter/iOS Software Engineer @ KBTG