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