大模型-Tool call、检索增强RAG

大模型

Tool call

心知天气:https://www.seniverse.com/

例子:调用天气接口 API

from openai import OpenAI
import requests
import json
"""
##### 天气接口 API 密钥获取:https://www.free-api.com/doc/558 #####
"""

# 定义调用天气 API 的函数
def get_weather(location, language="zh-Hans", unit="c"):
    url = "https://api.seniverse.com/v3/weather/now.json"
    params = {
   
        "key": "123",  # 替换为心知天气 Seniverse API Key
        "location": location,
        "language": language,
        "unit": unit,
    }
    response = requests.get(url, params=params)
    return response.json()


# # 初始化 OpenAI 客户端
# client = OpenAI(
#     api_key="",  # 替换为你的 OpenAI API Key
#     base_url="https://api.deepseek.com",  # DeepSeek 的 API 地址
# )

client = OpenAI(
    api_key="123", # 在这里将 MOONSHOT_API_KEY 替换为你从 Kimi 开放平台申请的 API Key
    base_url="https://api.moonshot.cn/v1",
)
model="moonshot-v1-8k"

# 发送消息并处理工具调用
def send_messages_with_tools(messages):
    response = client.chat.completions.create(
        model=model,  # 使用的模型
        messages=messages,
        tools=tools,
    )
    return response.choices[0].message

# 发送消息并处理工具调用
def send_messages_without_tools(messages):
    response = client.chat.completions.create(
        model=model,  # 使用的模型
        messages=messages
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java知识技术分享

感谢支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值