Open AI API 참조
测试
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": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'
프 록 시 인터페 이스
Cloud F lare 사용
Base URL
https://api.openai.com/v1
대체 하기
https://gateway.ai.cloudflare.com/v1/[xxx]/[yyy]/openai
예를 들면,
curl https://gateway.ai.cloudflare.com/v1/45a93dd9034ce3d27b263a074d05f09a/ververv/openai/chat/completions \
채 팅 인터페 이스 정의
응답 의 형 식 설정
reply _ format
text
또는 j son _ object
중 하나 여야 합니다 .
{ "type": "json_object" }
로 설정 하면 J SON 모 드가 활성화 되어 모델 이 생성 하는 메시 지가 유효 한 J SON 이 될 수 있습니다 .
** 중요 : ** J SON 모 드를 사용할 때 , ** 시스템 또는 사용자 메시지를 통해 J SON 을 생성 하도록 모델 에 지시 해야 합니다 .그렇지 않으면 모델 은 생성 이 토 큰 한 계에 도달 할 때까지 끝 없는 백 백 의 스트 림을 생성 하여 길 고 " 장 착 " 한 요청을 초래 할 수 있습니다 .또한 fin ish _ reason = " leng th " ' 가 발생 이
max _ tok ens ' 를 초 과 했 거나 대화 가 최대 컨 텍 스트 길 이를 초 과 했 음을 나타내는 경우 메시 지의 내용이 부분 적으로 차단 될 수 있음을 유 의 하십시오 .
함 수 호출 / 도구
To ols : 도구 목록
각 도구 는 하나의 객 체 이며 , 각 객 체는
type : Current ly , only function
is supported .
함 수 : 이름 , 설명 , 매 개 변 수
각 매 개 변 수의 정의 :
이름 , 매 개 변 수 유형 , 설명 , 선택 적 값 , 필요한 매 개 변 수
예 제
** 요청 **
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": "What is the weather like in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'
** 응답 **
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699896916,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": "{\n\"location\": \"Boston, MA\"\n}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 82,
"completion_tokens": 17,
"total_tokens": 99
}
}
큰 프레 임
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"tools": [ // tool列表,与model同级
{ // 具体某个tool
"type": "function", // 类型:暂时只支持function
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
// 更具体定义
}
}
}
],
"tool_choice": "auto" // 选择哪个tool,与model同级
}
매 개 변 수
{
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": ["location"],
}