unique_toolkit 0.7.13__tar.gz → 0.7.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/CHANGELOG.md +16 -0
  2. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/PKG-INFO +18 -2
  3. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/pyproject.toml +2 -2
  4. unique_toolkit-0.7.17/unique_toolkit/_common/validators.py +57 -0
  5. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/schemas.py +15 -20
  6. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/service.py +313 -65
  7. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/functions.py +12 -3
  8. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/service.py +5 -0
  9. unique_toolkit-0.7.17/unique_toolkit/evaluators/config.py +26 -0
  10. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/context_relevancy/constants.py +4 -2
  11. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/context_relevancy/utils.py +32 -18
  12. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/hallucination/constants.py +2 -2
  13. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/hallucination/utils.py +40 -30
  14. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/functions.py +23 -19
  15. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/infos.py +6 -4
  16. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/schemas.py +116 -32
  17. unique_toolkit-0.7.17/unique_toolkit/protocols/support.py +28 -0
  18. unique_toolkit-0.7.13/unique_toolkit/_common/validators.py +0 -8
  19. unique_toolkit-0.7.13/unique_toolkit/evaluators/config.py +0 -35
  20. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/LICENSE +0 -0
  21. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/README.md +0 -0
  22. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/__init__.py +0 -0
  23. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/_common/_base_service.py +0 -0
  24. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/_common/_time_utils.py +0 -0
  25. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/_common/exception.py +0 -0
  26. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/_common/validate_required_values.py +0 -0
  27. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/__init__.py +0 -0
  28. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/init_logging.py +0 -0
  29. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/init_sdk.py +0 -0
  30. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/performance/async_tasks.py +0 -0
  31. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  32. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/app/verification.py +0 -0
  33. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/__init__.py +0 -0
  34. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/constants.py +0 -0
  35. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/functions.py +0 -0
  36. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/schemas.py +0 -0
  37. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/state.py +0 -0
  38. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/chat/utils.py +0 -0
  39. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/__init__.py +0 -0
  40. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/constants.py +0 -0
  41. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/schemas.py +0 -0
  42. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/content/utils.py +0 -0
  43. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/__init__.py +0 -0
  44. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/constants.py +0 -0
  45. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/functions.py +0 -0
  46. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/schemas.py +0 -0
  47. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/service.py +0 -0
  48. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/embedding/utils.py +0 -0
  49. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/__init__.py +0 -0
  50. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/constants.py +0 -0
  51. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  52. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  53. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/exception.py +0 -0
  54. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  55. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  56. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/output_parser.py +0 -0
  57. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/evaluators/schemas.py +0 -0
  58. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/__init__.py +0 -0
  59. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/builder.py +0 -0
  60. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/constants.py +0 -0
  61. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/prompt.py +0 -0
  62. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/service.py +0 -0
  63. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/language_model/utils.py +0 -0
  64. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/short_term_memory/__init__.py +0 -0
  65. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/short_term_memory/constants.py +0 -0
  66. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/short_term_memory/functions.py +0 -0
  67. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/short_term_memory/schemas.py +0 -0
  68. {unique_toolkit-0.7.13 → unique_toolkit-0.7.17}/unique_toolkit/short_term_memory/service.py +0 -0
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.7.17] - 2025-05-16
9
+ - Change inheritance hierarchy of events for easier deprecation
10
+
11
+ ## [0.7.16] - 2025-05-16
12
+ - Add classmethods to create LanguageModelAssistatnMessage from functions and stream response
13
+ - Add completion like method to chat
14
+ - Add protocol for completion like method
15
+
16
+ ## [0.7.15] - 2025-05-13
17
+ - Add the possibility to specify ingestionConfig when creating or updating a Content.
18
+
19
+ ## [0.7.14] - 2025-05-08
20
+ - Fix bug not selecting the correct llm
21
+ - Add LMI type for flexible init of LanguageModelInfo
22
+ - Replace LanguageModel with LanguageModelInfo in hallucination check
23
+
8
24
  ## [0.7.13] - 2025-05-07
