-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support AI Agent API (box/box-codegen#531) (#170)
- Loading branch information
1 parent
d51df9a
commit fc9a00b
Showing
30 changed files
with
1,096 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ "engineHash": "6a7e147", "specHash": "137da0d", "version": "0.3.0" } | ||
{ "engineHash": "f6b5758", "specHash": "d36b9f0", "version": "0.3.0" } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Foundation | ||
|
||
public class GetAiAgentDefaultConfigHeaders { | ||
/// Extra headers that will be included in the HTTP request. | ||
public let extraHeaders: [String: String?]? | ||
|
||
/// Initializer for a GetAiAgentDefaultConfigHeaders. | ||
/// | ||
/// - Parameters: | ||
/// - extraHeaders: Extra headers that will be included in the HTTP request. | ||
public init(extraHeaders: [String: String?]? = [:]) { | ||
self.extraHeaders = extraHeaders | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
Sources/Managers/Ai/GetAiAgentDefaultConfigQueryParams.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
|
||
public class GetAiAgentDefaultConfigQueryParams { | ||
/// The mode to filter the agent config to return. | ||
public let mode: GetAiAgentDefaultConfigQueryParamsModeField | ||
|
||
/// The ISO language code to return the agent config for. | ||
/// If the language is not supported the default agent config is returned. | ||
public let language: String? | ||
|
||
/// The model to return the default agent config for. | ||
public let model: String? | ||
|
||
/// Initializer for a GetAiAgentDefaultConfigQueryParams. | ||
/// | ||
/// - Parameters: | ||
/// - mode: The mode to filter the agent config to return. | ||
/// - language: The ISO language code to return the agent config for. | ||
/// If the language is not supported the default agent config is returned. | ||
/// - model: The model to return the default agent config for. | ||
public init(mode: GetAiAgentDefaultConfigQueryParamsModeField, language: String? = nil, model: String? = nil) { | ||
self.mode = mode | ||
self.language = language | ||
self.model = model | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Sources/Managers/Ai/GetAiAgentDefaultConfigQueryParamsModeField.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
public enum GetAiAgentDefaultConfigQueryParamsModeField: String, CodableStringEnum { | ||
case ask | ||
case textGen = "text_gen" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Foundation | ||
|
||
/// The AI agent used to handle queries. | ||
public class AiAgentAsk: Codable { | ||
private enum CodingKeys: String, CodingKey { | ||
case type | ||
case longText = "long_text" | ||
case basicText = "basic_text" | ||
case longTextMulti = "long_text_multi" | ||
case basicTextMulti = "basic_text_multi" | ||
} | ||
|
||
/// The type of AI agent used to handle queries. | ||
public let type: AiAgentAskTypeField? | ||
|
||
public let longText: AiAgentLongTextTool? | ||
|
||
public let basicText: AiAgentBasicTextToolAsk? | ||
|
||
public let longTextMulti: AiAgentLongTextTool? | ||
|
||
public let basicTextMulti: AiAgentBasicTextToolAsk? | ||
|
||
/// Initializer for a AiAgentAsk. | ||
/// | ||
/// - Parameters: | ||
/// - type: The type of AI agent used to handle queries. | ||
/// - longText: | ||
/// - basicText: | ||
/// - longTextMulti: | ||
/// - basicTextMulti: | ||
public init(type: AiAgentAskTypeField? = nil, longText: AiAgentLongTextTool? = nil, basicText: AiAgentBasicTextToolAsk? = nil, longTextMulti: AiAgentLongTextTool? = nil, basicTextMulti: AiAgentBasicTextToolAsk? = nil) { | ||
self.type = type | ||
self.longText = longText | ||
self.basicText = basicText | ||
self.longTextMulti = longTextMulti | ||
self.basicTextMulti = basicTextMulti | ||
} | ||
|
||
required public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
type = try container.decodeIfPresent(AiAgentAskTypeField.self, forKey: .type) | ||
longText = try container.decodeIfPresent(AiAgentLongTextTool.self, forKey: .longText) | ||
basicText = try container.decodeIfPresent(AiAgentBasicTextToolAsk.self, forKey: .basicText) | ||
longTextMulti = try container.decodeIfPresent(AiAgentLongTextTool.self, forKey: .longTextMulti) | ||
basicTextMulti = try container.decodeIfPresent(AiAgentBasicTextToolAsk.self, forKey: .basicTextMulti) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encodeIfPresent(type, forKey: .type) | ||
try container.encodeIfPresent(longText, forKey: .longText) | ||
try container.encodeIfPresent(basicText, forKey: .basicText) | ||
try container.encodeIfPresent(longTextMulti, forKey: .longTextMulti) | ||
try container.encodeIfPresent(basicTextMulti, forKey: .basicTextMulti) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public enum AiAgentAskTypeField: String, CodableStringEnum { | ||
case aiAgentAsk = "ai_agent_ask" | ||
} |
48 changes: 48 additions & 0 deletions
48
Sources/Schemas/AiAgentAskOrAiAgentTextGen/AiAgentAskOrAiAgentTextGen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
|
||
public enum AiAgentAskOrAiAgentTextGen: Codable { | ||
case aiAgentAsk(AiAgentAsk) | ||
case aiAgentTextGen(AiAgentTextGen) | ||
|
||
private enum DiscriminatorCodingKey: String, CodingKey { | ||
case type | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
if let container = try? decoder.container(keyedBy: DiscriminatorCodingKey.self) { | ||
if let discriminator_0 = try? container.decode(String.self, forKey: .type) { | ||
switch discriminator_0 { | ||
case "ai_agent_ask": | ||
if let content = try? AiAgentAsk(from: decoder) { | ||
self = .aiAgentAsk(content) | ||
return | ||
} | ||
|
||
case "ai_agent_text_gen": | ||
if let content = try? AiAgentTextGen(from: decoder) { | ||
self = .aiAgentTextGen(content) | ||
return | ||
} | ||
|
||
default: | ||
throw DecodingError.typeMismatch(AiAgentAskOrAiAgentTextGen.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "The Decoded object contains an unexpected value for key type")) | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
throw DecodingError.typeMismatch(AiAgentAskOrAiAgentTextGen.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "The type of the decoded object cannot be determined.")) | ||
|
||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
switch self { | ||
case .aiAgentAsk(let aiAgentAsk): | ||
try aiAgentAsk.encode(to: encoder) | ||
case .aiAgentTextGen(let aiAgentTextGen): | ||
try aiAgentTextGen.encode(to: encoder) | ||
} | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
Sources/Schemas/AiAgentBasicGenTool/AiAgentBasicGenTool.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
|
||
/// AI agent basic tool used to generate text. | ||
public class AiAgentBasicGenTool: AiAgentLongTextTool { | ||
private enum CodingKeys: String, CodingKey { | ||
case contentTemplate = "content_template" | ||
} | ||
|
||
/// How the content should be included in a request to the LLM. | ||
/// When passing this parameter, you must include `{content}`. | ||
public let contentTemplate: String? | ||
|
||
/// Initializer for a AiAgentBasicGenTool. | ||
/// | ||
/// - Parameters: | ||
/// - model: The model to be used for the AI Agent for basic text. | ||
/// - systemMessage: System messages try to help the LLM "understand" its role and what it is supposed to do. | ||
/// This parameter requires using `{current_date}`. | ||
/// - promptTemplate: The prompt template contains contextual information of the request and the user prompt. | ||
/// | ||
/// When using the `prompt_template` parameter, you **must include** input for `{user_question}`. | ||
/// Inputs for `{current_date}` and`{content}` are optional, depending on the use. | ||
/// - numTokensForCompletion: The number of tokens for completion. | ||
/// - llmEndpointParams: | ||
/// - embeddings: | ||
/// - contentTemplate: How the content should be included in a request to the LLM. | ||
/// When passing this parameter, you must include `{content}`. | ||
public init(model: String? = nil, systemMessage: String? = nil, promptTemplate: String? = nil, numTokensForCompletion: Int64? = nil, llmEndpointParams: AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? = nil, embeddings: AiAgentLongTextToolEmbeddingsField? = nil, contentTemplate: String? = nil) { | ||
self.contentTemplate = contentTemplate | ||
|
||
super.init(model: model, systemMessage: systemMessage, promptTemplate: promptTemplate, numTokensForCompletion: numTokensForCompletion, llmEndpointParams: llmEndpointParams, embeddings: embeddings) | ||
} | ||
|
||
required public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
contentTemplate = try container.decodeIfPresent(String.self, forKey: .contentTemplate) | ||
|
||
try super.init(from: decoder) | ||
} | ||
|
||
public override func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encodeIfPresent(contentTemplate, forKey: .contentTemplate) | ||
try super.encode(to: encoder) | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
Sources/Schemas/AiAgentBasicTextToolAsk/AiAgentBasicTextToolAsk.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Foundation | ||
|
||
/// AI agent tool used to handle basic text. | ||
public class AiAgentBasicTextToolAsk: Codable { | ||
private enum CodingKeys: String, CodingKey { | ||
case model | ||
case systemMessage = "system_message" | ||
case promptTemplate = "prompt_template" | ||
case numTokensForCompletion = "num_tokens_for_completion" | ||
case llmEndpointParams = "llm_endpoint_params" | ||
} | ||
|
||
/// The model used for the AI Agent for basic text. | ||
public let model: String? | ||
|
||
/// System messages try to help the LLM "understand" its role and what it is supposed to do. | ||
public let systemMessage: String? | ||
|
||
/// The prompt template contains contextual information of the request and the user prompt. | ||
/// | ||
/// When passing `prompt_template` parameters, you **must include** inputs for `{current_date}`, `{user_question}`, and `{content}`. | ||
public let promptTemplate: String? | ||
|
||
/// The number of tokens for completion. | ||
public let numTokensForCompletion: Int64? | ||
|
||
/// The parameters for the LLM endpoint specific to OpenAI / Google models. | ||
public let llmEndpointParams: AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? | ||
|
||
/// Initializer for a AiAgentBasicTextToolAsk. | ||
/// | ||
/// - Parameters: | ||
/// - model: The model used for the AI Agent for basic text. | ||
/// - systemMessage: System messages try to help the LLM "understand" its role and what it is supposed to do. | ||
/// - promptTemplate: The prompt template contains contextual information of the request and the user prompt. | ||
/// | ||
/// When passing `prompt_template` parameters, you **must include** inputs for `{current_date}`, `{user_question}`, and `{content}`. | ||
/// - numTokensForCompletion: The number of tokens for completion. | ||
/// - llmEndpointParams: The parameters for the LLM endpoint specific to OpenAI / Google models. | ||
public init(model: String? = nil, systemMessage: String? = nil, promptTemplate: String? = nil, numTokensForCompletion: Int64? = nil, llmEndpointParams: AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? = nil) { | ||
self.model = model | ||
self.systemMessage = systemMessage | ||
self.promptTemplate = promptTemplate | ||
self.numTokensForCompletion = numTokensForCompletion | ||
self.llmEndpointParams = llmEndpointParams | ||
} | ||
|
||
required public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
model = try container.decodeIfPresent(String.self, forKey: .model) | ||
systemMessage = try container.decodeIfPresent(String.self, forKey: .systemMessage) | ||
promptTemplate = try container.decodeIfPresent(String.self, forKey: .promptTemplate) | ||
numTokensForCompletion = try container.decodeIfPresent(Int64.self, forKey: .numTokensForCompletion) | ||
llmEndpointParams = try container.decodeIfPresent(AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi.self, forKey: .llmEndpointParams) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encodeIfPresent(model, forKey: .model) | ||
try container.encodeIfPresent(systemMessage, forKey: .systemMessage) | ||
try container.encodeIfPresent(promptTemplate, forKey: .promptTemplate) | ||
try container.encodeIfPresent(numTokensForCompletion, forKey: .numTokensForCompletion) | ||
try container.encodeIfPresent(llmEndpointParams, forKey: .llmEndpointParams) | ||
} | ||
|
||
} |
Oops, something went wrong.