使用 Lyzr SDK 构建个性化礼品助手

当前位置: 电视猫 > php教程>
电视猫时间: 2023-11-30 15:00:00

  使用 Lyzr SDK 构建个性化礼品助手

找到完美的礼物可能具有挑战性,尤其是在考虑收件人的独特兴趣、场合和预算时。 个性化礼品助手应用程序可以让这个过程变得更轻松、更愉快。利用 lyzr automata 和 openai 的 gpt-4 turbo 的强大功能,此应用程序可帮助您策划个性化的礼物推荐,一定会让任何收件人感到高兴。

使用 Lyzr SDK 构建个性化礼品助手

设置环境

首先,让我们导入必要的库并设置我们的环境。

import streamlit as st
from lyzr_automata.ai_models.openai import openaimodel
from lyzr_automata import agent, task
from lyzr_automata.pipelines.linear_sync_pipeline import linearsyncpipeline
from pil import image
from lyzr_automata.tasks.task_literals import inputtype, outputtype
import os
登录后复制

设置 openai api 密钥

我们需要设置 openai api 密钥来访问 gpt-4 turbo 模型。

os.environ["openai_api_key"] = st.secrets["apikey"]
登录后复制

应用程序标题和简介

我们设置了应用程序的标题并提供了简短的介绍来指导用户如何使用个性化礼品助手。

st.title("personalized gift assistant")
st.markdown("welcome to personalized gift assistant! let us help you find the perfect gift for any occasion, tailored to your recipient's unique interests and your budget.")
st.markdown("1) mention your receiver's age.")
st.markdown("2) mention your receiver's interest.")
st.markdown("3) mention the occasion.")
st.markdown("4) mention your budget.")
input = st.text_input("please enter the above details:", placeholder="type here")
登录后复制

设置 openai 模型

我们用特定参数初始化openai模型,根据用户输入生成个性化礼物推荐

open_ai_text_completion_model = openaimodel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
登录后复制

定义生成函数

此功能使用 lyzr automata sdk 创建一个代理,根据用户的输入提供个性化礼物推荐。

def generation(input):
    generator_agent = agent(
        role="expert gift consultant",
        prompt_persona="your task is to curate a personalized list of 5-7 gifts for the user and provide explanations for each choice, taking into account the receiver's age, receiver's interests, the occasion, and the budget.")
    prompt = """
[prompts here]
"""
    generator_agent_task = task(
        name="generation",
        model=open_ai_text_completion_model,
        agent=generator_agent,
        instructions=prompt,
        default_input=input,
        output_type=outputtype.text,
        input_type=inputtype.text,
    ).execute()
    return generator_agent_task
登录后复制

生成礼物推荐的按钮

我们添加了一个按钮,点击后会触发生成个性化礼物推荐。

if st.button("Assist!"):
    solution = generation(input)
    st.markdown(solution)
登录后复制

个性化礼品助手旨在帮助您找到适合任何场合的完美礼物。通过利用 lyzr automata 和 openai 的 gpt-4 turbo 的强大功能,您可以获得根据收件人的年龄、兴趣、场合和预算量身定制的专家建议。立即探索个性化礼品助手,让送礼成为一种愉快的体验!

应用链接:https://giftassistant-lyzr.streamlit.app/

源代码:https://github.com/isakshay007/gift_assistant

如有任何疑问或支持,请随时联系

lyzr。您可以通过以下链接了解有关 lyzr 及其产品的更多信息:

网站:lyzr.ai
预订演示:预订演示
discord:加入我们的 discord 社区
slack:加入我们的 slack 频道

以上就是使用 Lyzr SDK 构建个性化礼品助手的详细内容,更多请关注php中文网其它相关文章!

最新电视剧
热门电视剧
影视资讯
最新剧情排行榜
最新电视剧剧情