mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-83154 AI: Added model to the response
Not all responses will return the model used. When possible, we can fallback to Moodle's stored config value.
This commit is contained in:
parent
2baf81a243
commit
b7d9100445
@ -37,6 +37,7 @@ abstract class response_base {
|
||||
* @param string $actionname The name of the action that was processed.
|
||||
* @param int $errorcode Error code. Must exist if success is false.
|
||||
* @param string $errormessage Error message. Must exist if success is false
|
||||
* @param string $model The model used to generate the response.
|
||||
*/
|
||||
public function __construct(
|
||||
/** @var bool The success status of the action. */
|
||||
@ -47,6 +48,8 @@ abstract class response_base {
|
||||
private int $errorcode = 0,
|
||||
/** @var string Error message. Must exist if status is error */
|
||||
private string $errormessage = '',
|
||||
/** @var string The model used to generate the response (if available). */
|
||||
protected ?string $model = null,
|
||||
|
||||
) {
|
||||
$this->timecreated = \core\di::get(\core\clock::class)->time();
|
||||
@ -113,4 +116,13 @@ abstract class response_base {
|
||||
public function get_errormessage(): string {
|
||||
return $this->errormessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model used to generate the response (if available).
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function get_model_used(): ?string {
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ class response_generate_image extends response_base {
|
||||
$this->draftfile = $response['draftfile'] ?? null;
|
||||
$this->revisedprompt = $response['revisedprompt'] ?? null;
|
||||
$this->sourceurl = $response['sourceurl'] ?? null;
|
||||
$this->model = $response['model'] ?? null;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
@ -68,6 +69,7 @@ class response_generate_image extends response_base {
|
||||
'draftfile' => $this->draftfile,
|
||||
'revisedprompt' => $this->revisedprompt,
|
||||
'sourceurl' => $this->sourceurl,
|
||||
'model' => $this->model,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ class response_generate_text extends response_base {
|
||||
$this->finishreason = $response['finishreason'] ?? null;
|
||||
$this->prompttokens = $response['prompttokens'] ?? null;
|
||||
$this->completiontokens = $response['completiontokens'] ?? null;
|
||||
$this->model = $response['model'] ?? null;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
@ -83,6 +84,7 @@ class response_generate_text extends response_base {
|
||||
'finishreason' => $this->finishreason,
|
||||
'prompttokens' => $this->prompttokens,
|
||||
'completiontokens' => $this->completiontokens,
|
||||
'model' => $this->model,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ class response_summarise_text extends response_base {
|
||||
$this->finishreason = $response['finishreason'] ?? null;
|
||||
$this->prompttokens = $response['prompttokens'] ?? null;
|
||||
$this->completiontokens = $response['completiontokens'] ?? null;
|
||||
$this->model = $response['model'] ?? null;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
@ -83,6 +84,7 @@ class response_summarise_text extends response_base {
|
||||
'finishreason' => $this->finishreason,
|
||||
'prompttokens' => $this->prompttokens,
|
||||
'completiontokens' => $this->completiontokens,
|
||||
'model' => $this->model,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +174,7 @@ class manager {
|
||||
'errormessage' => $response->get_errormessage(),
|
||||
'timecreated' => $action->get_configuration('timecreated'),
|
||||
'timecompleted' => $response->get_timecreated(),
|
||||
'model' => $response->get_model_used(),
|
||||
];
|
||||
|
||||
try {
|
||||
|
@ -106,6 +106,7 @@ class process_generate_text extends abstract_processor {
|
||||
'finishreason' => $bodyobj->choices[0]->finish_reason,
|
||||
'prompttokens' => $bodyobj->usage->prompt_tokens,
|
||||
'completiontokens' => $bodyobj->usage->completion_tokens,
|
||||
'model' => $bodyobj->model,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ class process_generate_image extends abstract_processor {
|
||||
'success' => true,
|
||||
'sourceurl' => $bodyobj->data[0]->url,
|
||||
'revisedprompt' => $bodyobj->data[0]->revised_prompt,
|
||||
'model' => $this->get_model(), // There is no model in the response, use config.
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,7 @@ class process_generate_text extends abstract_processor {
|
||||
'finishreason' => $bodyobj->choices[0]->finish_reason,
|
||||
'prompttokens' => $bodyobj->usage->prompt_tokens,
|
||||
'completiontokens' => $bodyobj->usage->completion_tokens,
|
||||
'model' => $bodyobj->model ?? $this->get_model(), // Fallback to config model.
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user