Skip to content

Commit

Permalink
Comments & code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
clpetersonucf committed Sep 18, 2024
1 parent 7f63e1f commit 20a6ae4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions fuel/app/classes/materia/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,19 @@ static public function question_set_generate($inst_id, $widget_id, $topic, $incl
}
}

/**
* Endpoint to facilitate AI text generation for widgets
*
* @param string $prompt The prompt to generate.
* @return array An array to be passed back to the widget containing the response string
*/
static public function widget_prompt_generate($prompt)
{
// verify eligibility
if ( ! Widget_Question_Generator::is_enabled()) return Msg::failure();
if (\Service_User::verify_session() !== true) return Msg::no_login();

// prompt generation & response handling
$result = Widget_Question_Generator::generate_from_prompt($prompt);
if ( ! $result instanceof Msg && is_string($result))
{
Expand Down
7 changes: 6 additions & 1 deletion fuel/app/classes/materia/widget/question/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ public static function query($prompt, $format='json')
return $client->chat()->create($params);
}

/**
* Generates a text response based on the provided prompt.
*
* @param string $prompt The prompt to send to the LLM.
* @return string The generated response.
*/
static public function generate_from_prompt($prompt)
{
if ( ! self::is_enabled()) return Msg::failure('Question generation is not enabled.');

if (empty($prompt) || strlen($prompt) > 10000) return Msg::invalid_input('Prompt text length invalid.');

try
Expand Down

0 comments on commit 20a6ae4

Please sign in to comment.