9
25
  - Adding litellm models `litellm:anthropic-claude-3-7-sonnet`, `litellm:anthropic-claude-3-7-sonnet-thinking`, `litellm:gemini-2-0-flash`, `gemini-2-5-flash-preview-04-17` , `litellm:gemini-2-5-pro-exp-03-25`
10
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.7.13
3
+ Version: 0.7.17
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -17,7 +17,7 @@ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
17
17
  Requires-Dist: regex (>=2024.5.15,<2025.0.0)
18
18
  Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
19
19
  Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
20
- Requires-Dist: unique-sdk (>=0.9.17,<0.10.0)
20
+ Requires-Dist: unique-sdk (>=0.9.26,<0.10.0)
21
21
  Description-Content-Type: text/markdown
22
22
 
23
23
  # Unique Toolkit
@@ -111,6 +111,22 @@ All notable changes to this project will be documented in this file.
111
111
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
112
112
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
113
113
 
114
+ ## [0.7.17] - 2025-05-16
115
+ - Change inheritance hierarchy of events for easier deprecation
116
+
117
+ ## [0.7.16] - 2025-05-16
118
+ - Add classmethods to create LanguageModelAssistatnMessage from functions and stream response
119
+ - Add completion like method to chat
120
+ - Add protocol for completion like method
121
+
122
+ ## [0.7.15] - 2025-05-13
123
+ - Add the possibility to specify ingestionConfig when creating or updating a Content.
124
+
125
+ ## [0.7.14] - 2025-05-08
126
+ - Fix bug not selecting the correct llm
127
+ - Add LMI type for flexible init of LanguageModelInfo
128
+ - Replace LanguageModel with LanguageModelInfo in hallucination check
129
+
114
130
  ## [0.7.13] - 2025-05-07
115
131
  - Adding litellm models `litellm:anthropic-claude-3-7-sonnet`, `litellm:anthropic-claude-3-7-sonnet-thinking`, `litellm:gemini-2-0-flash`, `gemini-2-5-flash-preview-04-17` , `litellm:gemini-2-5-pro-exp-03-25`
116
132
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.7.13"
3
+ version = "0.7.17"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -20,7 +20,7 @@ numpy = "^1.26.4"
20
20
  python-dotenv = "^1.0.1"
21
21
  regex = "^2024.5.15"
22
22
  tiktoken = "^0.7.0"
23
- unique-sdk = "^0.9.17"
23
+ unique-sdk = "^0.9.26"
24
24
 
25
25
  [tool.poetry.group.dev.dependencies]
26
26
  ruff = "0.5.0"
@@ -0,0 +1,57 @@
1
+ from typing import Annotated
2
+
3
+ from pydantic import BeforeValidator, PlainSerializer
4
+
5
+ from unique_toolkit.language_model import LanguageModelName
6
+ from unique_toolkit.language_model.infos import (
7
+ LanguageModelInfo,
8
+ LanguageModelProvider,
9
+ )
10
+
11
+ # TODO @klcd: Inform on deprecation of str as input
12
+ LMI = Annotated[
13
+ LanguageModelInfo,
14
+ BeforeValidator(
15
+ lambda v: validate_and_init_language_model_info(v),
16
+ json_schema_input_type=str | LanguageModelName | LanguageModelInfo,
17
+ ),
18
+ PlainSerializer(
19
+ lambda v: serialize_lmi(v),
20
+ when_used="json",
21
+ return_type=str | LanguageModelInfo,
22
+ ),
23
+ ]
24
+
25
+
26
+ def serialize_lmi(model: LanguageModelInfo) -> str | LanguageModelInfo:
27
+ if model.provider == LanguageModelProvider.CUSTOM:
28
+ return model
29
+
30
+ return model.name
31
+
32
+
33
+ def validate_and_init_language_model_info(
34
+ v: str | LanguageModelName | LanguageModelInfo,
35
+ ) -> LanguageModelInfo:
36
+ """Validate and initialize a LanguageModelInfo object.
37
+
38
+ Args:
39
+ v: The input value to validate and initialize.
40
+
41
+ Returns:
42
+ LanguageModelInfo: The validated and initialized LanguageModelInfo object.
43
+
44
+ """
45
+ if isinstance(v, LanguageModelName):
46
+ return LanguageModelInfo.from_name(v)
47
+ if isinstance(v, str):
48
+ if v in [name.value for name in LanguageModelName]:
49
+ return LanguageModelInfo.from_name(LanguageModelName(v))
50
+
51
+ return LanguageModelInfo(
52
+ name=v,
53
+ version="custom",
54
+ provider=LanguageModelProvider.CUSTOM,
55
+ )
56
+
57
+ return v
@@ -109,31 +109,26 @@ class ChatEventPayload(BaseModel):
109
109
  @deprecated("""Use `ChatEventPayload` instead.
110
110
  This class will be removed in the next major version.""")
