一、大型语言模型的概述
1.1 LLMs的定义与发展
1.2 传统LLMs的局限性
二、Function Calling与LangChain的概念与机制
2.1 什么是Function Calling?

2.2 什么是LangChain?
2.3 Function Calling与LangChain的结合
三、Function Calling+LangChain的技术架构
3.1 技术架构概览

技术架构包括以下几个核心组件:
-
用户接口层:通过自然语言输入需求(prompt),用户与业务系统(应用)交互。
-
解析与路由层:利用Function Calling解析用户请求,并确定所需的外部功能。
-
功能调用层:通过LangChain框架管理和执行具体的功能调用。
-
数据处理层:处理和分析从外部系统获取的数据。
-
结果反馈层:将处理后的结果反馈给用户。
3.2 解析与路由
3.3 功能调用与数据处理
3.4 结果展示与交互
3.5代码示例
import openaiimport osimport tiktoken# 加载 .env 文件from dotenv import load_dotenv, find_dotenvfrom langchain.prompts import PromptTemplatefrom langchain.llms import OpenAIfrom langchain.chains import LLMChainfrom langchain.chains import LLMRequestsChain#from langchain.chat_models import AzureChatOpenAIfrom langchain.chat_models import ChatOpenAI #直接访问OpenAI的GPT服务_ = load_dotenv(find_dotenv())# 从环境变量中获得你的 OpenAI Key和配置URLopenai.api_key = os.getenv('OPENAI_API_KEY')openai.api_base = os.getenv('OPENAI_API_URL')model = os.getenv('OPENAI_API_MODEL')llm = ChatOpenAI(model_name=model, temperature=0) #直接访问OpenAI的GPT服务#llm = AzureChatOpenAI( model_name=model, temperature=0, max_tokens=200) # 通过Azure的OpenAI服务#根据查询的结果结果返回给大模型,大模型再组装后进行返回def query_baidu(question):template = """Between >>> and <<< are the raw search result text from web.Extract the answer to the question '{query}' or say "not found" if the information is not contained.Use the formatExtracted:<answer or "not found">>>> {requests_result} <<<Extracted:"""PROMPT = PromptTemplate(input_variables=["query", "requests_result"],template=template,)inputs = {"query": question,"url": "http://www.baidu.com/s?wd=" + question.replace(" ", "+")}requests_chain = LLMRequestsChain(llm_chain = LLMChain(llm=llm, prompt=PROMPT), output_key="query_info", verbose=True)res = requests_chain.run(inputs)return res#python 程序入口if __name__ == "__main__":print(query_baidu("今天长沙的天气?"))


