-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:janhq/nitro into feat/model-sources
- Loading branch information
Showing
19 changed files
with
1,047 additions
and
21 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
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,71 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "common/json_serializable.h" | ||
|
||
namespace OpenAi { | ||
/** | ||
* The File object represents a document that has been uploaded to OpenAI. | ||
*/ | ||
struct File : public JsonSerializable { | ||
/** | ||
* The file identifier, which can be referenced in the API endpoints. | ||
*/ | ||
std::string id; | ||
|
||
/** | ||
* The object type, which is always file. | ||
*/ | ||
std::string object = "file"; | ||
|
||
/** | ||
* The size of the file, in bytes. | ||
*/ | ||
uint64_t bytes; | ||
|
||
/** | ||
* The Unix timestamp (in seconds) for when the file was created. | ||
*/ | ||
uint32_t created_at; | ||
|
||
/** | ||
* The name of the file. | ||
*/ | ||
std::string filename; | ||
|
||
/** | ||
* The intended purpose of the file. Supported values are assistants, | ||
* assistants_output, batch, batch_output, fine-tune, fine-tune-results | ||
* and vision. | ||
*/ | ||
std::string purpose; | ||
|
||
~File() = default; | ||
|
||
static cpp::result<File, std::string> FromJson(const Json::Value& json) { | ||
File file; | ||
|
||
file.id = std::move(json["id"].asString()); | ||
file.object = "file"; | ||
file.bytes = json["bytes"].asUInt64(); | ||
file.created_at = json["created_at"].asUInt(); | ||
file.filename = std::move(json["filename"].asString()); | ||
file.purpose = std::move(json["purpose"].asString()); | ||
|
||
return file; | ||
} | ||
|
||
cpp::result<Json::Value, std::string> ToJson() { | ||
Json::Value root; | ||
|
||
root["id"] = id; | ||
root["object"] = object; | ||
root["bytes"] = bytes; | ||
root["created_at"] = created_at; | ||
root["filename"] = filename; | ||
root["purpose"] = purpose; | ||
|
||
return root; | ||
} | ||
}; | ||
} // namespace OpenAi |
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,29 @@ | ||
#pragma once | ||
|
||
#include "common/file.h" | ||
#include "utils/result.hpp" | ||
|
||
class FileRepository { | ||
public: | ||
virtual cpp::result<void, std::string> StoreFile(OpenAi::File& file_metadata, | ||
const char* content, | ||
uint64_t length) = 0; | ||
|
||
virtual cpp::result<std::vector<OpenAi::File>, std::string> ListFiles( | ||
const std::string& purpose, uint8_t limit, const std::string& order, | ||
const std::string& after) const = 0; | ||
|
||
virtual cpp::result<OpenAi::File, std::string> RetrieveFile( | ||
const std::string file_id) const = 0; | ||
|
||
virtual cpp::result<std::pair<std::unique_ptr<char[]>, size_t>, std::string> | ||
RetrieveFileContent(const std::string& file_id) const = 0; | ||
|
||
virtual cpp::result<std::pair<std::unique_ptr<char[]>, size_t>, std::string> | ||
RetrieveFileContentByPath(const std::string& path) const = 0; | ||
|
||
virtual cpp::result<void, std::string> DeleteFileLocal( | ||
const std::string& file_id) = 0; | ||
|
||
virtual ~FileRepository() = default; | ||
}; |
Oops, something went wrong.