111
111
  class EventPayload(ChatEventPayload):
112
- user_message: EventUserMessage
113
- assistant_message: EventAssistantMessage
114
- additional_parameters: Optional[EventAdditionalParameters] = None
115
-
116
-
117
- @deprecated(
118
- """Use the more specific `ChatEvent` instead that has the same properties. \
119
- This class will be removed in the next major version."""
120
- )
121
- class Event(BaseModel):
122
- model_config = model_config
123
-
124
- id: str
125
- event: EventName
126
- user_id: str
127
- company_id: str
128
- payload: EventPayload
129
- created_at: Optional[int] = None
130
- version: Optional[str] = None
112
+ pass
113
+ # user_message: EventUserMessage
114
+ # assistant_message: EventAssistantMessage
115
+ # additional_parameters: Optional[EventAdditionalParameters] = None
131
116
 
132
117
 
133
118
  class ChatEvent(BaseEvent):
134
119
  model_config = model_config
135
120
 
136
- event: EventName
137
121
  payload: ChatEventPayload
138
122
  created_at: Optional[int] = None
139
123
  version: Optional[str] = None
124
+
125
+
126
+ @deprecated(
127
+ """Use the more specific `ChatEvent` instead that has the same properties. \
128
+ This class will be removed in the next major version."""
129
+ )
130
+ class Event(ChatEvent):
131
+ pass
132
+ # The below should only affect type hints
133
+ # event: EventName T
134
+ # payload: EventPayload
@@ -41,6 +41,7 @@ from unique_toolkit.language_model.infos import (
41
41
  )
42
42
  from unique_toolkit.language_model.schemas import (
43
43
  LanguageModelMessages,
44
+ LanguageModelResponse,
44
45
  LanguageModelStreamResponse,
45
46
  LanguageModelTool,
46
47
  )
@@ -81,7 +82,7 @@ class ChatService:
81
82
  @deprecated(
82
83
  "The event property is deprecated and will be removed in a future version."
83
84
  )
84
- def event(self) -> Event | ChatEvent | None:
85
+ def event(self) -> Event | ChatEvent:
85
86
  """
86
87
  Get the event object (deprecated).
87
88
 
@@ -279,14 +280,30 @@ class ChatService:
279
280
  Args:
280
281
  debug_info (dict): The new debug information.
281
282
  """
