|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <string> |
| 4 | +#include "common/assistant_tool.h" |
| 5 | +#include "common/thread_tool_resources.h" |
| 6 | +#include "common/variant_map.h" |
| 7 | +#include "utils/result.hpp" |
| 8 | + |
| 9 | +namespace OpenAi { |
| 10 | +// Deprecated. After jan's migration, we should remove this struct |
| 11 | +struct JanAssistant : JsonSerializable { |
| 12 | + std::string id; |
| 13 | + |
| 14 | + std::string name; |
| 15 | + |
| 16 | + std::string object = "assistant"; |
| 17 | + |
| 18 | + uint32_t created_at; |
| 19 | + |
| 20 | + Json::Value tools; |
| 21 | + |
| 22 | + Json::Value model; |
| 23 | + |
| 24 | + std::string instructions; |
| 25 | + |
| 26 | + ~JanAssistant() = default; |
| 27 | + |
| 28 | + cpp::result<Json::Value, std::string> ToJson() override { |
| 29 | + try { |
| 30 | + Json::Value json; |
| 31 | + |
| 32 | + json["id"] = id; |
| 33 | + json["name"] = name; |
| 34 | + json["object"] = object; |
| 35 | + json["created_at"] = created_at; |
| 36 | + |
| 37 | + json["tools"] = tools; |
| 38 | + json["model"] = model; |
| 39 | + json["instructions"] = instructions; |
| 40 | + |
| 41 | + return json; |
| 42 | + } catch (const std::exception& e) { |
| 43 | + return cpp::fail(std::string("ToJson failed: ") + e.what()); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + static cpp::result<JanAssistant, std::string> FromJson(Json::Value&& json) { |
| 48 | + if (json.empty()) { |
| 49 | + return cpp::fail("Empty JSON"); |
| 50 | + } |
| 51 | + |
| 52 | + JanAssistant assistant; |
| 53 | + if (json.isMember("assistant_id")) { |
| 54 | + assistant.id = json["assistant_id"].asString(); |
| 55 | + } else { |
| 56 | + assistant.id = json["id"].asString(); |
| 57 | + } |
| 58 | + |
| 59 | + if (json.isMember("assistant_name")) { |
| 60 | + assistant.name = json["assistant_name"].asString(); |
| 61 | + } else { |
| 62 | + assistant.name = json["name"].asString(); |
| 63 | + } |
| 64 | + assistant.object = "assistant"; |
| 65 | + assistant.created_at = 0; // Jan does not have this |
| 66 | + if (json.isMember("tools")) { |
| 67 | + assistant.tools = json["tools"]; |
| 68 | + } |
| 69 | + if (json.isMember("model")) { |
| 70 | + assistant.model = json["model"]; |
| 71 | + } |
| 72 | + assistant.instructions = json["instructions"].asString(); |
| 73 | + |
| 74 | + return assistant; |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +struct Assistant { |
| 79 | + /** |
| 80 | + * The identifier, which can be referenced in API endpoints. |
| 81 | + */ |
| 82 | + std::string id; |
| 83 | + |
| 84 | + /** |
| 85 | + * The object type, which is always assistant. |
| 86 | + */ |
| 87 | + std::string object = "assistant"; |
| 88 | + |
| 89 | + /** |
| 90 | + * The Unix timestamp (in seconds) for when the assistant was created. |
| 91 | + */ |
| 92 | + uint64_t created_at; |
| 93 | + |
| 94 | + /** |
| 95 | + * The name of the assistant. The maximum length is 256 characters. |
| 96 | + */ |
| 97 | + std::optional<std::string> name; |
| 98 | + |
| 99 | + /** |
| 100 | + * The description of the assistant. The maximum length is 512 characters. |
| 101 | + */ |
| 102 | + std::optional<std::string> description; |
| 103 | + |
| 104 | + /** |
| 105 | + * ID of the model to use. You can use the List models API to see all of |
| 106 | + * your available models, or see our Model overview for descriptions of them. |
| 107 | + */ |
| 108 | + std::string model; |
| 109 | + |
| 110 | + /** |
| 111 | + * The system instructions that the assistant uses. The maximum length is |
| 112 | + * 256,000 characters. |
| 113 | + */ |
| 114 | + std::optional<std::string> instructions; |
| 115 | + |
| 116 | + /** |
| 117 | + * A list of tool enabled on the assistant. There can be a maximum of 128 |
| 118 | + * tools per assistant. Tools can be of types code_interpreter, file_search, |
| 119 | + * or function. |
| 120 | + */ |
| 121 | + std::vector<std::unique_ptr<AssistantTool>> tools; |
| 122 | + |
| 123 | + /** |
| 124 | + * A set of resources that are used by the assistant's tools. The resources |
| 125 | + * are specific to the type of tool. For example, the code_interpreter tool |
| 126 | + * requires a list of file IDs, while the file_search tool requires a list |
| 127 | + * of vector store IDs. |
| 128 | + */ |
| 129 | + std::optional<std::variant<ThreadCodeInterpreter, ThreadFileSearch>> |
| 130 | + tool_resources; |
| 131 | + |
| 132 | + /** |
| 133 | + * Set of 16 key-value pairs that can be attached to an object. This can be |
| 134 | + * useful for storing additional information about the object in a structured |
| 135 | + * format. Keys can be a maximum of 64 characters long and values can be a |
| 136 | + * maximum of 512 characters long. |
| 137 | + */ |
| 138 | + Cortex::VariantMap metadata; |
| 139 | + |
| 140 | + /** |
| 141 | + * What sampling temperature to use, between 0 and 2. Higher values like |
| 142 | + * 0.8 will make the output more random, while lower values like 0.2 will |
| 143 | + * make it more focused and deterministic. |
| 144 | + */ |
| 145 | + std::optional<float> temperature; |
| 146 | + |
| 147 | + /** |
| 148 | + * An alternative to sampling with temperature, called nucleus sampling, |
| 149 | + * where the model considers the results of the tokens with top_p |
| 150 | + * probability mass. So 0.1 means only the tokens comprising the top 10% |
| 151 | + * probability mass are considered. |
| 152 | + * |
| 153 | + * We generally recommend altering this or temperature but not both. |
| 154 | + */ |
| 155 | + std::optional<float> top_p; |
| 156 | +}; |
| 157 | +} // namespace OpenAi |
0 commit comments