文本上下文 对话 gpt-3.5-turbo GPT-3

openai-cookbook/How_to_stream_completions.ipynb at main · openai/openai-cookbook https://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb

{
	"model": "gpt-3.5-turbo",
	"messages": [{
		"role": "user",
		"content": "昨天下雨了,我出门没带伞,会怎么样"
	}, {
		"role": "assistant",
		"content": "作为AI语言模型,我无法确定您出门时的具体地点和时间。但是如果您在雨中暴雨中走了一段较长的路程,您可能会感到湿透和寒冷,导致您感冒或生病。建议您在下雨天出门时带上雨具,以免不必要的健康风险。"
	}, {
		"role": "user",
		"content": "如果带了呢"
	}, {
		"role": "user",
		"content": "如果带了呢"
	}, {
		"role": "assistant",
		"content": "如果您在下雨天出门时带了伞,您就可以避免被雨淋湿,保持身体干燥,防止感冒和其他健康问题。另外,如果您使用一个可重复使用的伞,这还有助于减少浪费和环境污染。有一个优秀的习惯是在雨季到来之前更新您的雨具,以确保它们能够提供最好的保护。"
	}, {
		"role": "user",
		"content": "如果带了,在下雨前有丢失了呢"
	}, {
		"role": "assistant",
		"content": "如果您在下雨前带了伞但是丢失了,那么您就不能利用它来避免被雨淋湿。这样可能会导致身体受凉,感冒或其他健康问题,特别是如果您在很长时间内被雨淋湿。如果您在下雨天外出,建议您准备备用伞或其他雨具来备用,以防万一需要使用。同时,在下雨天外出前,最好检查好您带的所有雨具,包括伞的状态,这样可以避免出现丢失或使用不当的问题。"
	}, {
		"role": "user",
		"content": "你是什么引擎"
	}, {
		"role": "assistant",
		"content": "我是基于人工智能技术的AI语言模型,由OpenAI GPT-3 引擎驱动。它是一种自然语言处理技术,利用深度学习算法分析大量文本数据,从而在理解自然语言和产生自然语言的任务上表现出色。请注意,我是由OpenAI开发的AI语言模型系统的一部分,但我和GPT-3不是完全一样的东西。"
	}, {
		"role": "user",
		"content": "你俩哪里不一样"
	}, {
		"role": "user",
		"content": "你俩哪里不一样"
	}, {
		"role": "assistant",
		"content": "虽然我是由OpenAI GPT-3 引擎驱动,但是我和GPT-3在使用方法和应用场景上有所不同。\n\n- 使用方法方面,GPT-3是一种通用的自然语言处理模型,它可以用于生成文本、回答问题、翻译语言等,通过API接口提供服务。而我是根据固定的应答指令来进行回答的,一般用于简单的问答场景。\n\n- 应用场景方面,GPT-3覆盖了更广的应用场景,包括写作、机器翻译、对话等多个领域。而我则主要应用于简单的问答场景,例如提供基本的词语解释,给出一些简短、直接和易于理解的回答。\n\n另外,虽然我和GPT-3有不同的使用方法和应用场景,但是我们都是由深度学习技术驱动的AI语言模型,能够处理和产生自然语言的任务。"
	}, {
		"role": "user",
		"content": "如果带了,在下雨前又丢失了,然后在下雨前又买了一个,会怎样呢"
	}, {
		"role": "assistant",
		"content": "如果您在下雨前带了伞但是丢失了,之后重新购买了一个并使用它来保持身体干燥,在下雨天出行期间应该没有什么问题,并且您可以避免因为没有保护而感冒或生病。不过,购买一个新伞可能会花费您一些额外的时间和费用,而且也可能有些不便。因此,在下雨天前最好检查您现有的雨具,确保它们处于良好的状态,以避免丢失或其他不必要的问题。"
	}, {
		"role": "user",
		"content": "如果带了,在下雨前又丢失了,然后在下雨前又买了一个,但是它是坏的,会怎样呢"
	}],
	"stream": true
}

  

