Çözüm

Üretken yapay zeka ile acente destekli bir seyahat planlama uygulaması geliştirin

Aşağıdaki şemada, yapay zeka destekli uygulamalar oluşturmak için sınıfının en iyisi Google geliştirici hizmetlerini nasıl birleştirebileceğiniz hakkında genel bakış gösterilmektedir.

Mobil ve web için yapay zeka destekli güzel uygulamalar geliştirin

AI ile sorunsuz bir şekilde entegre edilebilen çoklu platform uygulamaları geliştirmek için Flutter ve Firebase Genkit'i kullanabilirsiniz.
LLM'nin çıkışını doğrulayabilecek bir şema tanımlayarak uygulamanızın, LLM'lerden gelen verileri güvenle tüketmesini sağlamak için Genkit'i kullanabilirsiniz. Flutter'da, isteği serileştirmek ve standart HTTP isteklerinden yararlanarak Genkit şemasıyla eşleştirmek üzere yanıtı seri durumdan çıkarmak için Dart'ı kullanabilirsiniz.
IDX ile herhangi bir yazılım yüklemenize gerek kalmadan Flutter uygulaması oluşturabilirsiniz. Bu şekilde Android uygulamanızı ve web uygulamanızı tarayıcıda geliştirip test edebilirsiniz.
Mobil uygulamalar ve web uygulamalarına yönelik bir ilişkisel veritabanı hizmeti olan Firebase Data Connect, Cloud SQL tarafından desteklenen ve tümüyle yönetilen bir PostgreSQL veritabanı kullanarak derleme ve ölçeklendirme yapmanıza olanak tanır. Firebase Authentication ile iyi entegre olan GraphQL kullanarak güvenli bir şema, sorgu ve mutasyon yönetimi sağlar. Data Connect, Kotlin Android ve web için SDK desteğini içerir.

Firebase Genkit ile aracı oluşturma

Aracı, kullanıcı girişini almak ve bir yanıt oluşturmak için AI düzenleme çerçevesini kullanır.
---
model: googleai/gemini-1.5-flash-latest
config:
  temperature: 1.0
  safetySettings:
    - category: HARM_CATEGORY_HATE_SPEECH
      threshold: BLOCK_LOW_AND_ABOVE
    - category: HARM_CATEGORY_DANGEROUS_CONTENT
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_HARASSMENT
      threshold: BLOCK_LOW_AND_ABOVE
    - category: HARM_CATEGORY_SEXUALLY_EXPLICIT
      threshold: BLOCK_LOW_AND_ABOVE
input:
  schema:
    request: string, The users request for where they want to travel to.
    place: string, The place that closely represents the users request.
    placeDescription: string, A description of that place.
    activities(array, a stringify list of activities that can be found at the specified place): string
    restaurants?(array, a stringify list of all the restaurants found at that location): string
output:
  schema:
    place: string, The place the user is traveling to.
    itineraryName: string, a catchy itinerary name that encapsulates the spirit of the trip and includes the place name
    startDate: string, the start date of the trip
    endDate: string, the end date of the trip
    tags(array, relevant tags for the trip): string
    itinerary(array):
      day: number
      date: string
      planForDay(array):
        activityRef: string, the reference value for the activity - this comes from the available activities JSON. If no value is present use a ref value of restaurant.
        activityTitle: string, a catchy title for the activity
        activityDesc: string, a six word description of the activity
        photoUri?: string, set the photo uri value for restaurants only.
        googleMapsUri?: string, if this is a restaurant include the googleMapsUri
---

Generate an itinerary for a tourist planning on traveling to the location specified based in their request.
If there is something that does not exist within the list of activities, do not include it in your answer.
Feel free to relate the activitiy to the request in a meaningful way.
In the plan for day array, put activities as a travel brouchure might do.
Come up with a catchy name for the itinerary.

Pick three activities per day, minimum of three day trip unless otherwise specified in the request.

Output schema should not include the properties type or object.

Pick a date after 2024-05-14 but before 2024-12-31.

The output date must be in the format year-month-day.

Give each activity a unique title and description.

Limit activity descriptions to 6 words.

If no restaurants are supplied, do not recommend any restaurants to eat at.

