openAi入门介绍
- 1.背景
- 2.关键概念
- Prompts and completions(语义搜索 或 文本补全)
- 2.1 Tokens
- 2.2 Models
- 3.快速入门
- 3.1 openAi账号注册
- 3.2 获取开发者API keys
- 3.3 官方SDK
- 4.其他说明
- 4.1 openAi自身限制
- 4.2 账号注册
- 4.3 收费价格
- 4.4 官方提供的探索应用程序的可能性
1.背景
openAi刚公布出来一两周,世面异常火爆,刚开始的时候openAi官网是不用注册账号就可以体验官方的ChatGPT聊天机器人,不过现在由于访问量大增,目前官方需要注册账号登录之后才能体验该功能。
根据官方文档的描述,OpenAI API 几乎可以应用于任何涉及理解或生成自然语言或实现代码等场景。提供一系列具有不同学习训练的模型,适用于处理不同的任务,并且自己能够自定义学习模型,通过大样本数据去喂养该模型,使其能实现自己的应用场景。这些模型可用于从内容生成到语义搜索和分类的所有领域。
2.关键概念
Prompts and completions(语义搜索 或 文本补全)
在一个非常简洁的界面上,只要有一个文本输入框,输入你想查询的文本,提交后台后,系统就能根据指定的模型去生成你查询文本相关的上下文内容
2.1 Tokens
类似描述的文本长度限制,要求输入和输出的文本总长度不能超过各模型限定的Tokens长度。要记住的一个限制是,您的文本提示和生成的完成组合不能超过模型的最大上下文长度(对于大多数模型,这是 2048 个标记,或大约 1500 个单词)。可以查官方的tokenizer tool,了解有关文本如何转换为分词的更多信息。
2.2 Models
模型,官方提供了很多模型集,如下三种
- GPT-3是一组可以理解和生成自然语言的模型,其包含Davinci, Curie, Babbage 和 Ada等子模型,每个子模型的功能不尽相同,官方有对各模型进行详细功能描述、模型支持的最大tokens、最后一次模型训练时间;
- Codex模型是我们可以理解和生成代码的 GPT-3 模型的后代。他们的训练数据包含自然语言和来自GitHub的数十亿行公共代码。该模型最擅长Python,精通JavaScript、Go、Perl、PHP、Ruby、Swift、TypeScript、SQL,甚至 Shell 等十几种语言。想让openai帮你写个小游戏?快来体验一下,输入你的描述,系统来编写完整代码Codex JavaScript Sandbox 和 demo videos;
- Content filter 该模型可以检测文本是否敏感或不安全。目前官方推荐使用moderation endpoint来替代该模型。模型对文本进行了四层分类:仇恨、自残、色情、暴力等。
开发人员可以在官网查询模型的详细信息,了解各模型集下面有哪些子模型,基于使用的场景来选择合适的模型。
3.快速入门
3.1 openAi账号注册
由于openAi刚开放,目前异常火爆,官方需要注册账号才能使用,并且当前是限定了中国区(包括香港)不能直接注册登录访问,需要使用代理IP去完成注册,详细请移步账号注册教程:https://blog.ittutorial.top/ai-ChatGPT/
3.2 获取开发者API keys
注册成功后,登录个人中心,拿到开发者API keys后,就能开始开发对接openAi接口
3.3 官方SDK
Libraries,官方提供了各种语言版本的SDK快速对接开发工具包,也可以不用该SDK工具包,自行直接对接openAi接口去封装自己的代码类库。
有了上面三个步骤,就可以进行开发自己的小应用了。其他关于openAi接口的详细内容,需要访问官方接口文档进一步了解学习
4.其他说明
4.1 openAi自身限制
- 目前使用的人数较多,官方每天都在调整策略进行限制,不稳定,搜索时长超过60s自动断开并报“Network error”,体验不好
- 中国区无法正常注册账号访问,需走代理ip进行访问,不过注册成功之后可以调openAi接口直接访问(不需代理ip)
- 根据描述写代码,写出来的代码能跑起来,执行结果也对,但跟预期存在一定偏差,可以用来借鉴编程思路、或基于其代码进行扩展,再或者重新组织准确的描述重新提交让openAi再提供一份代码
4.2 账号注册
注册过程较长,用的美国ip代理、接码平台选的google服务下的美国虚拟卡号码来接收注册账号用的验证码,注册成功之后,api的调用
4.3 收费价格
openAi是收费的,初始注册账号有18美金的试用金额,详情请看收费价格详细说明
4.4 官方提供的探索应用程序的可能性
Examples
- Q&A —— Answer questions based on existing knowledge.
- Grammar correction —— Corrects sentences into standard English.
- Summarize for a 2nd grader —— Translates difficult text into simpler concepts.
- Natural language to OpenAI API —— Create code to call to the OpenAI API using a natural language instruction.
- Text to command —— Translate text into programmatic commands.
- English to other languages —— Translates English text into French, Spanish and Japanese.
- Natural language to Stripe API —— Create code to call the Stripe API using natural language.
- SQL translate —— Translate natural language to SQL queries.
- Parse unstructured data —— Create tables from long form text
- Classification —— Classify items into categories via example.
- Python to natural language —— Explain a piece of Python code in human understandable language.
- Movie to Emoji —— Convert movie titles into emoji.
- Calculate Time Complexity —— Find the time complexity of a function.
- Translate programming languages —— Translate from one programming language to another
- Advanced tweet classifier —— Advanced sentiment detection for a piece of text.
- Explain code —— Explain a complicated piece of code.
- Keywords —— Extract keywords from a block of text.
- Factual answering —— Guide the model towards factual answering by showing it how to respond to questions that fall outside its knowledge base. Using a '?' to indicate a response to words and phrases that it doesn't know provides a natural response that seems to work better than more abstract replies.
- Ad from product description —— Turn a product description into ad copy.
- Product name generator —— Create product names from examples words. Influenced by a community prompt.
- TL;DR summarization —— Summarize text by adding a 'tl;dr:' to the end of a text passage. It shows that the API understands how to perform a number of tasks with no instructions.
- Python bug fixer —— Find and fix bugs in source code.
- Spreadsheet creator —— Create spreadsheets of various kinds of data. It's a long prompt but very versatile. Output can be copy+pasted into a text file and saved as a .csv with pipe separators.
- JavaScript helper chatbot —— Message-style bot that answers JavaScript questions
- ML/AI language model tutor —— Bot that answers questions about language models
- Science fiction book list maker —— Create a list of items for a given topic.
- Tweet classifier —— Basic sentiment detection for a piece of text.
- Airport code extractor —— Extract airport codes from text.
- SQL request —— Create simple SQL queries.
- Extract contact information —— Extract contact information from a block of text.
- JavaScript to Python —— Convert simple JavaScript expressions into Python.
- Friend chat —— Emulate a text message conversation.
- Mood to color —— Turn a text description into a color.
- Write a Python docstring —— An example of how to create a docstring for a given Python function. We specify the Python version, paste in the code, and then ask within a comment for a docstring, and give a characteristic beginning of a docstring (""").
- Analogy maker —— Create analogies. Modified from a community prompt to require fewer examples.
- JavaScript one line function —— Turn a JavaScript function into a one liner.
- Micro horror story creator —— Creates two to three sentence short horror stories from a topic input.
- Third-person converter —— Converts first-person POV to the third-person. This is modified from a community prompt to use fewer examples.
- Notes to summary —— Turn meeting notes into a summary.
- VR fitness idea generator —— Create ideas for fitness and virtual reality games.
- ESRB rating —— Categorize text based upon ESRB ratings.
- Essay outline —— Generate an outline for a research topic.
- Recipe creator (eat at your own risk) —— Create a recipe from a list of ingredients.
- Chat —— Open ended conversation with an AI assistant.
- Marv the sarcastic chat bot —— Marv is a factual chatbot that is also sarcastic.
- Turn by turn directions —— Convert natural language to turn-by-turn directions.
- Restaurant review creator —— Turn a few words into a restaurant review.
- Create study notes —— Provide a topic and get study notes.
- Interview questions —— Create interview questions.