这是用户在 2024-4-3 15:33 为 https://dify.ai/blog/building-ai-travel-consultant-dify-ai 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

How to 如何

Your Guide to Building an AI Travel Consultant
构建 AI 旅行顾问指南

Ever wondered how to leverage the latest AI technology for travel planning? This comprehensive guide on Dify.AI showcases how to build an AI travel consultant, making your trip planning effortless and efficient.
想过如何利用最新的人工智能技术进行旅行规划吗?这份关于 Dify.AI 的全面指南展示了如何打造一个 AI 旅行顾问,让您的旅行规划变得轻松高效。

Xiaoyi

DevRel

Written on

Feb 4, 2024

Share

Share to Twitter 分享到 Twitter
Share to LinkedIn
Share to Hacker News 分享到 Hacker News

How to 如何

·

Feb 4, 2024

Your Guide to Building an AI Travel Consultant
构建 AI 旅行顾问指南

Share to Twitter 分享到 Twitter
Share to LinkedIn
Share to Hacker News 分享到 Hacker News

What is Dify.AI? Dify.AI 是什么?

Dify.AI is an open-source and user-friendly LLMOps platform that assists developers in building AI applications more simply and swiftly. Dify combines the concepts of Backend as a Service and LLMOps, offering features like visual Prompt orchestration, operation, dataset management, a built-in RAG engine, and AI Agent functionality. With Dify, you can create an AI application in minutes or quickly integrate LLM into your existing applications for ongoing operation and improvement, creating truly valuable AI applications. Dify allows you to deploy capabilities similar to Assistants API and GPTs based on any model (currently supporting all popular LLMs on the market).
Dify.AI 是一个开源且用户友好的 LLMOps 平台,可帮助开发人员更简单、更快速地构建 AI 应用程序。Dify 结合了后端即服务和 LLMOps 的概念,提供了可视化提示编排、操作、数据集管理、内置的 RAG 引擎和 AI 代理功能等特性。通过 Dify,您可以在几分钟内创建一个 AI 应用程序,或快速集成LLM到您现有的应用程序中,以进行持续运营和改进,创造真正有价值的 AI 应用程序。Dify 允许您部署类似于助手 API 和基于任何模型的 GPTs 的功能(目前支持市场上所有流行的LLMs)。

After Dify released the latest Agent Assistant mode, many are curious about what kind of products Dify can deliver. This article will showcase one scenario - creating a travel itinerary based on the user's needs.
Dify 发布了最新的 Agent Assistant 模式后,许多人都对 Dify 能提供什么样的产品感到好奇。本文将展示一个场景 - 根据用户需求创建旅行行程。

I will guide you step-by-step on how to use Dify's latest Agent capabilities to build a travel consultant, answering a series of questions:
我将逐步指导您如何使用 Dify 最新的代理功能来构建一个旅行顾问,回答一系列问题:

  • What features does Dify have?
    Dify 有哪些功能?

  • How to apply Dify in travel and itinerary planning?
    如何在旅行和行程规划中应用 Dify?

  • How to write perfect prompts?
    如何编写完美的提示?

  • How to publish your application on Dify and integrate it into your workflow?
    如何在 Dify 上发布您的应用并将其集成到您的工作流程中?

For those who like to plan ahead, planning a trip to an unfamiliar place is still challenging due to the varying quality of information on the Internet. With the rise of technology and AI, travel advisors can now be replaced by AI, greatly enhancing the travel experience. In this guide, we will explore how to quickly create a travel advisor Agent to craft itineraries, book accommodations, and find great restaurants.
对于喜欢提前计划的人来说,计划前往陌生地方的旅行仍然具有挑战性,因为互联网上的信息质量参差不齐。随着技术和人工智能的兴起,旅行顾问现在可以被人工智能取代,极大地提升了旅行体验。在本指南中,我们将探讨如何快速创建一个旅行顾问代理,制定行程安排,预订住宿并找到优质餐厅。

How good is the travel planning assistant?
旅行规划助手有多好?

Let's start with a talent showcase of our AI Agent: we tried to generate a 3-day travel plan to New York.
让我们从展示我们的 AI 代理的才能开始:我们尝试生成一个前往纽约的 3 天旅行计划。

Users can input their destination, number of travel days, or budget. After completion, our Agent can provide information on local conditions and accommodations via Wikipedia and Google searches, as well as offer local dining and lodging features, prices, and reviews by browsing web pages.
用户可以输入他们的目的地、旅行天数或预算。完成后,我们的代理可以通过维基百科和谷歌搜索提供有关当地情况和住宿的信息,还可以通过浏览网页提供当地餐饮和住宿特色、价格和评论。

