Spaces:
Sleeping
Sleeping
Create cae.py
Browse files
cae.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
class CriticalAnalysisExpert:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.openai_api_key = os.environ.get("OPENAI_API_KEY") # Load OpenAI API key - **CAE هم اکنون از OpenAI API استفاده میکند**
|
| 7 |
+
openai.api_key = self.openai_api_key
|
| 8 |
+
self.model_name = "gpt-4o" # Specify GPT-4o model - **CAE هم اکنون از GPT-4o استفاده میکند**
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def analyze_outputs(self, chatbot_prompt, knowledge_base, faq_section):
|
| 12 |
+
prompt_critique_suggestions = self._analyze_chatbot_prompt(chatbot_prompt)
|
| 13 |
+
knowledge_base_critique_suggestions = self._analyze_knowledge_base(knowledge_base)
|
| 14 |
+
faq_section_critique_suggestions = self._analyze_faq_section(faq_section)
|
| 15 |
+
return prompt_critique_suggestions, knowledge_base_critique_suggestions, faq_section_critique_suggestions
|
| 16 |
+
|
| 17 |
+
def _analyze_chatbot_prompt(self, chatbot_prompt):
|
| 18 |
+
# **[محل پیادهسازی منطق تحلیل انتقادی پرامپت با استفاده از API ChatGPT و GPT-4o و پرامپت CAE نهایی - برای GPT-4o]**
|
| 19 |
+
# جایگزین placeholder با کد واقعی تحلیل انتقادی پرامپت (برای GPT-4o)
|
| 20 |
+
critique_prompt = f"""
|
| 21 |
+
Critique the following chatbot prompt:
|
| 22 |
+
|
| 23 |
+
{chatbot_prompt}
|
| 24 |
+
|
| 25 |
+
Provide detailed critique and suggestions for improvement in Persian.
|
| 26 |
+
"""
|
| 27 |
+
response = openai.ChatCompletion.create( # استفاده از openai.ChatCompletion.create به جای Gemini API
|
| 28 |
+
model=self.model_name,
|
| 29 |
+
messages=[
|
| 30 |
+
{"role": "user", "content": critique_prompt}
|
| 31 |
+
]
|
| 32 |
+
)
|
| 33 |
+
return response.choices[0].message.content # Return critique and suggestions as text
|
| 34 |
+
|
| 35 |
+
def _analyze_knowledge_base(self, knowledge_base):
|
| 36 |
+
# **[محل پیادهسازی منطق تحلیل انتقادی پایگاه دانش با استفاده از API ChatGPT و GPT-4o و پرامپت CAE نهایی - برای GPT-4o]**
|
| 37 |
+
# جایگزین placeholder با کد واقعی تحلیل انتقادی پایگاه دانش (برای GPT-4o)
|
| 38 |
+
critique_prompt = f"""
|
| 39 |
+
Critique the following knowledge base:
|
| 40 |
+
|
| 41 |
+
{knowledge_base}
|
| 42 |
+
|
| 43 |
+
Provide detailed critique and suggestions for improvement in Persian.
|
| 44 |
+
"""
|
| 45 |
+
response = openai.ChatCompletion.create( # استفاده از openai.ChatCompletion.create به جای Gemini API
|
| 46 |
+
model=self.model_name,
|
| 47 |
+
messages=[
|
| 48 |
+
{"role": "user", "content": critique_prompt}
|
| 49 |
+
]
|
| 50 |
+
)
|
| 51 |
+
return response.choices[0].message.content # Return critique and suggestions as text
|
| 52 |
+
|
| 53 |
+
def _analyze_faq_section(self, faq_section):
|
| 54 |
+
# **[محل پیادهسازی منطق تحلیل انتقادی بخش FAQ با استفاده از API ChatGPT و GPT-4o و پرامپت CAE نهایی - برای GPT-4o]**
|
| 55 |
+
# جایگزین placeholder با کد واقعی تحلیل انتقادی بخش FAQ (برای GPT-4o)
|
| 56 |
+
critique_prompt = f"""
|
| 57 |
+
Critique the following FAQ section:
|
| 58 |
+
|
| 59 |
+
{faq_section}
|
| 60 |
+
|
| 61 |
+
Provide detailed critique and suggestions for improvement in Persian.
|
| 62 |
+
"""
|
| 63 |
+
response = openai.ChatCompletion.create( # استفاده از openai.ChatCompletion.create به جای Gemini API
|
| 64 |
+
model=self.model_name,
|
| 65 |
+
messages=[
|
| 66 |
+
{"role": "user", "content": critique_prompt}
|
| 67 |
+
]
|
| 68 |
+
)
|
| 69 |
+
return response.choices[0].message.content # Return critique and suggestions as text
|