llama_ros: llama.cpp for ROS 2
Loading...
Searching...
No Matches
llava.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2024 Miguel Ángel González Santamarta
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef LLAVA_ROS__LLAVA_HPP
24#define LLAVA_ROS__LLAVA_HPP
25
26#include <functional>
27#include <memory>
28#include <mutex>
29#include <string>
30#include <vector>
31
32#include "clip.h"
33#include "common.h"
34#include "llava.h"
35
36#include "llama_ros/llama.hpp"
37
38namespace llava_ros {
39
41 std::string image_text = "";
42 std::string image_prefix = "";
43 std::string image_suffix = "";
44};
45
46class Llava : public llama_ros::Llama {
47
48public:
49 Llava(const struct common_params &params,
50 const struct LlavaParams &llava_params, std::string system_prompt = "");
51 ~Llava();
52
53 void reset() override;
54 bool load_image(std::string base64_str);
55 struct llava_image_embed *
56 base64_image_to_embed(const std::string &base64_str);
57
58protected:
59 void load_prompt(const std::string &input_prompt, bool add_pfx,
60 bool add_sfx) override;
61 bool eval_image(struct llava_image_embed *image_embed);
62 bool eval_prompt() override;
63 bool eval(struct llama_batch batch) override;
64
65 struct llava_image_embed *image_embed;
66 struct clip_ctx *ctx_clip;
68
69private:
70 void free_image();
73};
74
75} // namespace llava_ros
76
77#endif
Definition llama.hpp:169
std::string system_prompt
Definition llama.hpp:257
struct common_params params
Definition llama.hpp:245
struct LlavaParams llava_params
Definition llava.hpp:67
bool eval(struct llama_batch batch) override
Definition llava.cpp:264
bool eval_prompt() override
Definition llava.cpp:230
struct llava_image_embed * image_embed
Definition llava.hpp:65
bool load_image(std::string base64_str)
Definition llava.cpp:111
bool eval_image(struct llava_image_embed *image_embed)
Definition llava.cpp:157
void reset() override
Definition llava.cpp:54
void free_image()
Definition llava.cpp:126
struct clip_ctx * ctx_clip
Definition llava.hpp:66
~Llava()
Definition llava.cpp:49
int st_pos_id
Definition llava.hpp:72
void load_prompt(const std::string &input_prompt, bool add_pfx, bool add_sfx) override
Definition llava.cpp:64
Llava(const struct common_params &params, const struct LlavaParams &llava_params, std::string system_prompt="")
Definition llava.cpp:35
struct llava_image_embed * base64_image_to_embed(const std::string &base64_str)
Definition llava.cpp:134
int image_pose
Definition llava.hpp:71
Definition llava.hpp:38
Definition llava.hpp:40
std::string image_suffix
Definition llava.hpp:43
std::string image_prefix
Definition llava.hpp:42
std::string image_text
Definition llava.hpp:41