001package com.box.sdk; 002 003import com.eclipsesource.json.JsonObject; 004import com.eclipsesource.json.JsonValue; 005 006public abstract class BoxAIAgent extends BoxJSONObject { 007 /** 008 * The type of the AI agent. Value can be "ai_agent_ask" or "ai_agent_text_gen", 009 * "ai_agent_extract", "ai_agent_extract_structured". 010 */ 011 private String type; 012 013 /** 014 * Constructs an AI agent with default settings. 015 * 016 * @param type The type of the AI agent. Value can be "ai_agent_ask", "ai_agent_text_gen", 017 * "ai_agent_extract", "ai_agent_extract_structured". 018 */ 019 public BoxAIAgent(String type) { 020 super(); 021 this.type = type; 022 } 023 024 /** 025 * Constructs an AI agent with default settings. 026 * 027 * @param jsonObject JSON object representing the AI agent. 028 */ 029 public BoxAIAgent(JsonObject jsonObject) { 030 super(jsonObject); 031 } 032 033 /** 034 * Constructs an AI agent with default settings. 035 * 036 * @param jsonObject JSON object representing the AI agent. 037 */ 038 public static BoxAIAgent parse(JsonObject jsonObject) { 039 String type = jsonObject.get("type").asString(); 040 if (type.equals(BoxAIAgentAsk.TYPE)) { 041 return new BoxAIAgentAsk(jsonObject); 042 } else if (type.equals(BoxAIAgentTextGen.TYPE)) { 043 return new BoxAIAgentTextGen(jsonObject); 044 } else if (type.equals(BoxAIAgentExtract.TYPE)) { 045 return new BoxAIAgentExtract(jsonObject); 046 } else if (type.equals(BoxAIAgentExtractStructured.TYPE)) { 047 return new BoxAIAgentExtractStructured(jsonObject); 048 } else { 049 throw new IllegalArgumentException("Invalid AI agent type: " + type); 050 } 051 } 052 053 /** 054 * Gets the type of the AI agent. 055 * 056 * @return The type of the AI agent. 057 */ 058 public String getType() { 059 return type; 060 } 061 062 /** 063 * Sets the type of the AI agent. 064 * 065 * @param type The type of the AI agent. 066 */ 067 public void setType(String type) { 068 this.type = type; 069 } 070 071 @Override 072 void parseJSONMember(JsonObject.Member member) { 073 super.parseJSONMember(member); 074 String memberName = member.getName(); 075 JsonValue value = member.getValue(); 076 if (memberName.equals("type")) { 077 this.type = value.asString(); 078 } 079 } 080 081 public JsonObject getJSONObject() { 082 JsonObject jsonObject = new JsonObject(); 083 jsonObject.add("type", this.type); 084 return jsonObject; 085 } 086 087 /** The type of the AI agent for asking questions. */ 088 public enum Mode { 089 /** The type of AI agent used to handle queries. */ 090 ASK("ask"), 091 /** The type of AI agent used for generating text. */ 092 TEXT_GEN("text_gen"), 093 /** The type of AI agent used for extracting metadata freeform. */ 094 EXTRACT("extract"), 095 /** The type of AI agent used for extracting metadata structured. */ 096 EXTRACT_STRUCTURED("extract_structured"); 097 098 private final String value; 099 100 Mode(String value) { 101 this.value = value; 102 } 103 104 static BoxAIAgent.Mode fromJSONValue(String value) { 105 if (value.equals("ask")) { 106 return ASK; 107 } else if (value.equals("text_gen")) { 108 return TEXT_GEN; 109 } else if (value.equals("extract")) { 110 return EXTRACT; 111 } else if (value.equals("extract_structured")) { 112 return EXTRACT_STRUCTURED; 113 } else { 114 throw new IllegalArgumentException("Invalid AI agent mode: " + value); 115 } 116 } 117 118 String toJSONValue() { 119 return this.value; 120 } 121 122 @Override 123 public String toString() { 124 return this.value; 125 } 126 } 127}