App-Chit

 view release on metacpan or  search on metacpan

lib/App/Chit/Command/chat.pm  view on Meta::CPAN

	unshift @log, { role => 'system', content => $chit->{role} };
	push @log, { role => 'user', content => $prompt };
	
	my $temperature = $opt->{temperature} // $chit->{temperature};
	
	my $gpt = App::Chit::Util::chatgpt( $chit );
	my $response = $gpt->chat( \@log, $temperature );
	$spin->auto_done if $spin;
	if ( defined $response ) {
		chomp $response;
		say $response;
		push @{ $chit->{chat} //= [] },
			{ role => 'user',      content => $prompt },
			{ role => 'assistant', content => $response };
	}
	else {
		croak( "Error: " . $gpt->error );
	}
	
	App::Chit::Util::save_chit( $dir, $chit );
}

lib/App/Chit/Command/init.pm  view on Meta::CPAN

		$chit = {};
	}
	elsif ( $opt->{autofork} ) {
		$chit = App::Chit::Util::load_chit( App::Chit::Util::find_chit_dir() );
	}
	elsif ( $opt->{fork} ) {
		$chit = App::Chit::Util::load_chit( App::Chit::Util::find_chit_dir( $opt->{fork} ) );
	}
	App::Chit::Util::save_chit( $dir, $chit );
	
	say "ok";
}

1;

lib/App/Chit/Command/maxhistory.pm  view on Meta::CPAN

		[ "set=i",      "set maximum chat history length" ],
	);
}

sub execute ( $self, $opt, $args ) {
	my $dir = App::Chit::Util::find_chit_dir()
		or $self->usage_error("need to initialize chit first");
	my $chit = App::Chit::Util::load_chit( $dir );
	
	if ( length $opt->{set} ) {
		say "Previous maximum history length:   ", int( 0 + $chit->{history} );
		say "Setting maximum history length to: ", $opt->{set};
		$chit->{history} = $opt->{set};
	}
	else {
		say int( 0 + $chit->{history} );
	}
	
	App::Chit::Util::save_chit( $dir, $chit );
}

1;

lib/App/Chit/Command/model.pm  view on Meta::CPAN

		[ "set=s",      "set model (see https://platform.openai.com/docs/models)" ],
	);
}

sub execute ( $self, $opt, $args ) {
	my $dir = App::Chit::Util::find_chit_dir()
		or $self->usage_error("need to initialize chit first");
	my $chit = App::Chit::Util::load_chit( $dir );
	
	if ( $opt->{set} ) {
		say "Previous model:   ", $chit->{model};
		say "Setting model to: ", $opt->{set};
		$chit->{model} = $opt->{set};
	}
	else {
		say $chit->{model};
	}
	
	App::Chit::Util::save_chit( $dir, $chit );
}

1;

lib/App/Chit/Command/role.pm  view on Meta::CPAN

		[ "set=s",      "set role" ],
	);
}

sub execute ( $self, $opt, $args ) {
	my $dir = App::Chit::Util::find_chit_dir()
		or $self->usage_error("need to initialize chit first");
	my $chit = App::Chit::Util::load_chit( $dir );
	
	if ( $opt->{set} ) {
		say "Previous role:   ", $chit->{role};
		say "Setting role to: ", $opt->{set};
		$chit->{role} = $opt->{set};
	}
	else {
		say $chit->{role};
	}
	
	App::Chit::Util::save_chit( $dir, $chit );
}

1;

lib/App/Chit/Command/temperature.pm  view on Meta::CPAN

		$self->usage_error( "too cold" ) if $opt->{set} < 0;
	}
}

sub execute ( $self, $opt, $args ) {
	my $dir = App::Chit::Util::find_chit_dir()
		or $self->usage_error("need to initialize chit first");
	my $chit = App::Chit::Util::load_chit( $dir );
	
	if ( $opt->{set} ) {
		say "Previous temperature:   ", sprintf( '%.03f', $chit->{temperature} );
		say "Setting temperature to: ", $opt->{set};
		$chit->{temperature} = $opt->{set};
	}
	else {
		say sprintf( '%.03f', $chit->{temperature} );
	}
	
	App::Chit::Util::save_chit( $dir, $chit );
}

1;



( run in 2.050 seconds using v1.01-cache-2.11-cpan-d7a12ab2c7f )