-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added prompting tips in sidebar * Fixed bugs with prompt help button, moved prompt_tips.py to components * fix tip button placement * use existing function to init client
- Loading branch information
1 parent
253b989
commit 790db7d
Showing
4 changed files
with
102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import openai | ||
from utils.config import get_openai_api_key | ||
from components.chat import initialize_client | ||
|
||
# Initialize the OpenAI client | ||
client = initialize_client() | ||
|
||
def get_prompt_tips(user_prompt, lang): | ||
""" | ||
Generate prompt improvement tips based on the user's input in the specified language. | ||
Args: | ||
user_prompt (str): The prompt submitted by the user. | ||
lang (str): The language to use for generating tips ('English' or 'Deutsch'). | ||
Returns: | ||
str: Two tips for improving the prompt in the specified language. | ||
""" | ||
system_messages = { | ||
"English": """You are an AI assistant specializing in helping journalists improve their prompts for AI-based research and writing. | ||
Analyze the given prompt and provide two concise tips for improvement, focusing on aspects such as: | ||
1. Clarity and specificity | ||
2. Use of few-shot examples | ||
3. Implementing chain-of-thought reasoning | ||
4. Providing necessary context | ||
5. Ethical considerations in journalism | ||
Keep each tip brief and actionable.""", | ||
|
||
"Deutsch": """Sie sind ein KI-Assistent, der sich darauf spezialisiert hat, Journalisten bei der Verbesserung ihrer Prompts für KI-basierte Recherchen und Schreibarbeiten zu unterstützen. | ||
Analysieren Sie den gegebenen Prompt und geben Sie zwei prägnante Tipps zur Verbesserung, wobei Sie sich auf Aspekte wie die folgenden konzentrieren: | ||
1. Klarheit und Spezifität | ||
2. Verwendung von Few-Shot-Beispielen | ||
3. Implementierung von Chain-of-Thought-Reasoning | ||
4. Bereitstellung des notwendigen Kontexts | ||
5. Ethische Überlegungen im Journalismus | ||
Halten Sie jeden Tipp kurz und umsetzbar.""" | ||
} | ||
|
||
user_messages = { | ||
"English": f"Please provide two tips to improve this prompt: '{user_prompt}'", | ||
"Deutsch": f"Bitte geben Sie zwei Tipps zur Verbesserung dieses Prompts: '{user_prompt}'" | ||
} | ||
|
||
response = client.chat.completions.create( | ||
model="gpt-4o", | ||
messages=[ | ||
{"role": "system", "content": system_messages[lang]}, | ||
{"role": "user", "content": user_messages[lang]} | ||
], | ||
max_tokens=150 # Adjust as needed | ||
) | ||
|
||
return response.choices[0].message.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters