Skip to content

Commit 4b493ff

Browse files
committed
fix: change unique_ptr with optional, ref #17
1 parent 18cafe8 commit 4b493ff

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

code/ac/llama/Instance.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ void Instance::warmup() {
117117
}
118118

119119
Session& Instance::startSession(const Session::InitParams params) {
120-
if (m_session) {
120+
if (m_session.has_value()) {
121121
throw_ex{} << "Session is already started. Stop it to start a new one.";
122122
}
123123

124-
m_session.reset(new Session(*this, m_lctx.get(), params));
124+
m_session.emplace(*this, m_lctx.get(), params);
125125
return *m_session;
126126
}
127127

128+
void Instance::stopSession() noexcept {
129+
m_session.reset();
130+
}
131+
128132
} // namespace ac::llama

code/ac/llama/Instance.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AC_LLAMA_EXPORT Instance {
3535

3636
// only one session per instance can be active at a time
3737
Session& startSession(const Session::InitParams params);
38-
void stopSession() noexcept { m_session.reset(); }
38+
void stopSession() noexcept;
3939

4040
const Model& model() const noexcept { return m_model; }
4141
Sampler& sampler() noexcept { return m_sampler; }
@@ -44,7 +44,7 @@ class AC_LLAMA_EXPORT Instance {
4444
Model& m_model;
4545
Sampler m_sampler;
4646
astl::c_unique_ptr<llama_context> m_lctx;
47-
std::unique_ptr<Session> m_session;
47+
std::optional<Session> m_session;
4848
};
4949

5050
} // namespace ac::llama

0 commit comments

Comments
 (0)