282
-
283
+ [
284
+ company_id,
285
+ user_id,
286
+ assistant_message_id,
287
+ user_message_id,
288
+ chat_id,
289
+ user_message_text,
290
+ ] = validate_required_values(
291
+ [
292
+ self._company_id,
293
+ self._user_id,
294
+ self._assistant_message_id,
295
+ self._user_message_id,
296
+ self._chat_id,
297
+ self._user_message_text,
298
+ ]
299
+ )
283
300
  return await modify_message_async(
284
- user_id=self._user_id,
285
- company_id=self._company_id,
286
- assistant_message_id=self._assistant_message_id,
287
- chat_id=self._chat_id,
288
- user_message_id=self._user_message_id,
289
- user_message_text=self._user_message_text,
301
+ user_id=user_id,
302
+ company_id=company_id,
303
+ assistant_message_id=assistant_message_id,
304
+ chat_id=chat_id,
305
+ user_message_id=user_message_id,
306
+ user_message_text=user_message_text,
290
307
  assistant=False,
291
308
  debug_info=debug_info,
292
309
  )
@@ -298,14 +315,31 @@ class ChatService:
298
315
  Args:
299
316
  debug_info (dict): The new debug information.
300
317
  """
318
+ [
319
+ company_id,
320
+ user_id,
321
+ assistant_message_id,
322
+ user_message_id,
323
+ chat_id,
324
+ user_message_text,
325
+ ] = validate_required_values(
326
+ [
327
+ self._company_id,
328
+ self._user_id,
329
+ self._assistant_message_id,
330
+ self._user_message_id,
331
+ self._chat_id,
332
+ self._user_message_text,
333
+ ]
334
+ )
301
335
 
302
336
  return modify_message(
303
- user_id=self._user_id,
304
- company_id=self._company_id,
305
- assistant_message_id=self._assistant_message_id,
306
- chat_id=self._chat_id,
307
- user_message_id=self._user_message_id,
308
- user_message_text=self._user_message_text,
337
+ user_id=user_id,
338
+ company_id=company_id,
339
+ assistant_message_id=assistant_message_id,
340
+ chat_id=chat_id,
341
+ user_message_id=user_message_id,
342
+ user_message_text=user_message_text,
309
343
  assistant=False,
310
344
  debug_info=debug_info,
311
345
  )
@@ -334,13 +368,31 @@ class ChatService:
334
368
  Raises:
335
369
  Exception: If the modification fails.
336
370
  """