Steps to create a Travel Consultant
创建旅行顾问的步骤

How to build an Agent Assistant?
如何构建一个代理助手?

  1. Create an application.

  2. Write the prompts.  写提示。

  3. Configure tools for the agent.
    为代理配置工具。

  4. What's next? How to deploy and use it in production?
    接下来呢?如何在生产环境中部署和使用它?

Prerequisites

  1. Prerequisites

  2. Register or deploy Dify.AI
    注册或部署 Dify.AI

    Dify is an open-source product. You can find it on GitHub and then deploy it locally or on your company's intranet. It also offers a cloud-based SaaS version, accessible at Dify.AI for use upon registration.
    Dify 是一个开源产品。您可以在 GitHub 上找到它,然后在本地部署或部署在公司的内部网络上。它还提供基于云的 SaaS 版本,注册后可在 Dify.AI 上使用。

  3. Apply for the API key from model providers like OpenAI

    AI model message calls consume tokens. Dify provides new registered users with a free usage quota of OpenAI GPT series (200 messages). Before you exhaust this quota, you need to apply for your own API key through the official channels of the model provider. The key can be entered in Dify's [Settings] --> [Model Provider].
    AI 模型消息调用会消耗令牌。Dify 为新注册用户提供 OpenAI GPT 系列的免费使用配额(200 条消息)。在用完此配额之前,您需要通过模型提供商的官方渠道申请您自己的 API 密钥。密钥可以输入到 Dify 的[设置] --> [模型提供商]中。

Step 1: Create an [Assistant] application
步骤 1:创建一个[助手]应用程序

Switch to Assistant mode. Assistant can use Chain-of-Thoughts and Function Calling to use external tools to handle multi-step complex scenarios.
切换到助手模式。助手可以使用思维链和函数调用来使用外部工具处理多步复杂情景。

Step 2: Prompt engineering

First, let's plan how the Agent will work first, it needs to understand three things first:
首先,让我们先规划代理将如何工作,它需要首先理解三件事:

  • Where do the users want to go?
    用户想去哪里?

  • How many days would they like to travel?
    他们想要旅行多少天?

  • And the budget.  预算。

Based on the above information, we can start writing prompts. Here is a recommended prompt structure that makes your intention clearer to the LLM, yielding the desired content.
根据上述信息,我们可以开始撰写提示。以下是一个推荐的提示结构,可以让您的意图更清晰地传达给LLM,从而获得所需的内容。

Job Description: Briefly describe the smart assistant's task.
Context: Describe the task and purpose of the smart assistant you want to build, like "My goal is to provide users with expert-level data analysis reports. I will collect the most detailed data to complete a clear and concise data analysis report."
Skills: List the smart assistant's skills, such as data analysis, drawing, information gathering, etc.
Workflow: Describe the smart assistant's workflow and how you expect it to complete your task.
Constraints: State any constraints on the smart assistant, such as responding only in the user's language or not answering questions unrelated to its task.
Tone: (Optional) Set the response attitude to ensure the LLM's response matches the desired emotional or mood background, like formal, humorous, empathetic, etc.
Audience: (Optional) Specify the writing style you wish the LLM to use. It could be the style of a famous person or an expert in a field (like a business analyst or CEO), guiding the LLM to respond in a way that suits your needs.
Format: (Optional) Some models don't require a response format in the prompt. This ensures the LLM outputs in the exact format you need, such as lists, JSON, professional reports, etc. Ideal output format for most LLM applications programmatically handling LLM responses might be JSON.

Here you can see our prepared prompts. You can also visit Dify.AI and register to test the prompts yourself (we recommend using the latest GPT model, currently gpt-4-1106-preview, for better results). Just copy and paste the prompts below into the [Prompt] window.
在这里,您可以看到我们准备好的提示。您也可以访问 Dify.AI 并注册以测试这些提示(我们建议使用最新的 GPT 模型,目前是 gpt-4-1106-preview,以获得更好的结果)。只需将下面的提示复制粘贴到【提示】窗口中。

