@@ -36,15 +36,15 @@ class connector extends \local_ai_manager\base_connector {
3636 #[\Override]
3737 public function get_models_by_purpose (): array {
3838 $ chatgptmodels =
39- ['gpt-3.5-turbo ' , 'gpt-4-turbo ' , 'gpt-4o ' , 'gpt-4o-mini ' , 'o1 ' , 'o1-mini ' , 'o3 ' , 'o3-mini ' , 'o4-mini ' ];
39+ ['gpt-3.5-turbo ' , 'gpt-4-turbo ' , 'gpt-4o ' , 'gpt-4o-mini ' , 'o1 ' , 'o1-mini ' , 'o3 ' , 'o3-mini ' , 'o4-mini ' , ' text-embedding-3-small ' , ' text-embedding-3-large ' ];
4040 return [
4141 'chat ' => $ chatgptmodels ,
4242 'feedback ' => $ chatgptmodels ,
4343 'singleprompt ' => $ chatgptmodels ,
4444 'translate ' => $ chatgptmodels ,
4545 'itt ' => ['gpt-4-turbo ' , 'gpt-4o ' , 'gpt-4o-mini ' , 'o1 ' , 'o3 ' , 'o4-mini ' ],
4646 'questiongeneration ' => $ chatgptmodels ,
47- 'embedding ' => $ chatgptmodels , // ['text-embedding-3-small', 'text-embedding-3-large'],
47+ 'embedding ' =>['text-embedding-3-small ' , 'text-embedding-3-large ' ],
4848 'rag ' => $ chatgptmodels ,
4949
5050 ];
@@ -63,7 +63,14 @@ public function execute_prompt_completion(StreamInterface $result, request_optio
6363 */
6464 // phpcs:enable moodle.Commenting.TodoComment.MissingInfoInline
6565 $ content = json_decode ($ result ->getContents (), true );
66-
66+ $ purpose = $ requestoptions ->get_purpose ()->get_plugin_name ();
67+ if ($ purpose === 'embedding ' ) {
68+ return prompt_response::create_from_result (
69+ $ content ['model ' ],
70+ new usage (0 , 0 , 0 ),
71+ implode (", " , $ content ['data ' ][0 ]['embedding ' ])
72+ );
73+ }
6774 return prompt_response::create_from_result (
6875 $ content ['model ' ],
6976 new usage (
@@ -77,6 +84,27 @@ public function execute_prompt_completion(StreamInterface $result, request_optio
7784 #[\Override]
7885 public function get_prompt_data (string $ prompttext , request_options $ requestoptions ): array {
7986 $ options = $ requestoptions ->get_options ();
87+ $ purpose = $ requestoptions ->get_purpose ()->get_plugin_name ();
88+ if ($ purpose === 'embedding ' ) {
89+ return $ this ->get_embedding_prompt_data ($ prompttext , $ options );
90+ }
91+ return $ this ->get_chat_prompt_data ($ prompttext , $ options );
92+ }
93+ /**
94+ * Returns the prompt data for an embedding request.
95+ * !! THIS IS BREAKING A DEGREE OF ENCAPSULATION BY NEEDING TO KNOW ABOUT THE PURPOSE !!
96+ */
97+ protected function get_embedding_prompt_data (string $ prompttext , array $ options ): array {
98+ return [
99+ 'input ' => $ prompttext ,
100+ 'model ' => $ this ->get_instance ()->get_model (),
101+ 'encoding_format ' => 'float ' ,
102+ ];
103+ }
104+ /**
105+ * This is the "original" chat prompt data function, which is used for all purposes except embedding.
106+ */
107+ protected function get_chat_prompt_data (string $ prompttext , array $ options ): array {
80108 $ messages = [];
81109 if (array_key_exists ('conversationcontext ' , $ options )) {
82110 foreach ($ options ['conversationcontext ' ] as $ message ) {
0 commit comments