unique_toolkit 0.5.42__tar.gz → 0.5.43__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 (48) hide show
  1. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/CHANGELOG.md +5 -0
  2. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/PKG-INFO +6 -1
  3. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/pyproject.toml +1 -1
  4. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/language_model/__init__.py +3 -0
  5. unique_toolkit-0.5.43/unique_toolkit/language_model/prompt.py +124 -0
  6. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/LICENSE +0 -0
  7. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/README.md +0 -0
  8. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/__init__.py +0 -0
  9. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/_common/_base_service.py +0 -0
  10. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/_common/_time_utils.py +0 -0
  11. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/_common/exception.py +0 -0
  12. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/_common/validators.py +0 -0
  13. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/__init__.py +0 -0
  14. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/init_logging.py +0 -0
  15. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/init_sdk.py +0 -0
  16. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/performance/async_tasks.py +0 -0
  17. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  18. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/schemas.py +0 -0
  19. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/app/verification.py +0 -0
  20. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/chat/__init__.py +0 -0
  21. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/chat/schemas.py +0 -0
  22. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/chat/service.py +0 -0
  23. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/chat/state.py +0 -0
  24. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/chat/utils.py +0 -0
  25. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/content/__init__.py +0 -0
  26. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/content/schemas.py +0 -0
  27. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/content/service.py +0 -0
  28. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/content/utils.py +0 -0
  29. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/embedding/__init__.py +0 -0
  30. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/embedding/schemas.py +0 -0
  31. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/embedding/service.py +0 -0
  32. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/embedding/utils.py +0 -0
  33. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/config.py +0 -0
  34. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/context_relevancy/constants.py +0 -0
  35. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  36. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  37. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/context_relevancy/utils.py +0 -0
  38. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/exception.py +0 -0
  39. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/hallucination/constants.py +0 -0
  40. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  41. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  42. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/hallucination/utils.py +0 -0
  43. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/output_parser.py +0 -0
  44. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/evaluators/schemas.py +0 -0
  45. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/language_model/infos.py +0 -0
  46. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/language_model/schemas.py +0 -0
  47. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/language_model/service.py +0 -0
  48. {unique_toolkit-0.5.42 → unique_toolkit-0.5.43}/unique_toolkit/language_model/utils.py +0 -0
@@ -5,6 +5,11 @@ 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
+
9
+
10
+ ## [0.5.43] - 2024-12-13
11
+ - Add `Prompt` class to handle templated prompts that can be formatted into LanguageModelSystemMessage and LanguageModelUserMessage.
12
+
8
13
  ## [0.5.42] - 2024-12-11
9
14
  - Update `LanguageModelTokenLimits` with fix avoiding floats for token
10
15
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.5.42
3
+ Version: 0.5.43
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -100,6 +100,11 @@ All notable changes to this project will be documented in this file.
100
100
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
101
101
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
102
102
 
103
+
104
+
105
+ ## [0.5.43] - 2024-12-13
106
+ - Add `Prompt` class to handle templated prompts that can be formatted into LanguageModelSystemMessage and LanguageModelUserMessage.
107
+
103
108
  ## [0.5.42] - 2024-12-11
104
109
  - Update `LanguageModelTokenLimits` with fix avoiding floats for token
105
110
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.5.42"
3
+ version = "0.5.43"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -1,5 +1,8 @@
1
1
  from .infos import LanguageModel as LanguageModel
2
2
  from .infos import LanguageModelName as LanguageModelName
3
+ from .prompt import (
4
+ Prompt as Prompt,
5
+ )
3
6
  from .schemas import (
4
7
  LanguageModelAssistantMessage as LanguageModelAssistantMessage,
5
8
  )