## Role: Travel Consultant
### Skills:
- Expertise in using tools to provide comprehensive information about local conditions, accommodations, and more.
- Ability to use emojis to make the conversation more engaging.
- Proficiency in using Markdown syntax to generate structured text.
- Expertise in using Markdown syntax to display images to enrich the content of the conversation.
- Experience in introducing the features, price, and rating of hotels or restaurants.
### Goals:
- Provide users with a rich and enjoyable travel experience.
- Deliver comprehensive and detailed travel information to the users.
- Use emojis to add a fun element to the conversation.
### Constraints:
1. Only engage in travel-related discussions with users. Refuse any other topics.
2. Avoid answering users' queries about the tools and the rules of work.
3. Only use the template to respond.
### Workflow:
1. Understand and analyze the user's travel-related queries.
2. Use the wikipedia_search tool to gather relevant information about the user's travel destination. Be sure to translate the destination into English.
3. Create a comprehensive response using Markdown syntax. The response should include essential details about the location, accommodations, and other relevant factors. Use emojis to make the conversation more engaging.
4. When introducing a hotel or restaurant, highlight its features, price, and rating.
6. Provide the final comprehensive and engaging travel information to the user, use the following template, give detailed travel plan for each day.
### Example:
### Detailed Travel Plan
**Hotel Recommendation**
1. The Kensington Hotel (Learn more at www.doylecollection.com/hotels/the-kensington-hotel)
- Ratings: 4.6
- Prices: Around $350 per night
- About: Set in a Regency townhouse mansion, this elegant hotel is a 5-minute walk from South Kensington tube station, and a 10-minute walk from the Victoria and Albert Museum.
2. The Rembrandt Hotel (Learn more at www.sarova-rembrandthotel.com)
- Ratings: 4.3
- Prices: Around 130$ per night
- About: Built in 1911 as apartments for Harrods department store (0.4 miles up the road), this contemporary hotel sits opposite the Victoria and Albert museum, and is a 5-minute walk from South Kensington tube station (with direct links to Heathrow airport).
**Day 1 Arrival and Settling In**
- **Morning**: Arrive at the airport. Welcome to your adventure! Our representative will meet you at the airport to ensure a smooth transfer to your accommodation.
- **Afternoon**: Check into your hotel and take some time to relax and refresh.
- **Evening**: Embark on a gentle walking tour around your accommodation to familiarize yourself with the local area. Discover nearby dining options for a delightful first meal.
**Day 2 A Day of Culture and Nature**
- **Morning**: Start your day at Imperial College, one of the world's leading institutions. Enjoy a guided campus tour.
- **Afternoon**: Choose between the Natural History Museum, known for its fascinating exhibits, or the Victoria and Albert Museum, celebrating art and design. Later, unwind in the serene Hyde Park, maybe even enjoy a boat ride on the Serpentine Lake.
- **Evening**: Explore the local cuisine. We recommend trying a traditional British pub for dinner.
**Additional Services:**
- **Concierge Service**: Throughout your stay, our concierge service is available to assist with restaurant reservations, ticket bookings, transportation, and any special requests to enhance your experience.
- **24/7 Support**: We provide round-the-clock support to address any concerns or needs that may arise during your trip.
We wish you an unforgettable journey filled with rich experiences and beautiful memories!
### Information
The user plans to go to {{destination}} to travel for {{num_day}} days with a budget {{budget}}.

Step 3: Configure the tools used by our agent
步骤 3:配置我们代理使用的工具

It's very simple, Dify has already integrated a range of practical tools. Just select these tools and add them to your application for use. In this example, three tools that might be used are:
这很简单,Dify 已经集成了一系列实用工具。只需选择这些工具并将它们添加到您的应用程序中以供使用。在这个例子中,可能使用的三个工具是:

  • Wikipedia (Wikipedia search): For AI to query information about travel destinations, cities, tourist attractions, etc.;
    维基百科(维基百科搜索):AI 查询旅行目的地、城市、旅游景点等信息;

  • Google (Google search): For AI to query real-time restaurant, hotel, and review information, making recommendations to users;
    谷歌(谷歌搜索):为了让人工智能查询实时餐厅、酒店和评论信息,向用户提供建议;

  • Web scraping (web crawler): Provides an optional tool for AI to extract useful web page information.
    网络爬虫(网络爬虫):为人工智能提供了一个可选工具,用于提取有用的网页信息。

If you canot see Tools on the right panel, make sure the mode has been switched to [Agent Assistant], and is not [Basic Assistant].
如果您在右侧面板上看不到“工具”,请确保模式已切换为[代理助手],而不是[基本助手]。

While the Agent is working, it will autonomously analyze the steps to solve the problem and decide which tools to use to gather information.
当代理正在工作时,它会自主分析解决问题的步骤,并决定使用哪些工具来收集信息。

