إكمالات الدردشة

تعرف على كيفية إنشاء النص أو معالجته باستخدام نقطة نهاية الإكمال الخاصة بواجهة API OpenAI .

سنغطي ما يلي...

نقطة نهاية إكمال الدردشة

يمكن استخدام نقطة نهاية إكمال الدردشة لتنفيذ العديد من المهام على النص، بما في ذلك التصنيف، والتوليد، والتحويل، وإكمال النص غير المكتمل، والردود الفعلية، وغيرها. تتلقى نقطة النهاية رسالة إدخال من المستخدم والدور المُسند إليه، وتُرجع كائن JSON.

Press + to interact
Chat completions
Chat completions

استدعاء واجهة برمجة API للإكمالات

في مقطع الكود أدناه، نستخدم مكتبة openai في Python. يمكن استخدام الدالة التالية لاستدعاء نقطة نهاية الإكمال:

from openai import OpenAI
client = OpenAI(api_key="{{YOUR_SECTEY_KEY}}")
response = client.chat.completions.create(
model="model_id",
messages=[
{"role": "system", "content": "..."},
{"role": "user", "content": "..."}
],
)

فهم نقطة نهاية إكمال الدردشة

دعونا نلقي نظرة على نقطة نهاية إكمال الدردشة بمزيد من التفصيل، ومراجعة معلمات طلب ومعلمات استجابة .

معلمات الطلب

دعونا نرى بعض معلمات طلب الأساسية لهذه النقطة النهائية في الجدول أدناه:

Fields

Format

Type

Description

messages

Array

Required

This is a list of messages comprising the conversation as of yet.

model

String

Required

This is the ID of the model that the chat completions endpoint will use.

max_tokens

Integer

Optional

This is the maximum number of tokens to generate in the chat completion.

temperature

Float

Optional

Which sampling temperature should be employed, ranging from 0 to 2? The default temperature is set at 1. Opting for higher values, such as 0.8, will increase randomness in the output, whereas lower values, like 0.2, will enhance focus and determinism.

top_p

Float

Optional

Nucleus sampling is an alternative to temperature sampling in which the model evaluates the outcomes of tokens with top p probability mass. So, 0.1 indicates that only the top 10% probability mass tokens will be evaluated.

Default value: 1

response_format

object

Optional

This is an object that specifies the format of the output. This parameter is compatible with the newer models.

Setting to { "type" : "json_object" } will guarantee a valid JSON object.

n

Integer

Optional

It indicates the number of chat completions to generate.

Default value: 1

logprobs

Integer

Optional

This value decides whether to return the log probabilities of output tokens. This option is not available on the gpt-4-vision-preview model.

Default value: false

stop

String/array

Optional

This allows you to provide four sequences where the API will stop generating further tokens.

Default value: null

presence_penalty

Float

Optional

A value range between -2.0 to 2.0. The positive value penalizes the new tokens if they exist in the text, increasing the possibility of generating new things.

Default value: 0

frequency_penalty

Float

Optional

A value range between -2.0 to 2.0. The positive value penalizes the new tokens concerning their existing frequency in the text, decreasing the possibility of repeating the same words.

Default value: 0

ملاحظة : يمكنك معرفة المزيد عن وسيطة ...