• 百度文心一言4.0——使用及API测试


    登录百度智能云:百度智能云

    文心一言4.0使用

    开通付费:
    在这里插入图片描述
    创建应用:
    在这里插入图片描述
    自行创建应用名称:
    在这里插入图片描述
    对话测试:
    在这里插入图片描述

    API测试

    ERNIE-Bot-4 API:ERNIE-Bot-4

    打开链接查看自己的API Key,Secret Key。
    在这里插入图片描述

    可参考:API在线调试介绍

    找到示例代码即可:

    
    import requests
    import json
    
    def get_access_token():
        """
        使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key
        """
            
        url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]"
        
        payload = json.dumps("")
        headers = {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
        
        response = requests.request("POST", url, headers=headers, data=payload)
        return response.json().get("access_token")
    
    def main():
        url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=" + get_access_token()
        
        payload = json.dumps({
            "messages": [
                {
                    "role": "user",
                    "content": "介绍一下你自己"
                }
            ]
        })
        headers = {
            'Content-Type': 'application/json'
        }
        
        response = requests.request("POST", url, headers=headers, data=payload)
        
        print(response.text)
        
    
    if __name__ == '__main__':
        main()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    其中,[应用API Key]和[应用Secret Key]分别复制client_id和client_secret,注意是完整字符,不带*。在这里插入图片描述

    PyCharm中即可看到文本回复:
    {

    “id”:“as-xzha01438e”,

    “object”:“chat.completion”,

    “created”:1698112809,

    “result”:“我的大模型版本是文心一言,英文名是ERNIE Bot,是基于百度文心大模型技术推出的生成式对话产品。百度文心大模型是百度自主研发的产业级知识增强大模型,既包含基础通用的大模型,也包含面向重点任务领域和行业的大模型,以及丰富的工具与平台,支撑企业与开发者进行高效便捷的应用开发。相比Chat GPT,文心一言更适用于中文语境。”,

    “is_truncated”:false,

    “need_clear_history”:false,

    “usage”:{“prompt_tokens”:10,“completion_tokens”:140,“total_tokens”:150}

    }

  • 相关阅读:
    重新认识 IP地址
    Nacos-Feign-Gateway
    ssm框架的网上招聘系统的设计与实现,ssm框架,java编程,mysql数据库 myeclipse开发平台
    Servlet的url-pattern配置
    Cocos 进度条物体跟随效果
    未来五十年,智能科技将如何改变传统行业格局?
    【DaVinci Developer工具实战】05 - DaVinci Developer 功能区概述和介绍
    redisson使用全解——redisson官方文档+注释(下篇)
    探索一种C++中构造对象的方式
    字典序问题
  • 原文地址:https://blog.csdn.net/woshigaowei5146/article/details/134005577