Compare commits
3 Commits
237d42dba3
...
2342c838e5
Author | SHA1 | Date |
---|---|---|
oijkn | 2342c838e5 | |
Fatih Kadir Akın | b82b3854cb | |
oijkn | c0dda07665 |
|
@ -2,14 +2,17 @@
|
|||
|
||||
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
|
||||
|
||||
|
||||
<h2 align="center">Sponsors</h2>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://clemta.com" align="center" target="_blank">
|
||||
<img height="50" alt="Clemta logo" src="https://clemta.com/wp-content/uploads/2023/03/logo-clemta-com-1.png.webp">
|
||||
</a>
|
||||
<br>
|
||||
<br><br>
|
||||
<a href="https://llmchat.co" align="center" target="_blank">
|
||||
<img height="25" alt="LLMChat" src="https://github.com/user-attachments/assets/78bf6b22-234c-4ee2-a484-869e749eef42">
|
||||
</a>
|
||||
<br><sub><a href="https://git.new/llmchat" target="_blank">https://git.new/llmchat</a></sub><br><br>
|
||||
<a href="https://hf.co/chat" align="center" target="_blank">
|
||||
<img height="60" alt="Hugging Face logo" src="https://github.com/user-attachments/assets/4187ef06-7cae-402a-a410-e0a999758fed">
|
||||
</a>
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PromptFinder:
|
||||
"""
|
||||
A class to search for prompts based on a given action from a CSV file.
|
||||
"""
|
||||
|
||||
def __init__(self, csv_file_path=None):
|
||||
"""
|
||||
Initialize the PromptFinder with a CSV file path.
|
||||
"""
|
||||
self.csv_file_path = csv_file_path or self.get_default_csv_path()
|
||||
if self.csv_file_path is None:
|
||||
sys.exit("Error: CSV file not found in default paths or specified path.")
|
||||
try:
|
||||
self.df = pd.read_csv(self.csv_file_path)
|
||||
except FileNotFoundError:
|
||||
sys.exit(f"Error: CSV file '{self.csv_file_path}' not found.")
|
||||
|
||||
@staticmethod
|
||||
def get_default_csv_path():
|
||||
"""
|
||||
Returns the first existing default CSV path, or None if none found.
|
||||
"""
|
||||
default_paths = ["../prompts.csv", "./prompts.csv"]
|
||||
return next((path for path in default_paths if os.path.exists(path)), None)
|
||||
|
||||
def find_prompt(self, search_string):
|
||||
"""
|
||||
Find prompts based on the search_string.
|
||||
:param search_string: The action to search for in the CSV.
|
||||
:return: The found prompts or a message if no prompt is found.
|
||||
"""
|
||||
filtered_df = self.df[
|
||||
self.df["act"].str.lower().str.contains(search_string.lower())
|
||||
]
|
||||
if len(filtered_df) > 0:
|
||||
return filtered_df[["act", "prompt"]]
|
||||
else:
|
||||
return f"No prompt found for '{search_string}'."
|
||||
|
||||
@staticmethod
|
||||
def display_and_select_prompt(results):
|
||||
"""
|
||||
Display prompts and allow user to select one.
|
||||
:param results: DataFrame of found prompts.
|
||||
"""
|
||||
try:
|
||||
if isinstance(results, str):
|
||||
print(results) # No prompt found
|
||||
elif len(results) == 1:
|
||||
# Automatically select if only one prompt is found
|
||||
return results.iloc[0]["prompt"]
|
||||
else:
|
||||
for idx, row in enumerate(results.itertuples(), 1): # Use enumerate for sequential numbering
|
||||
print(f"{idx}. {row.act}: {row.prompt}")
|
||||
choice = int(input("Select a prompt number: "))
|
||||
return results.iloc[choice - 1]["prompt"]
|
||||
except KeyboardInterrupt:
|
||||
print("\nOperation cancelled by the user.")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
csv_file_path = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
prompt_finder = PromptFinder(csv_file_path)
|
||||
|
||||
if not sys.stdin.isatty():
|
||||
act_to_search = sys.stdin.readline().strip()
|
||||
else:
|
||||
act_to_search = input("Enter the ACT to search for: ")
|
||||
|
||||
found_prompts = prompt_finder.find_prompt(act_to_search)
|
||||
if isinstance(found_prompts, str):
|
||||
print(found_prompts)
|
||||
else:
|
||||
selected_prompt = prompt_finder.display_and_select_prompt(found_prompts)
|
||||
print(f"Selected Prompt: {selected_prompt}")
|
||||
except KeyboardInterrupt:
|
||||
print("\nScript interrupted by the user.")
|
||||
sys.exit(0)
|
Loading…
Reference in New Issue