推广 热搜: page  数据  小红  红书  考试  论文  数据分析  关键词  哪些  搜索 

azureopenai langchain的实践, Azure OpenAl 入门教程

   日期:2025-01-01     移动:https://sicmodule.kub2b.com/mobile/quote/17362.html

参考链接:https://azureopenai.cloudallonline.com/?zxwwy187
企业微软 Azure OpenAI 试用申请

langchain中有两个核心概念:agent和tool。

我来用一个故事来解释agent和tool的关系。

假设你是一个小学生,你要做一份关于太阳系的作业。你有一台电脑,上面有很多软件,比如浏览器,文档编辑器,画图软件等等。这些软件就相当于langchain里的tools,它们可以帮你完成一些具体的任务,比如搜索信息,写文字,画图片等等。

但是你不知道怎么用这些软件来做作业,你需要有一个指导者,一个老师,来告诉你该怎么做。这个老师就相当于langchain里的agent,它是一个语言模型,可以根据你的输入,给你一些建议和反馈。它也可以根据不同的情况,选择合适的软件(tools)来帮你完成作业。

比如,你问老师:“太阳系有几颗行星?”老师就会告诉你:“太阳系有八颗行星。”然后老师会选择浏览器这个软件(tool),搜索一些关于太阳系的网站,并把结果显示给你。你再问老师:“我该怎么写作业?”老师就会告诉你:“你可以先打开文档编辑器这个软件(tool),然后写一个标题,比如‘太阳系简介’。”然后老师会打开文档编辑器,并帮你写好标题。你再问老师:“我该怎么画太阳系的图片?”老师就会告诉你:“你可以先打开画图软件这个软件(tool),然后用圆形工具画出太阳和行星。”然后老师会打开画图软件,并帮你画出太阳和行星。

这样,通过agent和tools的配合,你就可以完成你的作业了。这就是agent和tool的关系。

企业如何合规、稳定使用ChatGPT以及Copilot?

出于合规角度,建议国内企业可以选择微软的Azure OpenAI服务来使用接口。

通过微软官方合作伙伴获取服务,企业用户可以合规、稳定地使用ChatGPT,满足国内发票需求,同时也能解决连接不稳定/响应速度慢/并发配额低等问题。

作为微软的合作伙伴,全云在线可为企业开通绿色申请通道!包括最新版本GPT-4o、Dalle-3等,只要企业有需求,全云在线都能协助快速开通!

参考链接:https://azureopenai.cloudallonline.com/?zxwwy187
企业微软 Azure OpenAI 试用申请

我们查看langchain的repo:

https://github.com/hwchase17/langchain

我们可以看到Langchain可以对接的LLM不止一个,agents和tools同样有很多个:

接下来我们验证Langchain与Azure OpenAI对接,实现基于一个/多个CSV构建QA机器人的效果。在下面的实验中,我们用到的agent是create_csv_agent。

Imimport necessary libraries # 导入需要的库import openai# 导入openai库,用于调用openai的apiimport pandas as pd# 导入pandas库,用于处理数据表格from langchain.agents import create_csv_agent# 从langchain.agents模块导入create_csv_agent函数,用于创建一个可以处理csv文件的agentfrom langchain.llms import AzureOpenAI# 从langchain.llms模块导入AzureOpenAI类,用于创建一个使用AzureOpenAI的语言模型port necessary libraries # 导入需要的库import openai# 导入openai库,用于调用openai的apiimport pandas as pd# 导入pandas库,用于处理数据表格from langchain.agents import create_csv_agent# 从langchain.agents模块导入create_csv_agent函数,用于创建一个可以处理csv文件的agentfrom langchain.llms import AzureOpenAI# 从langchain.llms模块导入AzureOpenAI类,用于创建一个使用AzureOpenAI的语言模型

# Load the csv file as Pandas dataframe.1df = pd.read_csv('https://www.163.com/dy/article/data/Sales_Performance_Report_DQLab_Store.csv')