上层应用的接口设计

{"version":"1.0.0","pars":{"user_id":"123","question":"我出门没带钱包 怎么买饭","group_id":"456","question_id":""}}

{"version":"1.0.0","pars":{"user_id":"123","question":"如果带了呢","group_id":"456","question_id":""}}

 

 

https://platform.openai.com/docs/api-reference/chat/create

Introduction

You can interact with the API through HTTP requests from any language, via our official Python bindings, our official Node.js library, or a community-maintained library.

To install the official Python bindings, run the following command:

pip install openai

To install the official Node.js library, run the following command in your Node.js project directory:

npm install openai

Authentication

The OpenAI API uses API keys for authentication. Visit your API Keys page to retrieve the API key you'll use in your requests.

Remember that your API key is a secret! Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.

All API requests should include your API key in an Authorization HTTP header as follows:

Authorization: Bearer OPENAI_API_KEY

Requesting organization

For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.

Example curl command:

1
2
3
curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Organization: org-JHbL6ZELC8Fgh2wxbvEGTLHD"

Example with the openai Python package:

1
2
3
4
5
import os
import openai
openai.organization = "org-JHbL6ZELC8Fgh2wxbvEGTLHD"
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Model.list()

Example with the openai Node.js package:

1
2
3
4
5
6
7
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
    organization: "org-JHbL6ZELC8Fgh2wxbvEGTLHD",
    apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.listEngines();

Organization IDs can be found on your Organization settings page.

Making requests

You can paste the command below into your terminal to run your first API request. Make sure to replace $OPENAI_API_KEY with your secret API key.

1
2
3
4
5
6
7
8
curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'

This request queries the gpt-3.5-turbo model to complete the text starting with a prompt of "Say this is a test". You should get a response back that resembles the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
   "id":"chatcmpl-abc123",
   "object":"chat.completion",
   "created":1677858242,
   "model":"gpt-3.5-turbo-0301",
   "usage":{
      "prompt_tokens":13,
      "completion_tokens":7,
      "total_tokens":20
   },
   "choices":[
      {
         "message":{
            "role":"assistant",
            "content":"\n\nThis is a test!"
         },
         "finish_reason":"stop",
         "index":0
      }
   ]
}

Now you've generated your first chat completion. We can see the finish_reason is stop which means the API returned the full completion generated by the model. In the above request, we only generated a single message but you can set the n parameter to generate multiple messages choices. In this example, gpt-3.5-turbo is being used for more of a traditional text completion task. The model is also optimized for chat applications as well.

Models

List and describe the various models available in the API. You can refer to the Models documentation to understand what models are available and the differences between them.

List models

GET https://api.openai.com/v1/models

Lists the currently available models, and provides basic information about each one such as the owner and availability.

Example request
curl
1
2
curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
  "data": [
    {
      "id": "model-id-0",
      "object": "model",
      "owned_by": "organization-owner",
      "permission": [...]
    },
    {
      "id": "model-id-1",
      "object": "model",
      "owned_by": "organization-owner",
      "permission": [...]
    },
    {
      "id": "model-id-2",
      "object": "model",
      "owned_by": "openai",
      "permission": [...]
    },
  ],
  "object": "list"
}

Retrieve model

GET https://api.openai.com/v1/models/{model}

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

Path parameters

Example request
text-davinci-003
curl
1
2
curl https://api.openai.com/v1/models/text-davinci-003 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
text-davinci-003
1
2
3
4
5
6
{
  "id": "text-davinci-003",
  "object": "model",
  "owned_by": "openai",
  "permission": [...]
}

Completions

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

Create completion

POST https://api.openai.com/v1/completions

Creates a completion for the provided prompt and parameters

Request body

