mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-30 01:19:00 +00:00
sync
This commit is contained in:
parent
1119d00e3b
commit
295d644988
70
lollms/functions/prompting/image_gen_prompts.py
Normal file
70
lollms/functions/prompting/image_gen_prompts.py
Normal file
@ -0,0 +1,70 @@
|
||||
# Lollms function call definition file
|
||||
# File Name: get_random_image_gen_prompt.py
|
||||
# Author: ParisNeo
|
||||
# Description: This function returns a random image_gen prompt for various instructional roles. Each prompt includes a title and content that describes the role and its mission.
|
||||
|
||||
# Import necessary libraries
|
||||
import random
|
||||
from typing import Tuple, List, Dict, Any
|
||||
|
||||
# ascii_colors offers advanced console coloring and bug tracing
|
||||
from ascii_colors import trace_exception
|
||||
|
||||
def get_random_image_gen_prompt() -> Tuple[str, str]:
|
||||
"""
|
||||
Returns a random image_gen prompt for various instructional roles.
|
||||
|
||||
Each prompt includes a title and content that describes the role and its mission.
|
||||
|
||||
Returns:
|
||||
Tuple[str, str]: A tuple containing the title and content of the image_gen prompt.
|
||||
"""
|
||||
try:
|
||||
image_gen_prompts = [
|
||||
]
|
||||
|
||||
return random.choice(image_gen_prompts)
|
||||
except Exception as e:
|
||||
return trace_exception(e)
|
||||
|
||||
|
||||
def get_image_gen_prompt(agent_name, number_of_entries=5) -> Tuple[str, str]:
|
||||
"""
|
||||
Returns a random image_gen prompt for various instructional roles.
|
||||
|
||||
Each prompt includes a title and content that describes the role and its mission.
|
||||
|
||||
Returns:
|
||||
Tuple[str, str]: A tuple containing the title and content of the image_gen prompt.
|
||||
"""
|
||||
try:
|
||||
from lollmsvectordb.vector_database import VectorDatabase
|
||||
from lollmsvectordb.lollms_vectorizers.bert_vectorizer import BERTVectorizer
|
||||
from lollmsvectordb.lollms_tokenizers.tiktoken_tokenizer import TikTokenTokenizer
|
||||
db = VectorDatabase("", BERTVectorizer(), TikTokenTokenizer(), number_of_entries)
|
||||
|
||||
image_gen_prompts = [
|
||||
]
|
||||
for entry in image_gen_prompts:
|
||||
db.add_document(entry[0], entry[0])
|
||||
db.build_index()
|
||||
results = db.search(agent_name, number_of_entries)
|
||||
|
||||
return [(r[2],image_gen_prompts[image_gen_prompts.index(r[2])]) for r in results]
|
||||
except Exception as e:
|
||||
return trace_exception(e)
|
||||
|
||||
# Metadata function
|
||||
def get_random_image_gen_prompt_function() -> Dict[str, Any]:
|
||||
"""
|
||||
Returns metadata for the get_random_image_gen_prompt function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Metadata including function name, function itself, description, and parameters.
|
||||
"""
|
||||
return {
|
||||
"function_name": "get_random_image_gen_prompt",
|
||||
"function": get_random_image_gen_prompt,
|
||||
"function_description": "Returns a random image_gen prompt for various instructional roles.",
|
||||
"function_parameters": [] # No parameters needed for this function
|
||||
}
|
@ -5,11 +5,27 @@
|
||||
|
||||
# Import necessary libraries
|
||||
import random
|
||||
from typing import Tuple, List, Dict, Any
|
||||
from typing import Tuple, List, Dict, Any, Optional
|
||||
|
||||
# ascii_colors offers advanced console coloring and bug tracing
|
||||
from ascii_colors import trace_exception
|
||||
|
||||
def find_entry(entries: List[Tuple[str, str]], key: str) -> Optional[Tuple[str, str]]:
|
||||
"""
|
||||
Finds and returns the entry in the list where the first value matches the specified key.
|
||||
|
||||
Args:
|
||||
entries (List[Tuple[str, str]]): The list of tuples to search.
|
||||
key (str): The key to search for in the first value of the tuples.
|
||||
|
||||
Returns:
|
||||
Optional[Tuple[str, str]]: The matching tuple if found, otherwise None.
|
||||
"""
|
||||
for entry in entries:
|
||||
if entry[0] == key:
|
||||
return entry
|
||||
return None
|
||||
|
||||
def get_random_system_prompt() -> Tuple[str, str]:
|
||||
"""
|
||||
Returns a random system prompt for various instructional roles.
|
||||
@ -190,7 +206,7 @@ def get_system_prompt(agent_name, number_of_entries=5) -> Tuple[str, str]:
|
||||
db.build_index()
|
||||
results = db.search(agent_name, number_of_entries)
|
||||
|
||||
return results
|
||||
return [find_entry(system_prompts, r[2]) for r in results]
|
||||
except Exception as e:
|
||||
return trace_exception(e)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user