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

徐州东站个人网站备案

徐州东站,个人网站备案,seo外包模板,中国开源网目录 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/96094.html

相关文章:

  • fullpage网站怎么做百度首页登录
  • 网站截流做cpa品牌营销案例分析
  • 各大网站投稿东莞做网站推广公司
  • 建网站郑州长沙推广公司
  • 厦门建网站互联网平台推广
  • 江阴网站制作文件外链网站
  • 西部数码网站站点大连网站建设
  • 阿里巴巴如何建设网站首页东莞网站建设优化推广
  • 中山建设招聘信息网站seo关键词排行优化教程
  • 公众号平台客服电话seo每天一贴
  • 济南防疫最新动态免费seo软件
  • 济南做网站创意环球网今日疫情消息
  • 政府网站开发要求百度免费打开
  • 网站源码对应的数据库怎么做百度推广seo效果怎么样
  • android studio的应用百度seoo优化软件
  • 西安做网站收费价格今日中央新闻
  • 如何给网站做右侧导航朝阳网站建设
  • 济南网站建设seo优化上海网络推广公司网站
  • 福建中海建设有限公司网站国内重大新闻
  • 建设工程安全备案网站昆明百度推广优化
  • 广州网站关键词优化推广seo关键词优化培训
  • 国外网站大牛不懂英语可以做吗宁波seo排名优化价格
  • 文明网站建设情况百度一下百度一下你就知道
  • jsp网站开发实例互联网营销师培训机构哪家好
  • 专业做淘宝网站公司网络营销论文3000字
  • 做网站模板 优帮云seo公司费用
  • 柳河县做网站网站关键词快速排名工具
  • 有关建筑企业的网站有哪些全网营销公司
  • 可以做直播卖产品的网站如何百度收录自己的网站
  • 网站页面模板页面布局成都网络优化托管公司