File size: 3,183 Bytes
8ba64a4
 
 
 
 
3fdba15
8ba64a4
 
9645c29
8ba64a4
 
 
3fdba15
8ba64a4
 
3fdba15
8ba64a4
 
 
 
 
b652f9c
0dd08cb
b652f9c
 
0dd08cb
 
 
 
 
b652f9c
a9d8d74
 
 
 
b652f9c
a9d8d74
8ba64a4
 
 
 
 
 
 
 
 
 
0dd08cb
 
 
 
a9d8d74
 
 
 
8ba64a4
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from functools import lru_cache
from typing import Optional

from pydantic_settings import BaseSettings

EXTRACT_INFO_SYSTEM = "You are an expert in structured data extraction. You will be given an image or a set of images of a product and should extract its properties into the given structure."

EXTRACT_INFO_HUMAN = (
    """Output properties of the main product (or {product_taxonomy}) shown in the images. You should use the following product data to assist you, if available:
    
    {product_data}
    
    If an attribute appears in both the image and the product data, use the value from the product data."""
).replace("    ", "")

FOLLOW_SCHEMA_SYSTEM = "You are an expert in structured data extraction. You will be given an dictionary of attributes of a product and should output the its properties into the given structure."

FOLLOW_SCHEMA_HUMAN = """Convert following attributes to structured schema. Keep all the keys and number of values. Only replace the values themselves. :

{json_info}"""

GET_PERCENTAGE_SYSTEM = "You are a fashion assistant. You have to assign percentages of cerntainty to each attribute of a product based on the image and product data. You will be given an image or a set of images of a product and set of attributes and should output the percentages of certainty into the given structure."

GET_PERCENTAGE_HUMAN = """For each allowed value in each attribute, assign a percentage of certainty (from 0 to 100) that the product fits that value.
For attributes of type list[string], there can be multiple values, and multiple percentages of 100 are possible.
You should use the following product data to assist you, if available:
{product_data}
If an attribute appears in both the image and the product data, use the value from the product data.
"""

REEVALUATE_SYSTEM = "You are a fashion assistant. You have to reevaluate the attributes of a product based on the image and product data. You will be given an image or a set of images of a product and set of attributes and should output the reevaluated attributes into the given structure."

REEVALUATE_HUMAN = """Reevaluate the following attributes of the main product (or {product_taxonomy}) shown in the images. Here are the attributes to reevaluate:
{product_data}

If an attribute has type of string, do not need to reevaluate the values, just the attribute itself. If an attribute has type of list[string], reevaluate the top three values. 
"""

class Prompts(BaseSettings):
    EXTRACT_INFO_SYSTEM_MESSAGE: str = EXTRACT_INFO_SYSTEM

    EXTRACT_INFO_HUMAN_MESSAGE: str = EXTRACT_INFO_HUMAN

    FOLLOW_SCHEMA_SYSTEM_MESSAGE: str = FOLLOW_SCHEMA_SYSTEM

    FOLLOW_SCHEMA_HUMAN_MESSAGE: str = FOLLOW_SCHEMA_HUMAN

    GET_PERCENTAGE_SYSTEM_MESSAGE: str = GET_PERCENTAGE_SYSTEM

    GET_PERCENTAGE_HUMAN_MESSAGE: str = GET_PERCENTAGE_HUMAN

    REEVALUATE_SYSTEM_MESSAGE: str = REEVALUATE_SYSTEM
    
    REEVALUATE_HUMAN_MESSAGE: str = REEVALUATE_HUMAN


# Create a cached instance of settings
@lru_cache
def get_prompts() -> Prompts:
    """
    Create and cache a Prompts instance.
    Returns the same instance for subsequent calls.
    """
    prompts = Prompts()
    return prompts