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

PHPz
发布: 2024-08-09 16:22:09
转载
906人浏览过

找到完美的礼物可能具有挑战性,尤其是在考虑收件人的独特兴趣、场合和预算时。 个性化礼品助手应用程序可以让这个过程变得更轻松、更愉快。利用 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中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:dev.to网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号