Example request
text-davinci-003
curl
1
2
3
4
5
6
7
8
9
curl https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "text-davinci-003",
    "prompt": "Say this is a test",
    "max_tokens": 7,
    "temperature": 0
  }'
Parameters
text-davinci-003
1
2
3
4
5
6
7
8
9
10
11
{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 7,
  "temperature": 0,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "logprobs": null,
  "stop": "\n"
}
Response
text-davinci-003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
  "object": "text_completion",
  "created": 1589478378,
  "model": "text-davinci-003",
  "choices": [
    {
      "text": "\n\nThis is indeed a test",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12
  }
}

Chat

Given a chat conversation, the model will return a chat completion response.

Create chat completion

Beta

POST https://api.openai.com/v1/chat/completions

Creates a completion for the chat message

Request body

Example request
curl
1
2
3
4
5
6
7
curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
Parameters
1
2
3
4
{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]
}
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}

Edits

Given a prompt and an instruction, the model will return an edited version of the prompt.

Create edit

POST https://api.openai.com/v1/edits

Creates a new edit for the provided input, instruction, and parameters.

Request body

Example request
text-davinci-edit-001
curl
1
2
3
4
5
6
7
8
curl https://api.openai.com/v1/edits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "text-davinci-edit-001",
    "input": "What day of the wek is it?",
    "instruction": "Fix the spelling mistakes"
  }'
Parameters
text-davinci-edit-001
1
2
3
4
5
{
  "model": "text-davinci-edit-001",
  "input": "What day of the wek is it?",
  "instruction": "Fix the spelling mistakes",
}
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "object": "edit",
  "created": 1589478378,
  "choices": [
    {
      "text": "What day of the week is it?",
      "index": 0,
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 32,
    "total_tokens": 57
  }
}

Images

Given a prompt and/or an input image, the model will generate a new image.

Related guide: Image generation

Create image

Beta

POST https://api.openai.com/v1/images/generations

Creates an image given a prompt.

Request body

Example request
curl
1
2
3
4
5
6
7
8
curl https://api.openai.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "prompt": "A cute baby sea otter",
    "n": 2,
    "size": "1024x1024"
  }'
Parameters
1
2
3
4
5
{
  "prompt": "A cute baby sea otter",
  "n": 2,
  "size": "1024x1024"
}
Response
1
2
3
4
5
6
7
8
9
10
11
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

Create image edit

Beta

POST https://api.openai.com/v1/images/edits

Creates an edited or extended image given an original image and a prompt.

Request body

Example request
curl
1
2
3
4
5
6
7
curl https://api.openai.com/v1/images/edits \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F image="@otter.png" \
  -F mask="@mask.png" \
  -F prompt="A cute baby sea otter wearing a beret" \
  -F n=2 \
  -F size="1024x1024"
Response
1
2
3
4
5
6
7
8
9
10
11
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

Create image variation

Beta

POST https://api.openai.com/v1/images/variations

Creates a variation of a given image.

Request body

Example request
curl
1
2
3
4
5
curl https://api.openai.com/v1/images/variations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F image="@otter.png" \
  -F n=2 \
  -F size="1024x1024"
Response
1
2
3
4
5
6
7
8
9
10
11
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

Embeddings

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.

Related guide: Embeddings

Create embeddings

POST https://api.openai.com/v1/embeddings

Creates an embedding vector representing the input text.

Request body

Example request
curl
1
2
3
4
5
6
7
curl https://api.openai.com/v1/embeddings \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "The food was delicious and the waiter...",
    "model": "text-embedding-ada-002"
  }'
Parameters
1
2
3
4
{
  "model": "text-embedding-ada-002",
  "input": "The food was delicious and the waiter..."
}
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        .... (1536 floats total for ada-002)
        -0.0028842222,
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

Audio

Learn how to turn audio into text.

Related guide: Speech to text

Create transcription

Beta

POST https://api.openai.com/v1/audio/transcriptions

Transcribes audio into the input language.