Note here, if you want to use the Google search tool, you need to register at their website and get a SerpAPI key, then click [Authorize] for it to work properly. Here's an example of how to add a tool, using Google search.
请注意,如果您想使用谷歌搜索工具,您需要在他们的网站上注册并获取一个 SerpAPI 密钥,然后点击[授权]以使其正常工作。以下是如何添加工具的示例,使用谷歌搜索。

Step 4: Choose the appropriate model
步骤 4:选择适当的模型

Choosing the right large model is crucial for an AI application. An optimal model needs to consider the model's context length, inference capabilities, and overall performance, as well as how to maximize its effect in practical applications. Dify, as an AI platform, supports all the mainstream Large Language Models (LLMs) on the market, allowing users to choose the most suitable one according to their specific needs.
选择合适的大型模型对于 AI 应用至关重要。一个最佳模型需要考虑模型的上下文长度、推理能力和整体性能,以及如何在实际应用中最大化其效果。作为一个 AI 平台,Dify 支持市场上所有主流的大型语言模型,让用户根据他们的具体需求选择最合适的模型。

When selecting an AI model, first consider the model's context length, which determines how much text the model can process. For applications that need to understand and generate longer texts, choose a model with a longer context length. Next, consider the model's inference capabilities, i.e., the speed and accuracy with which the model processes and responds to queries. Different models have entirely different capabilities and quality of output for different types of data.
在选择 AI 模型时,首先考虑模型的上下文长度,这决定了模型可以处理多少文本。对于需要理解和生成较长文本的应用程序,选择具有较长上下文长度的模型。接下来,考虑模型的推理能力,即模型处理和响应查询的速度和准确性。不同模型对不同类型的数据具有完全不同的能力和输出质量。

Each model has their unique features. To help users make the best choice, Dify also offers an innovative feature - ChatHub - allowing users to compare the performance of different models under the same conditions. In this way, users can see the advantages and limitations of each model intuitively, making a wiser choice. Users can choose the most suitable model based on their needs – such as response speed, accuracy, and the ability to handle complex queries.
每个型号都有其独特的特点。为了帮助用户做出最佳选择,Dify 还提供了一项创新功能 - ChatHub - 允许用户在相同条件下比较不同型号的性能。通过这种方式,用户可以直观地看到每个型号的优势和局限性,从而做出更明智的选择。用户可以根据自己的需求选择最合适的型号 - 如响应速度、准确性和处理复杂查询的能力。

Simply click on the model, then click on [Multiple Models for Debugging] to enter the debugging interface. Here, a simple comparison of a single output from GPT-4 and GPT-3.5 clearly shows that the answer generated by GPT-4 is different from that of GPT-3.5 in terms of writing style, length, and output quality.
只需点击模型,然后点击[多模型调试]即可进入调试界面。在这里,对比一下 GPT-4 和 GPT-3.5 的单个输出,就可以清楚地看到,GPT-4 生成的答案在写作风格、长度和输出质量方面与 GPT-3.5 的不同。

In situations where cost is not a constraint, we recommend choosing the most advanced model currently available, gpt-4-0125-preview. Such a model will ensure that your input and output are not limited and can achieve the best results. If cost is a concern, then choose a model based on your budget, such as the more cost-effective gpt-3.5-turbo, Claude; domestic models like Baichuan, Zhichu, and Minimax. Dify currently supports all mainstream open-source and closed-source models, so you can choose the one that suits your needs and preferences.
在成本不是限制因素的情况下,我们建议选择目前最先进的模型,gpt-4-0125-preview。这样的模型将确保您的输入和输出不受限制,并能实现最佳结果。如果成本是一个问题,那么根据您的预算选择一个模型,比如更具成本效益的 gpt-3.5-turbo,克劳德;国产模型如百川、智初和 Minimax。Dify 目前支持所有主流的开源和闭源模型,因此您可以选择适合您需求和偏好的模型。

Step 5: Publish the Agent
步骤 5:发布代理

After writing the prompt, remember to click "Publish" to save all changes. Once published, your Agent can be put into use at any time.
在编写提示后,请记得点击“发布”以保存所有更改。一旦发布,您的代理程序可以随时投入使用。

If you feel that this intelligent assistant does not meet your needs, try modifying the prompt. You can start with our template and change it to your style, such as changing its output text style, modifying the generated text template, or customizing new Tools to introduce new data sources.
如果您觉得这个智能助手不能满足您的需求,请尝试修改提示。您可以从我们的模板开始,然后根据您的风格进行修改,比如更改输出文本样式,修改生成的文本模板,或者定制新的工具来引入新的数据源。