# Display the dataframe information.df.info()

将csv文件加载为Pandas数据框架并进行展示:

# Configure the baseline configuration of the OpenAI library for Azure OpenAI Service.OPENAI_API_KEY = "xxx"OPENAI_DEPLOYMENT_NAME = "text-davinci-003"MODEL_NAME = "text-davinci-003"openai.api_type = "azure"openai.api_base = "https:/xxx/"openai.api_version = "2022-12-01"openai.api_key = " xxx"

# 通过LangChain从Azure OpenAI服务启动对LLM的连接。

# Initiate a connection to the LLM from Azure OpenAI Service via LangChain.llm = AzureOpenAI( openai_api_key="cdxxx", deployment_name="text-davinci-003", model_name="text-davinci-003", openai_api_version="2022-12-01")

# 做一个简单的提示,从Azure OpenAI服务中验证与LLM的连接。

# Make a simple prompt to validate the connection with LLM from Azure OpenAI Service.print(llm("What is the Azure OpenAI Service?"))

# 用Azure OpenAI服务的LLM启动LangChain的CSV代理,与CSV文件进行交互。

# Initiate a LangChain's CSV Agent with the LLM from Azure OpenAI Service to interact with the CSV file.agent = create_csv_agent(AzureOpenAI(openai_api_key="xxx", deployment_name="text-davinci-003", model_name="text-davinci-003", openai_api_version="2022-12-01"), 'https://www.163.com/dy/article/data/Sales_Performance_Report_DQLab_Store.csv', verbose=True)

# 显示CSV agent的默认prompt template

# Display the CSV Agent's default prompt template.agent.agent.llm_chain.prompt.template' You are working with a pandas dataframe in Python. The name of

agent.run("How many rows of data do you have?")

agent.run("Please list the years in this dataset.")

agent.run("Please tell me the total sales in 2011. Please tell me the total sales in 2012. And calculate the percentage of the increase from 2011 to 2012.")

agent.run("What is the customer's name with the highest total amount of purchases in 2012? And tell me the total amount of purchases.")

agent.run("What was the top sale product category in 2012?")

接下来,我们看同时对接两个csv的效果:

# Need LangChain 0.0.181 or above. https://python.langchain.com/en/latest/modules/agents/toolkits/examples/csv.html?highlight=csv#multi-csv-exampleagent = create_csv_agent(AzureOpenAI(openai_api_key="xxx", openai_api_version="2022-12-01",deployment_name="text-davinci-003", model_name="text-davinci-003"), ['https://www.163.com/dy/article/data/cnbc_news_database_r1_2012.csv', 'https://www.163.com/dy/article/data/nasdaq_index_2012.csv'], verbose=True)

# 显示CSV代理的默认 prompt template.

# Display the CSV Agent's default prompt template.agent.agent.llm_chain.prompt.template

agent.run("How many rows of data do you have?")

agent.run("What is average nasdaq index in 2012?")

agent.run("What is average nasdaq index in H1 2012? Please show me the monthly figure with growth or drop rate.")

agent.run("Since nasdaq index is growthing in H1 2012, do you think is there any news related to this growth? If yes, please tell me what is the news?")

agent.run("Please help to check my hypothesis that the drop of nasdaq index in 2012 is related to the negative sentiment of the news?")

agent.run("Please help to check my hypothesis that growth of the nasdaq index in 2012 is related to the positive sentiment of the news?")

'The growth of the nasdaq index in 2012 is related to the positive sentiment of the news, with a mean nasdaq change of 2.409912 for sentiment score of 1 compared to 5.244208 for sentiment score of 0.'


agent.run("In 2012, nasdaq index is growthing or dropping?")

本文地址:https://sicmodule.kub2b.com/quote/17362.html     企库往 https://sicmodule.kub2b.com/ , 查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


0相关评论
相关最新动态
推荐最新动态
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号