Request body

Example request
curl
1
2
3
4
5
curl https://api.openai.com/v1/audio/transcriptions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F file="@/path/to/file/audio.mp3" \
  -F model="whisper-1"
Parameters
1
2
3
4
{
  "file": "audio.mp3",
  "model": "whisper-1"
}
Response
1
2
3
{
  "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that."
}

Create translation

Beta

POST https://api.openai.com/v1/audio/translations

Translates audio into into English.

Request body

Example request
curl
1
2
3
4
5
curl https://api.openai.com/v1/audio/translations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F file="@/path/to/file/german.m4a" \
  -F model="whisper-1"
Parameters
1
2
3
4
{
  "file": "german.m4a",
  "model": "whisper-1"
}
Response
1
2
3
{
  "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?"
}

Files

Files are used to upload documents that can be used with features like Fine-tuning.

List files

GET https://api.openai.com/v1/files

Returns a list of files that belong to the user's organization.

Example request
curl
1
2
curl https://api.openai.com/v1/files \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
  "data": [
    {
      "id": "file-ccdDZrC3iZVNiQVeEA6Z66wf",
      "object": "file",
      "bytes": 175,
      "created_at": 1613677385,
      "filename": "train.jsonl",
      "purpose": "search"
    },
    {
      "id": "file-XjGxS3KTG0uNmNOK362iJua3",
      "object": "file",
      "bytes": 140,
      "created_at": 1613779121,
      "filename": "puppy.jsonl",
      "purpose": "search"
    }
  ],
  "object": "list"
}

Upload file

POST https://api.openai.com/v1/files

Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.

Request body

Example request
curl
1
2
3
4
curl https://api.openai.com/v1/files \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F purpose="fine-tune" \
  -F file="@mydata.jsonl"
Response
1
2
3
4
5
6
7
8
{
  "id": "file-XjGxS3KTG0uNmNOK362iJua3",
  "object": "file",
  "bytes": 140,
  "created_at": 1613779121,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune"
}

Delete file

DELETE https://api.openai.com/v1/files/{file_id}

Delete a file.

Path parameters

Example request
curl
1
2
3
curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \
  -X DELETE \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
{
  "id": "file-XjGxS3KTG0uNmNOK362iJua3",
  "object": "file",
  "deleted": true
}

Retrieve file

GET https://api.openai.com/v1/files/{file_id}

Returns information about a specific file.

Path parameters

Example request
curl
1
2
curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
{
  "id": "file-XjGxS3KTG0uNmNOK362iJua3",
  "object": "file",
  "bytes": 140,
  "created_at": 1613779657,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune"
}

Retrieve file content

GET https://api.openai.com/v1/files/{file_id}/content

Returns the contents of the specified file

Path parameters

Example request
curl
1
2
curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3/content \
  -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl

Fine-tunes

Manage fine-tuning jobs to tailor a model to your specific training data.

Related guide: Fine-tune models

Create fine-tune

POST https://api.openai.com/v1/fine-tunes

Creates a job that fine-tunes a specified model from a given dataset.

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

Learn more about Fine-tuning

Request body

Example request
curl
1
2
3
4
5
6
curl https://api.openai.com/v1/fine-tunes \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "training_file": "file-XGinujblHPwGLSztz8cPS8XY"
  }'
Response
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
{
  "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
  "object": "fine-tune",
  "model": "curie",
  "created_at": 1614807352,
  "events": [
    {
      "object": "fine-tune-event",
      "created_at": 1614807352,
      "level": "info",
      "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0."
    }
  ],
  "fine_tuned_model": null,
  "hyperparams": {
    "batch_size": 4,
    "learning_rate_multiplier": 0.1,
    "n_epochs": 4,
    "prompt_loss_weight": 0.1,
  },
  "organization_id": "org-...",
  "result_files": [],
  "status": "pending",
  "validation_files": [],
  "training_files": [
    {
      "id": "file-XGinujblHPwGLSztz8cPS8XY",
      "object": "file",
      "bytes": 1547276,
      "created_at": 1610062281,
      "filename": "my-data-train.jsonl",
      "purpose": "fine-tune-train"
    }
  ],
  "updated_at": 1614807352,
}