371
+ [
372
+ company_id,
373
+ user_id,
374
+ assistant_message_id,
375
+ user_message_id,
376
+ chat_id,
377
+ user_message_text,
378
+ ] = validate_required_values(
379
+ [
380
+ self._company_id,
381
+ self._user_id,
382
+ self._assistant_message_id,
383
+ self._user_message_id,
384
+ self._chat_id,
385
+ self._user_message_text,
386
+ ]
387
+ )
388
+
337
389
  return modify_message(
338
- user_id=self._user_id,
339
- company_id=self._company_id,
340
- assistant_message_id=self._assistant_message_id,
341
- chat_id=self._chat_id,
342
- user_message_id=self._user_message_id,
343
- user_message_text=self._user_message_text,
390
+ user_id=user_id,
391
+ company_id=company_id,
392
+ assistant_message_id=assistant_message_id,
393
+ chat_id=chat_id,
394
+ user_message_id=user_message_id,
395
+ user_message_text=user_message_text,
344
396
  assistant=False,
345
397
  content=content,
346
398
  references=references,
@@ -373,13 +425,32 @@ class ChatService:
373
425
  Raises:
374
426
  Exception: If the modification fails.
375
427
  """
428
+
429
+ [
430
+ company_id,
431
+ user_id,
432
+ assistant_message_id,
433
+ user_message_id,
434
+ chat_id,
435
+ user_message_text,
436
+ ] = validate_required_values(
437
+ [
438
+ self._company_id,
439
+ self._user_id,
440
+ self._assistant_message_id,
441
+ self._user_message_id,
442
+ self._chat_id,
443
+ self._user_message_text,
444
+ ]
445
+ )
446
+
376
447
  return await modify_message_async(
377
- user_id=self._user_id,
378
- company_id=self._company_id,
379
- assistant_message_id=self._assistant_message_id,
380
- chat_id=self._chat_id,
381
- user_message_id=self._user_message_id,
382
- user_message_text=self._user_message_text,
448
+ user_id=user_id,
449
+ company_id=company_id,
450
+ assistant_message_id=assistant_message_id,
451
+ chat_id=chat_id,
452
+ user_message_id=user_message_id,
453
+ user_message_text=user_message_text,
383
454
  assistant=False,
384
455
  content=content,
385
456
  references=references,
@@ -414,13 +485,31 @@ class ChatService:
414
485
  Raises:
415
486
  Exception: If the modification fails.
416
487
  """
488
+ [
489
+ company_id,
490
+ user_id,
491
+ assistant_message_id,
492
+ user_message_id,
493
+ chat_id,
494
+ user_message_text,
495
+ ] = validate_required_values(
496
+ [
497
+ self._company_id,
498
+ self._user_id,
499
+ self._assistant_message_id,
500
+ self._user_message_id,
501
+ self._chat_id,
502
+ self._user_message_text,
503
+ ]
504
+ )
505
+
417
506
  return modify_message(
418
- user_id=self._user_id,
419
- company_id=self._company_id,
420
- assistant_message_id=self._assistant_message_id,
421
- chat_id=self._chat_id,
422
- user_message_id=self._user_message_id,
423
- user_message_text=self._user_message_text,
507
+ user_id=user_id,
508
+ company_id=company_id,
509
+ assistant_message_id=assistant_message_id,
510
+ chat_id=chat_id,
511
+ user_message_id=user_message_id,
512
+ user_message_text=user_message_text,
424
513
  assistant=True,
425
514
  content=content,
426
515
  original_content=original_content,
@@ -456,14 +545,30 @@ class ChatService:
456
545
  Raises:
457
546
  Exception: If the modification fails.
458
547
  """
459
-
548
+ [
549
+ company_id,
550
+ user_id,
551
+ assistant_message_id,
552
+ user_message_id,
553
+ chat_id,
554
+ user_message_text,
555
+ ] = validate_required_values(
556
+ [
557
+ self._company_id,
558
+ self._user_id,
559
+ self._assistant_message_id,
560
+ self._user_message_id,
561
+ self._chat_id,
562
+ self._user_message_text,
563
+ ]
564
+ )
460
565
  return await modify_message_async(
461
- user_id=self._user_id,
462
- company_id=self._company_id,
463
- assistant_message_id=self._assistant_message_id,
464
- chat_id=self._chat_id,
465
- user_message_id=self._user_message_id,
466
- user_message_text=self._user_message_text,
566
+ user_id=user_id,
567
+ company_id=company_id,
568
+ assistant_message_id=assistant_message_id,
569
+ chat_id=chat_id,
570
+ user_message_id=user_message_id,
571
+ user_message_text=user_message_text,
467
572
  assistant=True,
468
573
  content=content,
469
574
  original_content=original_content,
@@ -595,11 +700,25 @@ class ChatService:
595
700
  Raises:
596
701
  Exception: If the creation fails.
597
702
  """
703
+ [
704
+ company_id,
705
+ user_id,
706
+ assistant_id,
707
+ chat_id,
708
+ ] = validate_required_values(
709
+ [
710
+ self._company_id,
711
+ self._user_id,
712
+ self._assistant_id,
713
+ self._chat_id,
714
+ ]
715
+ )
716
+
598
717
  chat_message = create_message(
599
- user_id=self._user_id,
600
- company_id=self._company_id,
601
- chat_id=self._chat_id,
602
- assistant_id=self._assistant_id,
718
+ user_id=user_id,
719
+ company_id=company_id,
720
+ chat_id=chat_id,
721
+ assistant_id=assistant_id,
603
722
  role=ChatMessageRole.ASSISTANT,
604
723
  content=content,
605
724
  original_content=original_content,
@@ -635,12 +754,24 @@ class ChatService:
635
754
  Raises:
636
755
  Exception: If the creation fails.
637
756
  """
638
-
757
+ [
758
+ company_id,
759
+ user_id,
760
+ assistant_id,
761
+ chat_id,
762
+ ] = validate_required_values(
763
+ [
764
+ self._company_id,
765
+ self._user_id,
766
+ self._assistant_id,
767
+ self._chat_id,
768
+ ]
769
+ )
639
770
  chat_message = await create_message_async(
640
- user_id=self._user_id,
641
- company_id=self._company_id,
642
- chat_id=self._chat_id,
643
- assistant_id=self._assistant_id,
771
+ user_id=user_id,
772
+ company_id=company_id,
773
+ chat_id=chat_id,
774
+ assistant_id=assistant_id,
644
775
  role=ChatMessageRole.ASSISTANT,
645
776
  content=content,
646
777
  original_content=original_content,
@@ -676,11 +807,24 @@ class ChatService:
676
807
  Raises:
677
808
  Exception: If the creation fails.
678
809
  """
810
+ [
811
+ company_id,
812
+ user_id,
813
+ assistant_id,
814
+ chat_id,
815
+ ] = validate_required_values(
816
+ [
817
+ self._company_id,
818
+ self._user_id,
819
+ self._assistant_id,
820
+ self._chat_id,
821
+ ]
822
+ )
679
823
  chat_message = create_message(
680
- user_id=self._user_id,
681
- company_id=self._company_id,
682
- chat_id=self._chat_id,
683
- assistant_id=self._assistant_id,
824
+ user_id=user_id,
825
+ company_id=company_id,
826
+ chat_id=chat_id,
827
+ assistant_id=assistant_id,
684
828
  role=ChatMessageRole.USER,
685
829
  content=content,
686
830
  original_content=original_content,
@@ -716,12 +860,24 @@ class ChatService:
716
860
  Raises:
717
861
  Exception: If the creation fails.
718
862
  """
719
-
863
+ [
864
+ company_id,
865
+ user_id,
866
+ assistant_id,
867
+ chat_id,
868
+ ] = validate_required_values(
869
+ [
870
+ self._company_id,
871
+ self._user_id,
872
+ self._assistant_id,
873
+ self._chat_id,
874
+ ]
875
+ )
720
876
  chat_message = await create_message_async(
721
- user_id=self._user_id,
722
- company_id=self._company_id,
723
- chat_id=self._chat_id,
724
- assistant_id=self._assistant_id,
877
+ user_id=user_id,
878
+ company_id=company_id,
879
+ chat_id=chat_id,
880
+ assistant_id=assistant_id,
725
881
  role=ChatMessageRole.USER,
726
882
  content=content,
727
883
  original_content=original_content,
@@ -761,9 +917,19 @@ class ChatService:
761
917
  Raises:
762
918
  Exception: If the creation fails
763
919
  """
920
+ [
921
+ company_id,
922
+ user_id,
923
+ ] = validate_required_values(
924
+ [
925
+ self._company_id,
926
+ self._user_id,
927
+ ]
928
+ )
929
+
764
930
  return create_message_assessment(
765
- user_id=self._user_id,
766
- company_id=self._company_id,
931
+ user_id=user_id,
932
+ company_id=company_id,
767
933
  assistant_message_id=assistant_message_id,
768
934
  status=status,
769
935
  type=type,
@@ -801,9 +967,19 @@ class ChatService:
801
967
  Raises:
802
968
  Exception: If the creation fails
803
969
  """
970
+ [
971
+ company_id,
972
+ user_id,
973
+ ] = validate_required_values(
974
+ [
975
+ self._company_id,
976
+ self._user_id,
977
+ ]
978
+ )
979
+
804
980
  return await create_message_assessment_async(
805
- user_id=self._user_id,
806
- company_id=self._company_id,
981
+ user_id=user_id,
982
+ company_id=company_id,
807
983
  assistant_message_id=assistant_message_id,
808
984
  status=status,
809
985
  type=type,
@@ -839,9 +1015,19 @@ class ChatService:
839
1015
  Raises:
840
1016
  Exception: If the modification fails
841
1017
  """
1018
+ [
1019
+ company_id,
1020
+ user_id,
1021
+ ] = validate_required_values(
1022
+ [
1023
+ self._company_id,
1024
+ self._user_id,
1025
+ ]
1026
+ )
1027
+
842
1028
  return modify_message_assessment(
843
- user_id=self._user_id,
844
- company_id=self._company_id,
1029
+ user_id=user_id,
1030
+ company_id=company_id,
845
1031
  assistant_message_id=assistant_message_id,
846
1032
  status=status,
847
1033
  type=type,
@@ -876,9 +1062,19 @@ class ChatService:
876
1062
  Raises:
877
1063
  Exception: If the modification fails
878
1064
  """
1065
+ [
1066
+ company_id,
1067
+ user_id,
1068
+ ] = validate_required_values(
1069
+ [
1070
+ self._company_id,
1071
+ self._user_id,
1072
+ ]
1073
+ )
1074
+
879
1075
  return await modify_message_assessment_async(
880
- user_id=self._user_id,
881
- company_id=self._company_id,
1076
+ user_id=user_id,
1077
+ company_id=company_id,
882
1078
  assistant_message_id=assistant_message_id,
883
1079
  status=status,
884
1080
  type=type,
@@ -938,6 +1134,32 @@ class ChatService:
938
1134
  other_options=other_options,
939
1135
  )
940
1136
 
1137
+ def complete(
1138
+ self,
1139
+ messages: LanguageModelMessages,
1140
+ model_name: LanguageModelName | str,
1141
+ content_chunks: list[ContentChunk] = [],
1142
+ debug_info: dict = {},
1143
+ temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1144
+ timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1145
+ tools: Optional[list[LanguageModelTool]] = None,
1146
+ start_text: Optional[str] = None,
1147
+ other_options: Optional[dict] = None,
1148
+ ) -> LanguageModelResponse:
1149
+ response = self.stream_complete(
1150
+ messages=messages,
1151
+ model_name=model_name,
1152
+ content_chunks=content_chunks,
1153
+ debug_info=debug_info,
1154
+ temperature=temperature,
1155
+ timeout=timeout,
1156
+ tools=tools,
1157
+ start_text=start_text,
1158
+ other_options=other_options,
1159
+ )
1160
+
1161
+ return LanguageModelResponse.from_stream_response(response)
1162
+
941
1163
  async def stream_complete_async(
942
1164
  self,
943
1165
  messages: LanguageModelMessages,
@@ -989,3 +1211,29 @@ class ChatService:
989
1211
  start_text=start_text,
990
1212
  other_options=other_options,
991
1213
  )
1214
+
1215
+ async def complete_async(
1216
+ self,
1217
+ messages: LanguageModelMessages,
1218
+ model_name: LanguageModelName | str,
1219
+ content_chunks: list[ContentChunk] = [],
1220
+ debug_info: dict = {},
1221
+ temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1222
+ timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1223
+ tools: Optional[list[LanguageModelTool]] = None,
1224
+ start_text: Optional[str] = None,
1225
+ other_options: Optional[dict] = None,
1226
+ ) -> LanguageModelResponse:
1227
+ response = self.stream_complete_async(
1228
+ messages=messages,
1229
+ model_name=model_name,
1230
+ content_chunks=content_chunks,
1231
+ debug_info=debug_info,
1232
+ temperature=temperature,
1233
+ timeout=timeout,
1234
+ tools=tools,
1235
+ start_text=start_text,
1236
+ other_options=other_options,
1237
+ )
1238
+
1239
+ return LanguageModelResponse.from_stream_response(await response)