06-30 00:00
Notice
Recent Posts
Recent Comments
06-30 00:00
«   2024/06   »
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
Archives
Today
Total
관리 메뉴

pear

[android] simple GPT retrofit 2 - data 본문

android

[android] simple GPT retrofit 2 - data

pearlab 2023. 6. 13. 10:20

Request Body

import com.google.gson.annotations.SerializedName;
public class GptCall {

   @SerializedName("model")
   public String model;

   @SerializedName("messages")
   public messages messages;

   @SerializedName("max_tokens")
   public String max_tokens;
   public class messages {
      public String role;
      public String content;
   }
}

 

Request Body Json String Example

//String json = "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"What is the OpenAI mission?\"}]}";

 

Resbody

public class gptResponse {

    public String id;
    public String object;
    public int created;
    public String model;

    public choices choices[];

    public class choices{
        public message message;
        public String finish_reason;
        public int index;
    }

    public class message{
        public String role;
        public String content;
    }
}

Response Json String Example

//    {
//        "id": "chatcmpl-(...)",
//            "object": "chat.completion",
//            "created": 1678346481,
//            "model": "gpt-3.5-turbo-0301",
//            "usage": {
//        "prompt_tokens": 11,
//                "completion_tokens": 313,
//                "total_tokens": 324
//    },
//        "choices": [
//        {
//            "message": {
//            "role": "assistant",
//                    "content": "한글날은 한글의 문화적·역사적·언어학적 가치를 널리 알리고 (...)"
//        },
//            "finish_reason": "stop",
//                "index": 0
//        }
//    ]
//    }