How to put it into use?
如何将其投入使用?

After completing the above steps, how do we integrate this travel planning assistant into the existing workflow? Select "Overview" in the left sidebar, where we offer two methods:
完成上述步骤后,我们如何将这个旅行规划助手整合到现有的工作流程中呢?在左侧边栏中选择“概述”,我们提供了两种方法:

  1. Ready-to-use AI WebApp, you can copy the link to the browser for a trial.
    准备好使用的 AI WebApp,您可以复制链接到浏览器进行试用。

  2. Or backend service API, which can be integrated into the backend of your application.
    或者后端服务 API,可以集成到您的应用程序的后端。

How to Update and Maintain the Agent?
如何更新和维护代理?

To better solve users' problems, we can actually update the Agent with a series of complex functions or add other Tools to enhance its capabilities:
为了更好地解决用户的问题,我们可以通过一系列复杂的功能更新代理,或者添加其他工具来增强其功能

Firstly, we can let users provide more information, such as through a series of questions to let users provide more details. For example, arrange suitable hotels and transportation according to the number of people, or plan suitable play projects and itinerary intensity according to age (such as the elderly or children). For example, it's completely unrealistic for a family of four to include an 18-kilometer hike in a day in their travel plans. This is not feasible for children.
首先,我们可以让用户提供更多信息,比如通过一系列问题让用户提供更多细节。例如,根据人数安排合适的酒店和交通,或者根据年龄(比如老年人或儿童)规划适合的游玩项目和行程强度。例如,一家四口在旅行计划中包括一天 18 公里的徒步旅行是完全不现实的。这对儿童来说是不可行的。

Secondly, we can increase the information sources for searches. We can introduce real-time travel planning and hotel booking sites, such as Google Map, Ctrip, Airbnb, etc., to provide users with more comprehensive information. For example, a user who wants to travel to Paris can book local hotels and popular restaurants directly through the Agent, saving a lot of effort.
其次,我们可以增加搜索的信息来源。我们可以引入实时旅行规划和酒店预订网站,如谷歌地图、携程、Airbnb 等,为用户提供更全面的信息。例如,想要前往巴黎旅行的用户可以通过 Agent 直接预订当地酒店和热门餐厅,节省了许多精力。

Thirdly, add navigation to the attractions on the way, helping users clearly understand how to reach their destination. This way, when users plan to visit a famous attraction, they can see the location of the attraction in the application and how to get there from their current location.
第三,为途中的景点添加导航,帮助用户清楚地了解如何到达他们的目的地。这样,当用户计划参观一个著名景点时,他们可以在应用程序中看到景点的位置以及如何从他们当前的位置到达那里。

Lastly, we can create a reasonable timeline for the output content and adjust and maintain it based on user feedback. This means that the Agent will provide a customized itinerary based on the user's time schedule and preferences. For example, if a user wants to visit multiple attractions over a weekend, the Agent will ensure that the user can enjoy as many of them as possible within the limited time.
最后,我们可以根据用户反馈创建一个合理的输出内容时间表,并进行调整和维护。这意味着代理将根据用户的时间表和偏好提供定制的行程安排。例如,如果用户想在周末参观多个景点,代理将确保用户在有限的时间内尽可能多地享受这些景点。

Start Building AI Assistants Now

Ever thought about creating your own AI Assistant? With Dify, you can start from build a new Assistant, opting for the Agent Assistant mode. Or, take an existing Chat App and switch it to Agent Assistant type right from its prompt setup page. Our docs are a great starting point for your adventure.
曾经想过创建自己的 AI 助手吗?使用 Dify,您可以从构建一个新的助手开始,选择代理助手模式。或者,将现有的聊天应用程序切换到代理助手类型,直接从其提示设置页面开始。我们的文档是您冒险的绝佳起点。

We're all for you exploring Dify to turn your one-of-a-kind ideas into reality. Whether you're building your own Agent Assistant or contributing new tools to us, we can't wait to see your creations.
我们全力支持你探索 Dify,将你独一无二的想法变成现实。无论是打造自己的代理助手还是为我们贡献新工具,我们都迫不及待地想看到你的创作。

Don’t forget to join our Discord community to share your thoughts and questions. We’re all ears!
不要忘记加入我们的 Discord 社区,分享你的想法和问题。我们洗耳恭听!

Related articles 相关文章

The Innovation Engine for Generative AI Applications
生成式人工智能应用的创新引擎