List fine-tunes

GET https://api.openai.com/v1/fine-tunes

List your organization's fine-tuning jobs

Example request
curl
1
2
curl https://api.openai.com/v1/fine-tunes \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
  "object": "list",
  "data": [
    {
      "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
      "object": "fine-tune",
      "model": "curie",
      "created_at": 1614807352,
      "fine_tuned_model": null,
      "hyperparams": { ... },
      "organization_id": "org-...",
      "result_files": [],
      "status": "pending",
      "validation_files": [],
      "training_files": [ { ... } ],
      "updated_at": 1614807352,
    },
    { ... },
    { ... }
  ]
}

Retrieve fine-tune

GET https://api.openai.com/v1/fine-tunes/{fine_tune_id}

Gets info about the fine-tune job.

Learn more about Fine-tuning

Path parameters

Example request
curl
1
2
curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
  "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
  "object": "fine-tune",
  "model": "curie",
  "created_at": 1614807352,
  "events": [
    {
      "object": "fine-tune-event",
      "created_at": 1614807352,
      "level": "info",
      "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807356,
      "level": "info",
      "message": "Job started."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807861,
      "level": "info",
      "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807864,
      "level": "info",
      "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807864,
      "level": "info",
      "message": "Job succeeded."
    }
  ],
  "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20",
  "hyperparams": {
    "batch_size": 4,
    "learning_rate_multiplier": 0.1,
    "n_epochs": 4,
    "prompt_loss_weight": 0.1,
  },
  "organization_id": "org-...",
  "result_files": [
    {
      "id": "file-QQm6ZpqdNwAaVC3aSz5sWwLT",
      "object": "file",
      "bytes": 81509,
      "created_at": 1614807863,
      "filename": "compiled_results.csv",
      "purpose": "fine-tune-results"
    }
  ],
  "status": "succeeded",
  "validation_files": [],
  "training_files": [
    {
      "id": "file-XGinujblHPwGLSztz8cPS8XY",
      "object": "file",
      "bytes": 1547276,
      "created_at": 1610062281,
      "filename": "my-data-train.jsonl",
      "purpose": "fine-tune-train"
    }
  ],
  "updated_at": 1614807865,
}

Cancel fine-tune

POST https://api.openai.com/v1/fine-tunes/{fine_tune_id}/cancel

Immediately cancel a fine-tune job.

Path parameters

Example request
curl
1
2
curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7",
  "object": "fine-tune",
  "model": "curie",
  "created_at": 1614807770,
  "events": [ { ... } ],
  "fine_tuned_model": null,
  "hyperparams": { ... },
  "organization_id": "org-...",
  "result_files": [],
  "status": "cancelled",
  "validation_files": [],
  "training_files": [
    {
      "id": "file-XGinujblHPwGLSztz8cPS8XY",
      "object": "file",
      "bytes": 1547276,
      "created_at": 1610062281,
      "filename": "my-data-train.jsonl",
      "purpose": "fine-tune-train"
    }
  ],
  "updated_at": 1614807789,
}

List fine-tune events

GET https://api.openai.com/v1/fine-tunes/{fine_tune_id}/events

Get fine-grained status updates for a fine-tune job.

Path parameters

Query parameters

Example request
curl
1
2
curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
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
{
  "object": "list",
  "data": [
    {
      "object": "fine-tune-event",
      "created_at": 1614807352,
      "level": "info",
      "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807356,
      "level": "info",
      "message": "Job started."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807861,
      "level": "info",
      "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807864,
      "level": "info",
      "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT."
    },
    {
      "object": "fine-tune-event",
      "created_at": 1614807864,
      "level": "info",
      "message": "Job succeeded."
    }
  ]
}