@@ -0,0 +1,124 @@
1
+ from string import Template
2
+ from typing import Any
3
+
4
+ from unique_toolkit.language_model.schemas import (
5
+ LanguageModelSystemMessage,
6
+ LanguageModelUserMessage,
7
+ )
8
+
9
+
10
+ class Prompt:
11
+ """
12
+ A class for handling templated prompts that can be formatted into LanguageModelSystemMessage and LanguageModelUserMessage.
13
+
14
+ This class wraps a string template and provides methods to format it with variables and
15
+ convert it into different types of language model messages. It uses Python's string.Template
16
+ for variable substitution.
17
+
18
+ Usage:
19
+ # Create a prompt with a template and set variables
20
+ prompt = Prompt("Hello, ${name}!", name="World")
21
+
22
+ # Substitute the template with variables and return the formatted content
23
+ content = prompt.substitute(name="World")
24
+
25
+ # Get the formatted content
26
+ content = prompt.content # Returns "Hello, World!"
27
+
28
+ # Get the template
29
+ template = prompt.template
30
+
31
+ # Convert to language model messages
32
+ system_msg = prompt.to_system_msg()
33
+ user_msg = prompt.to_user_msg()
34
+ user_msg_with_images = prompt.to_user_msg_with_images(images=["IMAGE_IN_BASE64"])
35
+
36
+ Properties:
37
+ template: Returns the underlying template string
38
+ content: Returns the current formatted content string
39
+
40
+ Methods:
41
+ substitute(**kwargs): Substitutes the template with the given variables
42
+ to_user_msg(): Converts the prompt to a LanguageModelUserMessage
43
+ to_user_msg_with_images(images): Converts the prompt to a LanguageModelUserMessage with images
44
+ """
45
+
46
+ def __init__(self, template: str, **kwargs):
47
+ self._template = Template(template)
48
+ self._content = self._template.template
49
+ if kwargs:
50
+ self._content = self._template.substitute(**kwargs)
51
+
52
+ @property
53
+ def template(self):
54
+ """
55
+ Returns the template string.
56
+
57
+ Returns:
58
+ str: The template string.
59
+ """
60
+ return self._template
61
+
62
+ @property
63
+ def content(self):
64
+ """
65
+ Returns the formatted content string.
66
+
67
+ Returns:
68
+ str: The formatted content string.
69
+ """
70
+ return self._content
71
+
72
+ def substitute(self, **kwargs: Any) -> str:
73
+ """
74
+ Substitutes the template with the given kwargs. Raises KeyError if a required parameter is missing.
75
+
76
+ Args:
77
+ **kwargs: Keyword arguments to substitute into the template.
78
+
79
+ Returns:
80
+ str: The substituted template string.
81
+
82
+ Raises:
83
+ KeyError: If a required parameter in the template is missing from kwargs.
84
+ """
85
+ self._content = self._template.substitute(**kwargs)
86
+ return self._content
87
+
88
+ def to_system_msg(self) -> LanguageModelSystemMessage:
89
+ """
90
+ Returns a LanguageModelSystemMessage with the content of the prompt.
91
+
92
+ Returns:
93
+ LanguageModelSystemMessage: The formatted prompt.
94
+ """
95
+ return LanguageModelSystemMessage(content=self._content)
96
+
97
+ def to_user_msg(self) -> LanguageModelUserMessage:
98
+ """
99
+ Returns a LanguageModelUserMessage with the content of the prompt.
100
+
101
+ Returns:
102
+ LanguageModelUserMessage: The formatted prompt.
103
+ """
104
+ return LanguageModelUserMessage(content=self._content)
105
+
106
+ def to_user_msg_with_images(self, images: list[str]) -> LanguageModelUserMessage:
107
+ """
108
+ Returns a LanguageModelUserMessage with the content of the prompt and the images.
109
+
110
+ Args:
111
+ images: List of images in base64 format.
112
+
113
+ Returns:
114
+ LanguageModelUserMessage: The formatted prompt with images.
115
+ """
116
+ return LanguageModelUserMessage(
117
+ content=[
118
+ {"type": "text", "text": self._content},
119
+ *[
120
+ {"type": "image_url", "imageUrl": {"url": image}}
121
+ for image in images
122
+ ],
123
+ ]
124
+ )
File without changes