{{#if restaurants}}
Find a restaurant to eat at each day.

Include a restaurant to visit in the itinerary for each day from the available restaurants.
The restaurant should be the only activity with a photoUri.
The photoUri for the restaurant should be from the photoUri property from the restaurant array.
If there are no restaurants to pick from, do not include it in the list.

The photoUri from the restaurantFinder should be in the format of places/${placeId}/photos/${photoId}

Each restaurant should be unique to the overall itinerary.
Each restaurant must contain a photoUri in their output JSON schema.
Each restaurant must also include  an activitiyRef, activityTitle, and activityDesc in their output
{{/if}}
Output must be in JSON format.

REQUEST : {{request}}
PLACE : {{place}}
PLACE DESCRIPTION : {{placeDescription}}
AVAILABLE ACTIVITIES : {{activities}}
RESTAURANTS : {{restaurants}}
Üretken yapay zeka ile çalışırken modelin yüksek kaliteli yanıtlar vermesi için etkili istemler oluşturmak önemlidir. Firebase Genkit, üretken yapay zeka istemlerinizi yazmanıza ve düzenlemenize yardımcı olmak için Dotprompt eklentisini ve metin biçimini sağlar. Biçim; istemi, giriş ve çıkış şemasını, modeli ve yapılandırmayı tek bir dosyada içerir.

Aşağıdaki kod örneğinde, seyahat uygulamasında kullanılan bir Dotprompt dosyası gösterilmektedir. Şema, kullanıcının hayalini kurduğu seyahati tarif ederken sağladığı bilgilere dayanır.
Dotprompt, istemlerin kod olduğu prensibiyle tasarlanmıştır. İstemlerinizi noktaprompt dosyası adı verilen özel biçimlendirilmiş dosyalarda yazıp tutar, kodunuz için kullandığınız sürüm kontrol sistemini kullanarak bu dosyalardaki değişiklikleri takip eder ve bunları, üretken yapay zeka modellerinizi çağıran kodla birlikte dağıtırsınız.
Akışlar; güçlü bir şekilde yazılmış, akışa uygun, yerel ve uzaktan çağrılabilir ve tamamen gözlemlenebilir işlevlerdir. Firebase Genkit, akışlarla (ör. çalıştırma veya hata ayıklama akışları) çalışmak için komut satırı arayüzü ve geliştirici kullanıcı arayüzü sunar.
import {defineTool} from '@genkit-ai/ai/tool';
...
{
  name: 'restaurantFinder',
  description: `Used when needing to find a restaurant based on a users location.
  The location should be used to find nearby restaurants to a place. You can also
  selectively find restaurants based on the users preferences, but you should default
  to 'Local' if there are no indications of restaurant types in the users request.
  `,
  inputSchema: z.object({
    place: z.string(),
    typeOfRestaurant: z.string().optional() }),
    outputSchema: z.unknown(),
},
...
async (input) => {
  if (input.typeOfRestaurant == undefined) {
    input.typeOfRestaurant = "Local";
  }
  const geocodeEndpoint = "https://places.googleapis.com/v1/places:searchText";
  const textQuery = {textQuery: `${input.typeOfRestaurant} restaurants in ${input.place}`};

  const  response = await axios.post(
    geocodeEndpoint,
    JSON.stringify(textQuery),
    {
      headers: {
        "Content-Type": "application/json",
        "X-Goog-Api-Key": MAPS_API_KEY,
        "X-Goog-FieldMask": "places.displayName,places.formattedAddress,places.priceLevel,places.photos.name,places.editorialSummary,places.googleMapsUri"
      }
    }
  );
  console.log(response.data);
  let data = (response.data as PlaceResponse);
  for(let i = 0; i < data.places.length; i++) {
    if (data.places[i].photos) {
      data.places[i].photos = [data.places[i].photos[0]];
    }
  }
  return data as PlaceResponse;
}
Aracının yanıtları daha hassas hale getirebilmesi ve ek görevleri tamamlayabilmesi için Genkit'te işlev çağrısını kullanarak temsilcinin işlevini artırabilirsiniz. Seyahat uygulaması, kullanıcının istediği seyahate göre Places API'den restoran bilgilerini döndürebilen bir araç tanımlar. Kod, sorgu sonuçlarının doğrulanabilmesi için giriş ve çıkış şemasını tanımlamak üzere Zod'u kullanır.
...
export const textRefinement = defineFlow(
{
  name: 'textRefinement',
  inputSchema: z.string(),
  outputSchema: z.unknown(),
},
async (userRequest) => {
  const refinementPrompt = await prompt('textRefinement')
  const result = await refinementPrompt.generate({
      input: {
          request: userRequest
      },
  });
  return result.output();
});
Gemini, kullanıcılara daha özel bir arama deneyimi sunmak için hayalini kurduğu seyahati tarif ettikten sonra seyahat uygulamasının sağladığı istemlere dayanarak daha fazla bilgi gerekip gerekmediğini belirler ve daha fazla bilgi gerektiğini düşünürse uygulamaya sinyal gönderir. Daha sonra uygulama, kullanıcıdan bu bilgileri ister ve arka uçtaki isteğe ekler.
import 'package:http:http.dart' as http;
...
Future<List<Trip>> generateTrips(String description, List<Image> images) async {
  final uri = Uri.parse('.../generateTrips');
  final request = http.MultipartRequest('POST', uri);
  request.fields['description'] = description;
  request.files.add(http.MultipartFile.fromData(
      images.name, images.bytes,
      contentType: MediaType('image', 'png'),
  ));
  var response = await request.send();
  if (response.statusCode == 200) {
      final body = await response.body.text();
      final items = jsonDecode(body) as List<dynamic>;
      return items.map(Trip.fromJson).toList();
  }
  ...
  import { imagen2, geminiProVision } from '@genkit-ai/vertexai';
  import { generate } from '@genkit-ai/ai';

  const imageResult = await generate({
    model: imagen2,
    prompt: 'Generate an image of a very specific historical time and place.',
  });
  const generatedImage = imageResult.media();

  const descriptionResult = await generate({
    model: geminiProVision,
    prompt: [
      {
        text: 'What is the historical time and place represented in this picture?',
      },
      { media: generatedImage },
    ],
  });
  console.log(descriptionResult.text());
  }
Seyahat uygulaması, kullanıcıdan metin girişi kullanarak veya sesle yazma özelliğini etkinleştirmek için mikrofon düğmesine dokunarak hayallerindeki seyahati tanımlamasını istiyor. Kullanıcı isterse resim de yükleyebilir.

Uygulama, her platformda yerel sesle yazma özellikleriyle entegrasyon sağlamak için pub.dev'deki Dart paketi'nden yararlanıyor. Ayrıca, resim veya video gibi çok modlu girişleri yönetmek için Firebase Genkit'in içindeki Gemini API'yi kullanıyor. Gemini API, Firebase Data Connect'i ve yerleştirmeleri kullanarak en yakın komşu araması yapmak için önerilen gezileri ve bilgileri döndürmek amacıyla Retrieval-Artırılmış Oluşturma (RAG) teknolojisini kullanır.

Uygulamanızı üretim için ölçeklendirme

Firebase Hosting, Flutter gibi popüler modern web çerçeveleriyle entegre olur. Bu çerçevelerle Firebase Hosting ve Cloud Functions for Firebase'i kullanarak tercih ettiğiniz çerçeve ortamında uygulama ve mikro hizmetler geliştirebilir, ardından bunları yönetilen ve güvenli bir sunucu ortamında dağıtabilirsiniz. Üretime geçmeden önce uygulamanızdaki tüm hizmetlerin güvenliği ve performansı hakkında bilgi edinin. Daha fazla bilgi için Firebase lansman kontrol listesine bakın.
Test verilerini hızlı bir şekilde yinelemek için Google Yapay Zeka'dan yararlanan seyahat uygulaması, ölçeklenmesi gerekmeyen yapay zeka kullanım alanının minimum düzeyde olduğu uygulamalar için iyi bir seçenektir. Vertex AI, üretim uygulamalarını ölçeklendirmeye yardımcı olacak daha yüksek kotaya ve kullanıcı verilerini korumak için daha güçlü gizlilik politikalarına sahiptir. Genkit, modeller arasında kolayca geçiş yapmanızı sağlayan yerleşik bir işleve sahiptir. Böylece istemlerinizi veya API çağrılarınızı yeniden yazmanız gerekmez.