• python openai playground使用教程


    playground介绍

    OpenAI Playground是一个基于Web的工具,旨在帮助开发人员测试和尝试OpenAI的语言模型,如GPT-3。通过Playground,用户可以在不编写任何代码的情况下与AI模型进行交互,并了解其工作原理。

    在这里插入图片描述

    playground地址:https://platform.openai.com/playground

    Playground特点
    • 灵活性:Playground提供一个交互式界面,以便用户自定义输入和修改模型参数。
    • 定制性:用户可以根据自己的需求选择不同的语言模型和模型设置,以满足特定的应用场景。
    • 易用性:Playground的用户界面简洁直观,无需编写复杂的代码,即可快速上手和进行实验
    模型设置和参数选择

    Web界面分为左中右三部分

    • 左侧:System,You are a helpful assistant.(定义gpt模型的角色)
    • 中间:USER,Enter a user meaasge here.(输入想问的问题,或者想要补全的句子),submit即可产出回答。
    • 右侧:模型设置和参数选择
      • Mode:模式选择,chat、Complete and Edit。
      • Model:turbo、davinci、curie、babbage、ada。
      • Temperature:介于0-1之间,越接近1,模型生成的回答越有不确定性(创造性),越接近0,模型的答案越确定。
        在这里插入图片描述
    四种语言模型介绍
    • AdaAda是一种基础模型,适合用于提示和短对话。
    • BabbageBabbage是一个中等规模的模型,适合于更长的对话和创造性写作。
    • CurieCurie是一个大型模型,适用于复杂的对话和生成性任务。
    • DavinciDavinciOpenAI提供的最先进的语言模型,适合处理长篇大论、技术文档和创造性写作等。
    playground应用

    examples:https://platform.openai.com/examples

    OpenAI官网的examples中提供了许多有用的示例,可以了解OpenAI的使用。

    • Emoji Translation(一个表情包翻译器)
      作用是将文字转为emoji

    • 设置Prompt
    • SYSTEM:You will be provided with text, and your task is to translate it into emojis. Do not use any regular text. Do your best with emojis only.
    • USER:Artificial intelligence is a technology with great promise.
    • Open in playground
      在这里插入图片描述
      点击submit即可生成对应的转化结果。
    构建自己的playground应用
    • 定义System
    • 定义user
    • 点击submit输出结果
    • 右上角点击”Save"保存
      在这里插入图片描述
    • Save preset
      This will save the current Playground state as a preset which you can access later or share with others.
    • 点击 Your presets,即可看到自己的playground列表
      在这里插入图片描述
    playground python使用

    一个情感分析playground
    在这里插入图片描述

    • 点击View code
      You can use the following code to start integrating your current prompt and settings into your application.
    • copy复制python代码
      在这里插入图片描述
    • 本地python中使用
      question:“To be or not to be, this is a question.”
      response:
    {
      "id": "chatcmpl-89lIKZt8UG1aVVBkB9Wo3ECiPoZ9M",
      "object": "chat.completion",
      "created": 1697337444,
      "model": "gpt-3.5-turbo-0613",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Sentiment: NEUTRAL\nProbability: 0.50"
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 130,
        "completion_tokens": 13,
        "total_tokens": 143
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    包含rolecontenttotal_tokens等完整输出。

    可见的是这种方法相当消耗tokenmoney),因此之后我们会选择微调fine-tuning的形式,OpenAI也已经提供了简便的微调方式。

  • 相关阅读:
    Leetcode 878. 第 N 个神奇数字
    后端关卡18 了解JDBC
    设计模式之解释器模式
    MySQL8.0学习笔记
    【2023年11月第四版教材】软考高项极限冲刺篇笔记(3)
    贪心算法笔记
    用微信小程序开启桶装水订购业务
    M1 芯片 MacBook 结合 MAMP 集成环境配置 PHP 环境变量
    设计模式之观察者模式
    Java高并发编程实战2,原子性、可见性、有序性,傻傻分不清
  • 原文地址:https://blog.csdn.net/weixin_46530492/article/details/133838665