@@ -117,6 +117,112 @@ def test_graphql_error_handling(self, mock_post: MagicMock) -> None:
117117 with self .assertRaises (DataSpaceAPIError ):
118118 self .client .get_by_id_graphql ("123" )
119119
120+ @patch .object (AIModelClient , "post" )
121+ def test_call_model (self , mock_post : MagicMock ) -> None :
122+ """Test calling an AI model."""
123+ mock_post .return_value = {
124+ "success" : True ,
125+ "output" : "Paris is the capital of France." ,
126+ "latency_ms" : 150 ,
127+ "provider" : "OpenAI" ,
128+ }
129+
130+ result = self .client .call_model (
131+ model_id = "123" ,
132+ input_text = "What is the capital of France?" ,
133+ parameters = {"temperature" : 0.7 , "max_tokens" : 100 },
134+ )
135+
136+ self .assertTrue (result ["success" ])
137+ self .assertEqual (result ["output" ], "Paris is the capital of France." )
138+ self .assertEqual (result ["latency_ms" ], 150 )
139+ mock_post .assert_called_once ()
140+
141+ @patch .object (AIModelClient , "post" )
142+ def test_call_model_async (self , mock_post : MagicMock ) -> None :
143+ """Test calling an AI model asynchronously."""
144+ mock_post .return_value = {
145+ "task_id" : "task-456" ,
146+ "status" : "PENDING" ,
147+ "created_at" : "2024-01-01T00:00:00Z" ,
148+ }
149+
150+ result = self .client .call_model_async (
151+ model_id = "123" ,
152+ input_text = "Generate a long document" ,
153+ parameters = {"max_tokens" : 2000 },
154+ )
155+
156+ self .assertEqual (result ["task_id" ], "task-456" )
157+ self .assertEqual (result ["status" ], "PENDING" )
158+ mock_post .assert_called_once ()
159+
160+ @patch .object (AIModelClient , "post" )
161+ def test_call_model_error (self , mock_post : MagicMock ) -> None :
162+ """Test AI model call with error."""
163+ mock_post .return_value = {
164+ "success" : False ,
165+ "error" : "Model not available" ,
166+ }
167+
168+ result = self .client .call_model (
169+ model_id = "123" ,
170+ input_text = "Test input" ,
171+ )
172+
173+ self .assertFalse (result ["success" ])
174+ self .assertEqual (result ["error" ], "Model not available" )
175+
176+ @patch .object (AIModelClient , "post" )
177+ def test_create_model (self , mock_post : MagicMock ) -> None :
178+ """Test creating an AI model."""
179+ mock_post .return_value = {
180+ "id" : "new-model-123" ,
181+ "displayName" : "New Model" ,
182+ "modelType" : "LLM" ,
183+ }
184+
185+ result = self .client .create (
186+ {
187+ "displayName" : "New Model" ,
188+ "modelType" : "LLM" ,
189+ "provider" : "OpenAI" ,
190+ }
191+ )
192+
193+ self .assertEqual (result ["id" ], "new-model-123" )
194+ self .assertEqual (result ["displayName" ], "New Model" )
195+ mock_post .assert_called_once ()
196+
197+ @patch .object (AIModelClient , "put" )
198+ def test_update_model (self , mock_put : MagicMock ) -> None :
199+ """Test updating an AI model."""
200+ mock_put .return_value = {
201+ "id" : "123" ,
202+ "displayName" : "Updated Model" ,
203+ "modelType" : "LLM" ,
204+ }
205+
206+ result = self .client .update (
207+ "123" ,
208+ {
209+ "displayName" : "Updated Model" ,
210+ },
211+ )
212+
213+ self .assertEqual (result ["displayName" ], "Updated Model" )
214+ mock_put .assert_called_once ()
215+
216+ @patch .object (AIModelClient , "delete" )
217+ def test_delete_model (self , mock_delete : MagicMock ) -> None :
218+ """Test deleting an AI model."""
219+ mock_delete .return_value = {"message" : "Model deleted successfully" }
220+
221+ result = self .client .delete_model ("123" )
222+
223+ self .assertEqual (result ["message" ], "Model deleted successfully" )
224+ mock_delete .assert_called_once ()
225+
120226
121227if __name__ == "__main__" :
122228 unittest .main ()
0 commit comments