欢迎光临
我们一直在努力

使用 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 频道

赞(0) 打赏
未经允许不得转载:码农资源网 » 使用 Lyzr SDK 构建个性化礼品助手
分享到

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册