Delete fine-tune model

DELETE https://api.openai.com/v1/models/{model}

Delete a fine-tuned model. You must have the Owner role in your organization.

Path parameters

Example request
curl
1
2
3
curl https://api.openai.com/v1/models/curie:ft-acmeco-2021-03-03-21-44-20 \
  -X DELETE \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
{
  "id": "curie:ft-acmeco-2021-03-03-21-44-20",
  "object": "model",
  "deleted": true
}

Moderations

Given a input text, outputs if the model classifies it as violating OpenAI's content policy.

Related guide: Moderations

Create moderation

POST https://api.openai.com/v1/moderations

Classifies if text violates OpenAI's Content Policy

Request body

Example request
curl
1
2
3
4
5
6
curl https://api.openai.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "input": "I want to kill them."
  }'
Parameters
1
2
3
{
  "input": "I want to kill them."
}
Response
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
{
  "id": "modr-5MWoLO",
  "model": "text-moderation-001",
  "results": [
    {
      "categories": {
        "hate": false,
        "hate/threatening": true,
        "self-harm": false,
        "sexual": false,
        "sexual/minors": false,
        "violence": true,
        "violence/graphic": false
      },
      "category_scores": {
        "hate": 0.22714105248451233,
        "hate/threatening": 0.4132447838783264,
        "self-harm": 0.005232391878962517,
        "sexual": 0.01407341007143259,
        "sexual/minors": 0.0038522258400917053,
        "violence": 0.9223177433013916,
        "violence/graphic": 0.036865197122097015
      },
      "flagged": true
    }
  ]
}

Engines

 
The Engines endpoints are deprecated.

Please use their replacement, Models, instead. Learn more.

These endpoints describe and provide access to the various engines available in the API.

List engines

Deprecated

GET https://api.openai.com/v1/engines

Lists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability.

Example request
curl
1
2
curl https://api.openai.com/v1/engines \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
  "data": [
    {
      "id": "engine-id-0",
      "object": "engine",
      "owner": "organization-owner",
      "ready": true
    },
    {
      "id": "engine-id-2",
      "object": "engine",
      "owner": "organization-owner",
      "ready": true
    },
    {
      "id": "engine-id-3",
      "object": "engine",
      "owner": "openai",
      "ready": false
    },
  ],
  "object": "list"
}

Retrieve engine

Deprecated

GET https://api.openai.com/v1/engines/{engine_id}

Retrieves a model instance, providing basic information about it such as the owner and availability.

Path parameters

Example request
text-davinci-003
curl
1
2
curl https://api.openai.com/v1/engines/text-davinci-003 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
text-davinci-003
1
2
3
4
5
6
{
  "id": "text-davinci-003",
  "object": "engine",
  "owner": "openai",
  "ready": true
}

Parameter details

Frequency and presence penalties

The frequency and presence penalties found in the Completions API can be used to reduce the likelihood of sampling repetitive sequences of tokens. They work by directly modifying the logits (un-normalized log-probabilities) with an additive contribution.

mu[j] -> mu[j] - c[j] * alpha_frequency - float(c[j] > 0) * alpha_presence

Where:

  • mu[j] is the logits of the j-th token
  • c[j] is how often that token was sampled prior to the current position
  • float(c[j] > 0) is 1 if c[j] > 0 and 0 otherwise
  • alpha_frequency is the frequency penalty coefficient
  • alpha_presence is the presence penalty coefficient

As we can see, the presence penalty is a one-off additive contribution that applies to all tokens that have been sampled at least once and the frequency penalty is a contribution that is proportional to how often a particular token has already been sampled.

Reasonable values for the penalty coefficients are around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition.

 

 

 

 

 

 

 

 

posted @ 2023-04-01 23:31  papering  阅读(548)  评论(0编辑  收藏  举报