介绍:众所周知大模型训练数据都是用的历史数据,无法实时查询天气信息,因此使用本地ollama大模型调实时天气api接口的方式,大模型识别和理解你要查询的请求,然后调第三方天气api接口返回实时天气。
python代码:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 20 13:43:03 2024
@author: xiaobai
"""
# 引入langchain_ollama中的ChatOllama
from langchain_ollama import ChatOllama
import os
import gradio as gr
import requests
# 配置大模型
model_tool = ChatOllama(model='llama3.2:3b', base_url='http://localhost:11434', format='json')
# 1. 获取北京天气的方法
def get_beijing_weather():
weather_api_url = 'https://api.seniverse.com/v3/weather/now.json'
params = {
'key': '替换成你自己的key',