当前位置: 首页 > wzjs >正文

西安做网站的公司客服常见的营销型网站

西安做网站的公司客服,常见的营销型网站,网站建设企业资质,洛阳网站建设哪家权威目录 1️⃣ 选择框架2️⃣开发操作导入Python库创建功能函数装载环境变量创建Agent运行Agent 学习参考资料: 微软 AI Agents for Beginners 代码仓库 1️⃣ 选择框架 semantic-kernel开发框架 导入库创建功能函数(Agent 要完成什么功能)…

目录

  • 1️⃣ 选择框架
  • 2️⃣开发操作
    • 导入Python库
    • 创建功能函数
    • 装载环境变量
    • 创建Agent
    • 运行Agent


学习参考资料:

  • 微软 AI Agents for Beginners
    • 代码仓库

1️⃣ 选择框架

semantic-kernel开发框架

  1. 导入库
  2. 创建功能函数(Agent 要完成什么功能)
  3. 创建客户端
    1. 加载环境变量(保存在.env,保证API_Key安全性)
    2. 配置基地址(URL
    3. 选择基座模型
  4. 创建Agent
    1. 将客户端配置到 service
    2. Agent 名称
  5. 运行Agent

可能头疼地方的解决方案:

  • 模型API付费:
    • 创建 Github Token
    • 基地址:https://models.inference.ai.azure.com/

2️⃣开发操作

导入Python库

import os 
from typing import Annotated
from openai import AsyncOpenAIfrom dotenv import load_dotenvfrom semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.functions import kernel_function

创建功能函数

import random   # Define a sample plugin for the sampleclass DestinationsPlugin:"""A List of Random Destinations for a vacation."""def __init__(self):# List of vacation destinationsself.destinations = ["Barcelona, Spain","Paris, France","Berlin, Germany","Tokyo, Japan","Sydney, Australia","New York, USA","Cairo, Egypt","Cape Town, South Africa","Rio de Janeiro, Brazil","Bali, Indonesia"]# Track last destination to avoid repeatsself.last_destination = None@kernel_function(description="Provides a random vacation destination.")def get_random_destination(self) -> Annotated[str, "Returns a random vacation destination."]:# Get available destinations (excluding last one if possible)available_destinations = self.destinations.copy()if self.last_destination and len(available_destinations) > 1:available_destinations.remove(self.last_destination)# Select a random destinationdestination = random.choice(available_destinations)# Update the last destinationself.last_destination = destinationreturn destination

装载环境变量

load_dotenv()
client = AsyncOpenAI(api_key=os.environ.get("GITHUB_TOKEN"), base_url="https://models.inference.ai.azure.com/",
)# Create an AI Service that will be used by the `ChatCompletionAgent`
chat_completion_service = OpenAIChatCompletion(# 模型可自行选择ai_model_id="gpt-4o-mini",async_client=client,
)

创建Agent

agent = ChatCompletionAgent(service=chat_completion_service, plugins=[DestinationsPlugin()],name="TravelAgent",instructions="You are a helpful AI Agent that can help plan vacations for customers at random destinations",
)

运行Agent

async def main():# Create a new thread for the agent# If no thread is provided, a new thread will be# created and returned with the initial responsethread: ChatHistoryAgentThread | None = Noneuser_inputs = ["Plan me a day trip.",]for user_input in user_inputs:print(f"# User: {user_input}\n")first_chunk = Trueasync for response in agent.invoke_stream(messages=user_input, thread=thread,):# 5. Print the responseif first_chunk:print(f"# {response.name}: ", end="", flush=True)first_chunk = Falseprint(f"{response}", end="", flush=True)thread = response.threadprint()# Clean up the threadawait thread.delete() if thread else Noneawait main()

在这里插入图片描述

http://www.dtcms.com/wzjs/398241.html

相关文章:

  • 用什么做网站方便关于进一步优化当前疫情防控措施
  • 博客网站建设下载app
  • 更换网站后台管理系统百度快速排名工具
  • qq在线网站代码手机怎么建自己的网站
  • 帮人家做家务的网站自助网站建设平台
  • 如何制作一个个人网站品牌软文范文
  • 访问WordPress速度seo建站系统
  • 北京加盟网站建设2020 惠州seo服务
  • 昆明网站制作公司哪家靠谱百度广告联盟平台
  • 网站开发与移动互联百度游戏中心app
  • python基础教程for循环搜索引擎优化是指什么
  • 山东 网站建设东莞市网站seo内容优化
  • 做网站开发要学多久河南推广网站的公司
  • 怎么知道网站的空间是谁做的手机搭建网站
  • 运动鞋网站建设目的百度上首页
  • 建立网站的条件百度一级代理商
  • 织梦手机网站模板删除产品营销策划方案3000字
  • 深圳建网站的网络公司软文写作技巧有哪些
  • 上海做网站优化的公司广州网站优化服务
  • 如何用工控做网站网站搭建关键词排名
  • 淘宝客网站做app企业营销战略
  • 大连做网站优化公司市场推广专员
  • 南同网站建设青岛网站推广企业
  • 长春 网站 设计博客网
  • 做网站鞍山免费国外ddos网站
  • 做外贸最好的网站建设洛阳网站seo
  • 某旅行社网站建设规划书seo推广知识
  • 天津 网站建设百度游戏客服在线咨询
  • 上海微信网站建设怎么去做推广
  • 1个ip可以做几个网站吗关键词工具