pub struct FunctionTable<T> {
function_list: Vec<Function>,
call_table: HashMap<String, Box<FuncBody<T>>>,
basic_context: Arc<BasicContext>,
}
Expand description
OpenAI function の管理テーブル。
BasicContext は標準で関数に渡されるコンテキスト情報で、 コンストラクタで初期化され、Self はそれへの参照を保持する。
T は追加のコンテキスト情報の型。 標準以外の関数を追加する場合に使用可能。 Self::call に渡したのものがそのまま関数に引き渡される。
Fields§
§function_list: Vec<Function>
OpenAI API に渡すためのリスト。
call_table: HashMap<String, Box<FuncBody<T>>>
関数名から Rust 関数へのマップ。
basic_context: Arc<BasicContext>
BasicContext への参照。
Implementations§
Source§impl<T: 'static> FunctionTable<T>
impl<T: 'static> FunctionTable<T>
pub fn new(ctrl: Control, storage_dir_name: Option<&str>) -> Self
pub fn basic_context(&self) -> &BasicContext
pub fn debug_mode(&self) -> bool
Sourcepub fn function_list(&self) -> &[Function]
pub fn function_list(&self) -> &[Function]
OpenAI API に渡すためのリストを取得する。
Sourcepub fn create_help(&self) -> String
pub fn create_help(&self) -> String
関数一覧のヘルプ文字列を生成する。
Sourcepub async fn call(&self, ctx: T, func_name: &str, args_json_str: &str) -> String
pub async fn call(&self, ctx: T, func_name: &str, args_json_str: &str) -> String
関数を呼び出す。
引数は json 文字列であり、OpenAI API からのデータをそのまま渡せる。 エラーも適切な文字列メッセージとして返す。
Sourceasync fn call_internal(
&self,
ctx: T,
func_name: &str,
args: &FuncArgs,
) -> Result<String>
async fn call_internal( &self, ctx: T, func_name: &str, args: &FuncArgs, ) -> Result<String>
Self::call の内部メイン処理。
Sourcepub fn register_function(
&mut self,
function: Function,
body: impl Fn(Arc<BasicContext>, T, &FuncArgs) -> FuncBodyAsync<'_> + Send + Sync + 'static,
)
pub fn register_function( &mut self, function: Function, body: impl Fn(Arc<BasicContext>, T, &FuncArgs) -> FuncBodyAsync<'_> + Send + Sync + 'static, )
関数を登録する。
Sourcepub fn register_basic_functions(&mut self)
pub fn register_basic_functions(&mut self)
basicfuncs 以下のすべての基本的な関数を登録する。
Auto Trait Implementations§
impl<T> Freeze for FunctionTable<T>
impl<T> !RefUnwindSafe for FunctionTable<T>
impl<T> Send for FunctionTable<T>
impl<T> Sync for FunctionTable<T>
impl<T> Unpin for FunctionTable<T>
impl<T> !UnwindSafe for FunctionTable<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more