Skip to content

Commit

Permalink
Merge pull request #13 from Tauffer-Consulting/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vinicvaz authored Jan 18, 2024
2 parents 6a12755 + 390e20d commit ac185b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pieces/PromptCreatorForImageGeneratorPiece/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class InputModel(BaseModel):
"""
context: str = Field(
...,
description="The context to generate an image from"
description="The context to generate an image from",
)
art_style: str = Field(
default="You know many art styles, so you always vary a lot on your suggestions!",
description="The art style to generate an image from. Your imagination is the limit!"
description="Realistic"
)
output_type: OutputTypeType = Field(
default=OutputTypeType.string,
description="The type of output to return"

)
openai_model: LLMModelType = Field(
default=LLMModelType.gpt_3_5_turbo,
Expand Down Expand Up @@ -67,7 +67,7 @@ class OutputModel(BaseModel):
class SecretsModel(BaseModel):
"""
PromptCreatorForImageGeneratorPiece secrets model
"""
"""
OPENAI_API_KEY: str = Field(
description="Your OpenAI API key"
)
21 changes: 13 additions & 8 deletions pieces/PromptCreatorForImageGeneratorPiece/piece.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@ def piece_function(self, input_data: InputModel, secrets_data: SecretsModel):
client = OpenAI(api_key=secrets_data.OPENAI_API_KEY)

template = """You have access to an AI that generates images through text prompts.
Your function is to write a prompt for this AI from a given context. It is very importat that the maximum size of the output prompt must be 1000 characters.
Keep in mind that the AI generating images has no knowledge of the context you've been given. Therefore, it's crucial to include all the important information in the prompt you generate.
You always write a short prompt that is designed to help the image generator AI create an image for the given context.
You are very good at writing these text prompts for any context that is given to you.
You're very creative in how you describe the context you've been given, and like to vary the mood that runs through the prompt you've written.
You always suggest some specific art style for the AI to create the image.
For this one the art style would be: {art_style}
Now, create a prompt to help the image generator AI to create an image for this context:
Your function is to write a prompt for this AI from a given context.
It is very importat that the prompt be very sucint and direct, around 30 to 100 characters.
Examples of prompts:
- Cartoon of a dog playing with a ball in the park.
- A painting of a sunset in the mountains.
- Portrait of a child playing in a park, using natural lighting and candid expressions.
- Capture a street performer in action amidst a bustling city. Use a blurred background to emphasize the subject and show movement.
- Create a stylized portrait of an entrepreneur against a city skyline. Use dramatic lighting and post-processing techniques to create a futuristic look.
- Illustrate a lone lighthouse standing against the vibrant colors of a sunset. Emphasize the contrasting elements, such as the lighthouse’s solidity against the ephemeral beauty of the sunset.
VERY IMPORTANT: The output must be ONLY and ONLY the prompt, nothing else (no title, no description, no context, no nothing).
Context:
{context}"""

prompt = template.format(art_style=input_data.art_style, context=input_data.context)
self.logger.info(f"Generating prompt")
generated_prompt = self.openai_response(input_data, prompt, client)

generated_prompt = f"{generated_prompt}\n\nUse the art style: {input_data.art_style}"

if input_data.output_type == "string":
self.logger.info("Returning prompt as a string")
self.format_display_result(input_data, generated_prompt)
Expand Down
2 changes: 1 addition & 1 deletion pieces/TextGeneratorPiece/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class InputModel(BaseModel):
description="OpenAI model name."
)
completion_max_tokens: int = Field(
default=500,
default=500,
description="The maximum number of tokens in the generated text."
)
temperature: float = Field(
Expand Down
8 changes: 4 additions & 4 deletions pieces/TextSummarizerPiece/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class InputModel(BaseModel):
"""
TextSummarizerPiece Input model
"""
text: Optional[str] = Field(
default=None,
text: str = Field(
default="",
description="Text to summarize",
json_schema_extra={
'widget': "textarea",
}
)
text_file_path: Optional[str] = Field(
default=None,
text_file_path: str = Field(
default="",
description="Use it only if not using text field. File path to the text to summarize",
json_schema_extra={
"from_upstream": "always"
Expand Down

0 comments on commit ac185b3

Please sign in to comment.