Spaces:
Paused
Paused
add o3-mini, chatgpt-4o-latest
Browse files
app.py
CHANGED
|
@@ -103,6 +103,8 @@ languages = ["American English",
|
|
| 103 |
"Portuguese"]
|
| 104 |
|
| 105 |
models = ["gpt-4o",
|
|
|
|
|
|
|
| 106 |
"claude-3-7-sonnet-latest",
|
| 107 |
"claude-3-5-sonnet-20240620",
|
| 108 |
"claude-3-5-sonnet-20241022",
|
|
@@ -386,7 +388,7 @@ Return the reformatted structure only. Do not add any preceding or trailing char
|
|
| 386 |
|
| 387 |
<structure>/n{structure}</structure>"""
|
| 388 |
|
| 389 |
-
|
| 390 |
You are given information of a product, a reference structure, and a reference copy.
|
| 391 |
Please analyze the structure, make a plan on how to follow the structure correctly.
|
| 392 |
Use the tone of voice of the reference copy if available for the generated description.
|
|
@@ -616,8 +618,11 @@ Guidelines:
|
|
| 616 |
|
| 617 |
|
| 618 |
def get_model(model_name, temperature=0.0):
|
| 619 |
-
if model_name.startswith("gpt")
|
|
|
|
| 620 |
chat = ChatOpenAI(model=model_name, max_tokens=4096, temperature=temperature)
|
|
|
|
|
|
|
| 621 |
elif model_name.startswith("claude"):
|
| 622 |
chat = ChatAnthropic(model_name=model_name,
|
| 623 |
anthropic_api_key=os.environ["ANTHROPIC_API_KEY"],
|
|
@@ -730,7 +735,7 @@ def generate(*data):
|
|
| 730 |
if model.startswith("gemini"):
|
| 731 |
if len((structure + copy).strip()) > 0:
|
| 732 |
messages = [
|
| 733 |
-
|
| 734 |
max_length=max_length,
|
| 735 |
key_features=key_features,
|
| 736 |
structure=structure,
|
|
@@ -743,46 +748,70 @@ def generate(*data):
|
|
| 743 |
print("Gemini input: ", messages)
|
| 744 |
ri = chat.generate_content(messages)
|
| 745 |
print("Gemini response: ", ri)
|
| 746 |
-
response.append(ri)
|
| 747 |
else:
|
| 748 |
-
if
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
messages = [
|
| 762 |
-
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 763 |
-
HumanMessage(content=copy_prompt.format(nversions=nversions, min_length=min_length, max_length=max_length, key_features=key_features, structure=structure, copy=copy, included_phrases=included_phrases, excluded_phrases=excluded_phrases)),]
|
| 764 |
|
| 765 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
print('------------')
|
| 767 |
-
|
| 768 |
-
# print("Improving structure")
|
| 769 |
-
# structure = improve_structure(chat=chat, structure=structure)
|
| 770 |
-
messages = [
|
| 771 |
-
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 772 |
-
HumanMessage(content=struct_prompt.format(nversions=nversions, min_length=min_length, max_length=max_length, key_features=key_features, structure=structure, copy=copy, included_phrases=included_phrases, excluded_phrases=excluded_phrases)),]
|
| 773 |
-
print("Chat message", messages[1].content)
|
| 774 |
-
print('------------')
|
| 775 |
-
batch.append(messages)
|
| 776 |
|
| 777 |
-
|
|
|
|
| 778 |
|
| 779 |
descriptions = ""
|
| 780 |
|
| 781 |
descriptions = []
|
| 782 |
descriptions_post = []
|
| 783 |
|
| 784 |
-
if model.startswith("gemini"):
|
| 785 |
-
descriptions =
|
| 786 |
descriptions_post = [post_process(text=desc,
|
| 787 |
guidance_prompt=guidance_prompt,
|
| 788 |
language=languages[i],
|
|
|
|
| 103 |
"Portuguese"]
|
| 104 |
|
| 105 |
models = ["gpt-4o",
|
| 106 |
+
"chatgpt-4o-latest",
|
| 107 |
+
"o3-mini",
|
| 108 |
"claude-3-7-sonnet-latest",
|
| 109 |
"claude-3-5-sonnet-20240620",
|
| 110 |
"claude-3-5-sonnet-20241022",
|
|
|
|
| 388 |
|
| 389 |
<structure>/n{structure}</structure>"""
|
| 390 |
|
| 391 |
+
reasoning_prompt = """
|
| 392 |
You are given information of a product, a reference structure, and a reference copy.
|
| 393 |
Please analyze the structure, make a plan on how to follow the structure correctly.
|
| 394 |
Use the tone of voice of the reference copy if available for the generated description.
|
|
|
|
| 618 |
|
| 619 |
|
| 620 |
def get_model(model_name, temperature=0.0):
|
| 621 |
+
if model_name.startswith("gpt") \
|
| 622 |
+
or model_name.startswith("chatgpt"):
|
| 623 |
chat = ChatOpenAI(model=model_name, max_tokens=4096, temperature=temperature)
|
| 624 |
+
elif model_name.startswith("o3"):
|
| 625 |
+
chat = openai.OpenAI()
|
| 626 |
elif model_name.startswith("claude"):
|
| 627 |
chat = ChatAnthropic(model_name=model_name,
|
| 628 |
anthropic_api_key=os.environ["ANTHROPIC_API_KEY"],
|
|
|
|
| 735 |
if model.startswith("gemini"):
|
| 736 |
if len((structure + copy).strip()) > 0:
|
| 737 |
messages = [
|
| 738 |
+
reasoning_prompt.format(min_length=min_length,
|
| 739 |
max_length=max_length,
|
| 740 |
key_features=key_features,
|
| 741 |
structure=structure,
|
|
|
|
| 748 |
print("Gemini input: ", messages)
|
| 749 |
ri = chat.generate_content(messages)
|
| 750 |
print("Gemini response: ", ri)
|
| 751 |
+
response.append(ri.text)
|
| 752 |
else:
|
| 753 |
+
if model.startswith("o3"):
|
| 754 |
+
messages = [
|
| 755 |
+
{
|
| 756 |
+
"role": "user",
|
| 757 |
+
"content": reasoning_prompt.format(min_length=min_length,
|
| 758 |
+
max_length=max_length,
|
| 759 |
+
key_features=key_features,
|
| 760 |
+
structure=structure,
|
| 761 |
+
copy=copy,
|
| 762 |
+
included_phrases=included_phrases,
|
| 763 |
+
excluded_phrases=excluded_phrases)
|
| 764 |
+
}
|
| 765 |
+
]
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
+
ri = chat.chat.completions.create(
|
| 768 |
+
model="o3-mini",
|
| 769 |
+
messages=messages,
|
| 770 |
+
)
|
| 771 |
+
|
| 772 |
+
print("O3 input: ", messages)
|
| 773 |
+
print("O3 response: ", ri.choices[0].message.content)
|
| 774 |
+
response.append(ri.choices[0].message.content)
|
| 775 |
+
else:
|
| 776 |
+
if len((structure + copy).strip()) > 0:
|
| 777 |
+
if len(copy.strip()) > 0 and len(structure.strip()) > 0:
|
| 778 |
+
print('------------')
|
| 779 |
+
print("Using both copy and structure")
|
| 780 |
+
# print("Improving structure")
|
| 781 |
+
# structure = improve_structure(chat=chat, structure=structure)
|
| 782 |
+
messages = [
|
| 783 |
+
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 784 |
+
HumanMessage(content=struct_copy_prompt.format(nversions=nversions, min_length=min_length, max_length=max_length, key_features=key_features, structure=structure, copy=copy, included_phrases=included_phrases, excluded_phrases=excluded_phrases)),]
|
| 785 |
+
|
| 786 |
+
elif len(copy.strip()) > 0:
|
| 787 |
+
print('------------')
|
| 788 |
+
print("Using copy")
|
| 789 |
+
messages = [
|
| 790 |
+
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 791 |
+
HumanMessage(content=copy_prompt.format(nversions=nversions, min_length=min_length, max_length=max_length, key_features=key_features, structure=structure, copy=copy, included_phrases=included_phrases, excluded_phrases=excluded_phrases)),]
|
| 792 |
+
|
| 793 |
+
elif len(structure.strip()) > 0:
|
| 794 |
+
print('------------')
|
| 795 |
+
print("Using structure")
|
| 796 |
+
# print("Improving structure")
|
| 797 |
+
# structure = improve_structure(chat=chat, structure=structure)
|
| 798 |
+
messages = [
|
| 799 |
+
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 800 |
+
HumanMessage(content=struct_prompt.format(nversions=nversions, min_length=min_length, max_length=max_length, key_features=key_features, structure=structure, copy=copy, included_phrases=included_phrases, excluded_phrases=excluded_phrases)),]
|
| 801 |
+
print("Chat message", messages[1].content)
|
| 802 |
print('------------')
|
| 803 |
+
batch.append(messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
|
| 805 |
+
if not(model.startswith("gemini") or model.startswith("o3")):
|
| 806 |
+
response = chat.batch(batch)
|
| 807 |
|
| 808 |
descriptions = ""
|
| 809 |
|
| 810 |
descriptions = []
|
| 811 |
descriptions_post = []
|
| 812 |
|
| 813 |
+
if model.startswith("gemini") or model.startswith("o3"):
|
| 814 |
+
descriptions = response
|
| 815 |
descriptions_post = [post_process(text=desc,
|
| 816 |
guidance_prompt=guidance_prompt,
|
| 817 |
language=languages[i],
|