Program Listing for File llm_context.hpp

(Latest Version)

Return to documentation for file (morpheus/_lib/include/morpheus/llm/llm_context.hpp)


/* * SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "morpheus/export.h" #include "morpheus/llm/fwd.hpp" // for ControlMessage #include "morpheus/llm/input_map.hpp" #include "morpheus/llm/llm_task.hpp" #include <mrc/types.hpp> #include <pymrc/utilities/json_values.hpp> #include <memory> #include <string> #include <vector> namespace morpheus::llm { struct LLMContextState { LLMTask task; std::shared_ptr<ControlMessage> message; }; class MORPHEUS_EXPORT LLMContext : public std::enable_shared_from_this<LLMContext> { public: LLMContext(); LLMContext(LLMTask task, std::shared_ptr<ControlMessage> message); LLMContext(std::shared_ptr<LLMContext> parent, std::string name, input_mappings_t inputs); ~LLMContext(); std::shared_ptr<LLMContext> parent() const; const std::string& name() const; const input_mappings_t& input_map() const; const LLMTask& task() const; std::shared_ptr<ControlMessage>& message() const; const mrc::pymrc::JSONValues& all_outputs() const; std::string full_name() const; std::shared_ptr<LLMContext> push(std::string name, input_mappings_t inputs); void pop(); mrc::pymrc::JSONValues get_input() const; mrc::pymrc::JSONValues get_input(const std::string& node_name) const; mrc::pymrc::JSONValues get_inputs() const; void set_output(mrc::pymrc::JSONValues&& outputs); void set_output(const std::string& output_name, mrc::pymrc::JSONValues&& output); void set_output_names(std::vector<std::string> output_names); void outputs_complete(); const mrc::pymrc::JSONValues& view_outputs() const; private: input_mappings_t::const_iterator find_input(const std::string& node_name, bool throw_if_not_found = true) const; std::shared_ptr<LLMContext> m_parent{nullptr}; std::string m_name; input_mappings_t m_inputs; std::vector<std::string> m_output_names; // Names of keys to be used as the output. Empty means use all keys std::shared_ptr<LLMContextState> m_state; mrc::pymrc::JSONValues m_outputs; mrc::Promise<void> m_outputs_promise; mrc::SharedFuture<void> m_outputs_future; }; } // namespace morpheus::llm

© Copyright 2024, NVIDIA. Last updated on Jul 8, 2024.