Copy as Markdown
Other Tools
/* THIS FILE IS AUTOGENERATED FROM LlamaRunner.webidl BY Codegen.py - DO NOT EDIT */
#ifndef DOM_LLAMARUNNERBINDING_H_
#define DOM_LLAMARUNNERBINDING_H_
#include "js/CallAndConstruct.h"
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/Span.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrototypeList.h"
namespace mozilla {
namespace dom {
struct LlamaChatMessage;
struct LlamaChatMessageAtoms;
struct LlamaChatOptionsAtoms;
struct LlamaChatResponseAtoms;
struct LlamaContextOptions;
struct LlamaContextOptionsAtoms;
struct LlamaDeTokenizationOptions;
struct LlamaDeTokenizationOptionsAtoms;
struct LlamaFormatChatOptionsAtoms;
struct LlamaLogitBias;
struct LlamaLogitBiasAtoms;
struct LlamaModelOptionsAtoms;
class LlamaRunner;
struct LlamaSamplerConfig;
struct LlamaSamplerConfigAtoms;
struct LlamaTokenizationOptions;
struct LlamaTokenizationOptionsAtoms;
struct NativePropertyHooks;
class ProtoAndIfaceCache;
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
enum class LlamaChatPhase : uint8_t {
Prompt,
Generation,
};
namespace binding_detail {
template <> struct EnumStrings<LlamaChatPhase> {
static constexpr nsLiteralCString Values[2] {
"prompt"_ns,
"generation"_ns,
};
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, LlamaChatPhase aArgument, JS::MutableHandle<JS::Value> aValue);
enum class LlamaKVCacheDtype : uint8_t {
F32,
F16,
Q8_0,
Q5_1,
Q5_0,
Q4_1,
Q4_0,
};
namespace binding_detail {
template <> struct EnumStrings<LlamaKVCacheDtype> {
static constexpr nsLiteralCString Values[7] {
"f32"_ns,
"f16"_ns,
"q8_0"_ns,
"q5_1"_ns,
"q5_0"_ns,
"q4_1"_ns,
"q4_0"_ns,
};
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, LlamaKVCacheDtype aArgument, JS::MutableHandle<JS::Value> aValue);
enum class LlamaSamplerType : uint8_t {
Logit_bias,
Dry,
Top_k,
Top_p,
Top_n_sigma,
Min_p,
Xtc,
Typical,
Temperature,
Temperature_ext,
Infill,
Penalties,
Mirostat,
Dist,
};
namespace binding_detail {
template <> struct EnumStrings<LlamaSamplerType> {
static constexpr nsLiteralCString Values[14] {
"logit-bias"_ns,
"dry"_ns,
"top-k"_ns,
"top-p"_ns,
"top-n-sigma"_ns,
"min-p"_ns,
"xtc"_ns,
"typical"_ns,
"temperature"_ns,
"temperature-ext"_ns,
"infill"_ns,
"penalties"_ns,
"mirostat"_ns,
"dist"_ns,
};
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, LlamaSamplerType aArgument, JS::MutableHandle<JS::Value> aValue);
struct LlamaChatMessage : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR nsCString mContent;
MOZ_INIT_OUTSIDE_CTOR nsCString mRole;
LlamaChatMessage();
explicit inline LlamaChatMessage(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaChatMessage(LlamaChatMessage&& aOther) = default;
explicit inline LlamaChatMessage(const LlamaChatMessage& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaChatMessage&
operator=(const LlamaChatMessage& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaChatMessageAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaChatMessage : public LlamaChatMessage
{
inline FastLlamaChatMessage()
: LlamaChatMessage(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaChatResponse : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR bool mIsPhaseCompleted;
MOZ_INIT_OUTSIDE_CTOR LlamaChatPhase mPhase;
MOZ_INIT_OUTSIDE_CTOR nsCString mPiece;
MOZ_INIT_OUTSIDE_CTOR Sequence<int32_t> mTokens;
LlamaChatResponse();
explicit inline LlamaChatResponse(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaChatResponse(LlamaChatResponse&& aOther) = default;
explicit inline LlamaChatResponse(const LlamaChatResponse& aOther)
{
*this = aOther;
}
bool
Init(const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const;
void
TraceDictionary(JSTracer* trc);
LlamaChatResponse&
operator=(const LlamaChatResponse& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaChatResponseAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaChatResponse : public LlamaChatResponse
{
inline FastLlamaChatResponse()
: LlamaChatResponse(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaContextOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR bool mFlashAttn;
MOZ_INIT_OUTSIDE_CTOR LlamaKVCacheDtype mKCacheDtype;
MOZ_INIT_OUTSIDE_CTOR uint32_t mNBatch;
MOZ_INIT_OUTSIDE_CTOR uint32_t mNCtx;
MOZ_INIT_OUTSIDE_CTOR uint32_t mNSeqMax;
MOZ_INIT_OUTSIDE_CTOR int32_t mNThreads;
MOZ_INIT_OUTSIDE_CTOR int32_t mNThreadsBatch;
MOZ_INIT_OUTSIDE_CTOR uint32_t mNUbatch;
MOZ_INIT_OUTSIDE_CTOR bool mNoPerf;
MOZ_INIT_OUTSIDE_CTOR bool mOffloadKqv;
MOZ_INIT_OUTSIDE_CTOR bool mOpOffload;
MOZ_INIT_OUTSIDE_CTOR bool mSwaFull;
MOZ_INIT_OUTSIDE_CTOR LlamaKVCacheDtype mVCacheDtype;
LlamaContextOptions();
explicit inline LlamaContextOptions(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaContextOptions(LlamaContextOptions&& aOther) = default;
explicit inline LlamaContextOptions(const LlamaContextOptions& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaContextOptions&
operator=(const LlamaContextOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaContextOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaContextOptions : public LlamaContextOptions
{
inline FastLlamaContextOptions()
: LlamaContextOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaDeTokenizationOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR int32_t mMaxCharsPerToken;
MOZ_INIT_OUTSIDE_CTOR bool mRenderSpecialTokens;
LlamaDeTokenizationOptions();
explicit inline LlamaDeTokenizationOptions(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaDeTokenizationOptions(LlamaDeTokenizationOptions&& aOther) = default;
explicit inline LlamaDeTokenizationOptions(const LlamaDeTokenizationOptions& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaDeTokenizationOptions&
operator=(const LlamaDeTokenizationOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaDeTokenizationOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaDeTokenizationOptions : public LlamaDeTokenizationOptions
{
inline FastLlamaDeTokenizationOptions()
: LlamaDeTokenizationOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaLogitBias : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR float mBias;
MOZ_INIT_OUTSIDE_CTOR int32_t mToken;
LlamaLogitBias();
explicit inline LlamaLogitBias(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaLogitBias(LlamaLogitBias&& aOther) = default;
explicit inline LlamaLogitBias(const LlamaLogitBias& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaLogitBias&
operator=(const LlamaLogitBias& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaLogitBiasAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaLogitBias : public LlamaLogitBias
{
inline FastLlamaLogitBias()
: LlamaLogitBias(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaTokenizationOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR bool mAddBosAndEos;
MOZ_INIT_OUTSIDE_CTOR bool mParseSpecilControlTokens;
LlamaTokenizationOptions();
explicit inline LlamaTokenizationOptions(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaTokenizationOptions(LlamaTokenizationOptions&& aOther) = default;
explicit inline LlamaTokenizationOptions(const LlamaTokenizationOptions& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaTokenizationOptions&
operator=(const LlamaTokenizationOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaTokenizationOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaTokenizationOptions : public LlamaTokenizationOptions
{
inline FastLlamaTokenizationOptions()
: LlamaTokenizationOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaFormatChatOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR bool mAddAssistant;
MOZ_INIT_OUTSIDE_CTOR Sequence<LlamaChatMessage> mMessages;
LlamaFormatChatOptions();
explicit inline LlamaFormatChatOptions(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaFormatChatOptions(LlamaFormatChatOptions&& aOther) = default;
explicit inline LlamaFormatChatOptions(const LlamaFormatChatOptions& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaFormatChatOptions&
operator=(const LlamaFormatChatOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaFormatChatOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaFormatChatOptions : public LlamaFormatChatOptions
{
inline FastLlamaFormatChatOptions()
: LlamaFormatChatOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaModelOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR bool mCheckTensors;
MOZ_INIT_OUTSIDE_CTOR LlamaContextOptions mContext;
MOZ_INIT_OUTSIDE_CTOR int32_t mNGpuLayers;
MOZ_INIT_OUTSIDE_CTOR bool mUseMlock;
MOZ_INIT_OUTSIDE_CTOR bool mUseMmap;
LlamaModelOptions();
explicit inline LlamaModelOptions(const FastDictionaryInitializer& )
: mContext(FastDictionaryInitializer())
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaModelOptions(LlamaModelOptions&& aOther) = default;
explicit inline LlamaModelOptions(const LlamaModelOptions& aOther)
: mContext(FastDictionaryInitializer())
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaModelOptions&
operator=(const LlamaModelOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaModelOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaModelOptions : public LlamaModelOptions
{
inline FastLlamaModelOptions()
: LlamaModelOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaSamplerConfig : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR int32_t mDryAllowedLength;
MOZ_INIT_OUTSIDE_CTOR float mDryBase;
MOZ_INIT_OUTSIDE_CTOR float mDryMultiplier;
MOZ_INIT_OUTSIDE_CTOR int32_t mDryPenaltyLastN;
MOZ_INIT_OUTSIDE_CTOR float mDynatempExponent;
MOZ_INIT_OUTSIDE_CTOR float mDynatempRange;
MOZ_INIT_OUTSIDE_CTOR Sequence<LlamaLogitBias> mLogitBias;
MOZ_INIT_OUTSIDE_CTOR int32_t mMinKeep;
MOZ_INIT_OUTSIDE_CTOR float mMinP;
MOZ_INIT_OUTSIDE_CTOR int32_t mMirostat;
MOZ_INIT_OUTSIDE_CTOR float mMirostatEta;
MOZ_INIT_OUTSIDE_CTOR float mMirostatTau;
MOZ_INIT_OUTSIDE_CTOR bool mNoPerf;
MOZ_INIT_OUTSIDE_CTOR float mPenaltyFreq;
MOZ_INIT_OUTSIDE_CTOR int32_t mPenaltyLastN;
MOZ_INIT_OUTSIDE_CTOR float mPenaltyPresent;
MOZ_INIT_OUTSIDE_CTOR float mPenaltyRepeat;
MOZ_INIT_OUTSIDE_CTOR Optional<uint32_t> mSeed;
MOZ_INIT_OUTSIDE_CTOR float mTemp;
MOZ_INIT_OUTSIDE_CTOR int32_t mTopK;
MOZ_INIT_OUTSIDE_CTOR float mTopNSigma;
MOZ_INIT_OUTSIDE_CTOR float mTopP;
MOZ_INIT_OUTSIDE_CTOR float mTypP;
MOZ_INIT_OUTSIDE_CTOR LlamaSamplerType mType;
MOZ_INIT_OUTSIDE_CTOR float mXtcProbability;
MOZ_INIT_OUTSIDE_CTOR float mXtcThreshold;
LlamaSamplerConfig();
explicit inline LlamaSamplerConfig(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaSamplerConfig(LlamaSamplerConfig&& aOther) = default;
explicit inline LlamaSamplerConfig(const LlamaSamplerConfig& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaSamplerConfig&
operator=(const LlamaSamplerConfig& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaSamplerConfigAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaSamplerConfig : public LlamaSamplerConfig
{
inline FastLlamaSamplerConfig()
: LlamaSamplerConfig(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
struct LlamaChatOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR LlamaDeTokenizationOptions mDeTokenizationOptions;
MOZ_INIT_OUTSIDE_CTOR int32_t mMaxGeneratedTokens;
MOZ_INIT_OUTSIDE_CTOR int32_t mMinOutputBufferSize;
MOZ_INIT_OUTSIDE_CTOR nsCString mPrompt;
MOZ_INIT_OUTSIDE_CTOR Sequence<LlamaSamplerConfig> mSamplers;
MOZ_INIT_OUTSIDE_CTOR bool mStopOnEndOfGenerationTokens;
MOZ_INIT_OUTSIDE_CTOR Sequence<int32_t> mStopTokens;
MOZ_INIT_OUTSIDE_CTOR LlamaTokenizationOptions mTokenizationOptions;
LlamaChatOptions();
explicit inline LlamaChatOptions(const FastDictionaryInitializer& )
: mDeTokenizationOptions(FastDictionaryInitializer()),
mTokenizationOptions(FastDictionaryInitializer())
{
// Do nothing here; this is used by our "Fast" subclass
}
LlamaChatOptions(LlamaChatOptions&& aOther) = default;
explicit inline LlamaChatOptions(const LlamaChatOptions& aOther)
: mDeTokenizationOptions(FastDictionaryInitializer()),
mTokenizationOptions(FastDictionaryInitializer())
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
LlamaChatOptions&
operator=(const LlamaChatOptions& aOther);
private:
static bool
InitIds(JSContext* cx, LlamaChatOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastLlamaChatOptions : public LlamaChatOptions
{
inline FastLlamaChatOptions()
: LlamaChatOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
namespace LlamaRunner_Binding {
typedef mozilla::dom::LlamaRunner NativeType;
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);
bool
Wrap(JSContext* aCx, mozilla::dom::LlamaRunner* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
template <class T>
inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> reflector(aCx);
return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, DefineInterfaceProperty aDefineOnGlobal);
JS::Handle<JSObject*>
GetConstructorObjectHandle(JSContext* aCx);
inline bool CreateAndDefineOnGlobal(JSContext* aCx)
{
// Get the interface or namespace object for this class. This will
// create the object as needed and always define the properties for
// it on the global. The caller should make sure the interface or
// namespace is exposed on the global before calling this.
return GetPerInterfaceObjectHandle(aCx, constructors::id::LlamaRunner,
&CreateInterfaceObjects,
DefineInterfaceProperty::Always);
}
} // namespace LlamaRunner_Binding
} // namespace dom
template <>
struct MaxContiguousEnumValue<dom::LlamaChatPhase>
{
static constexpr dom::LlamaChatPhase value = dom::LlamaChatPhase::Generation;
static_assert(static_cast<uint8_t>(dom::LlamaChatPhase::Prompt) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(std::size(dom::binding_detail::EnumStrings<dom::LlamaChatPhase>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
template <>
struct MaxContiguousEnumValue<dom::LlamaKVCacheDtype>
{
static constexpr dom::LlamaKVCacheDtype value = dom::LlamaKVCacheDtype::Q4_0;
static_assert(static_cast<uint8_t>(dom::LlamaKVCacheDtype::F32) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(std::size(dom::binding_detail::EnumStrings<dom::LlamaKVCacheDtype>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
template <>
struct MaxContiguousEnumValue<dom::LlamaSamplerType>
{
static constexpr dom::LlamaSamplerType value = dom::LlamaSamplerType::Dist;
static_assert(static_cast<uint8_t>(dom::LlamaSamplerType::Logit_bias) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(std::size(dom::binding_detail::EnumStrings<dom::LlamaSamplerType>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
} // namespace mozilla
#endif // DOM_LLAMARUNNERBINDING_H_