Сбер НеСпасибо, [04.08.2024 0:14]
import sys
from PyQt5.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QTextEdit, QComboBox, QPushButton, QLabel, QFrame
)
from PyQt5.QtGui import QPalette, QColor, QFont
from g4f.client import Client

# Допустимые модели ИИ
MODELS = [
    "blackbox", "claude-3-haiku", "nemotron-4-340b-instruct", "command-r+", 
    "mixtral-8x7b", "Phi-3-mini-4k-instruct", "Nous-Hermes-2-Mixtral-8x7B-DPO", 
    "CohereForAI/c4ai-command-r-plus", "databricks/dbrx-instruct", "deepseek-coder", 
    "Qwen2-7B-Instruct", "SparkDesk-v1.1", "deepseek-chat", "meta/meta-llama-3-70b-instruct",
    "meta-llama/Meta-Llama-3-70B-Instruct", "meta-llama/Meta-Llama-3-8B-Instruct", 
    "gpt-4o-mini", "llama-3-8b-instruct", "llama-3-70b-instruct", "llama-3-70b-chat", 
    "llama-3.1-70b-instruct", "llama-3.1-405b-instruct"
]

class ChatApp(QWidget):
    def init(self):
        super().init()
        self.initUI()
        self.client = Client()
    
    def initUI(self):
        self.setWindowTitle('Chat Application')
        self.setGeometry(100, 100, 600, 500)
        
        # Set dark theme
        palette = self.palette()
        palette.setColor(QPalette.Window, QColor(53, 53, 53))
        palette.setColor(QPalette.WindowText, QColor(255, 255, 255))
        palette.setColor(QPalette.Base, QColor(25, 25, 25))
        palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        palette.setColor(QPalette.ToolTipBase, QColor(255, 255, 255))
        palette.setColor(QPalette.ToolTipText, QColor(255, 255, 255))
        palette.setColor(QPalette.Text, QColor(255, 255, 255))
        palette.setColor(QPalette.Button, QColor(53, 53, 53))
        palette.setColor(QPalette.ButtonText, QColor(255, 255, 255))
        palette.setColor(QPalette.BrightText, QColor(255, 0, 0))
        palette.setColor(QPalette.Link, QColor(42, 130, 218))
        self.setPalette(palette)

        layout = QVBoxLayout()

        # Add model selection
        self.model_label = QLabel("Выберите модель ИИ:")
        self.model_label.setFont(QFont("Arial", 12))
        layout.addWidget(self.model_label)
        
        self.model_combo = QComboBox()
        self.model_combo.addItems(MODELS)
        layout.addWidget(self.model_combo)
        
        # Add input field
        self.text_input = QTextEdit()
        self.text_input.setPlaceholderText("Введите ваше сообщение...")
        layout.addWidget(self.text_input)
        
        # Add buttons
        button_layout = QVBoxLayout()
        self.send_button = QPushButton("Отправить")
        self.send_button.clicked.connect(self.get_response)
        button_layout.addWidget(self.send_button)
        
        self.clear_button = QPushButton("Очистить консоль")
        self.clear_button.clicked.connect(self.clear_text)
        button_layout.addWidget(self.clear_button)
        
        layout.addLayout(button_layout)
        
        # Add result display
        self.result_label = QLabel("Результат:")
        self.result_label.setFont(QFont("Arial", 12))
        layout.addWidget(self.result_label)
        
        self.result_display = QTextEdit()
        self.result_display.setReadOnly(True)
        self.result_display.setStyleSheet("background-color: #1e1e1e; color: white;")
        layout.addWidget(self.result_display)
        
        # Add a frame to separate messages
        self.message_frame = QFrame()
        self.message_frame.setFrameShape(QFrame.StyledPanel)
        layout.addWidget(self.message_frame)

Сбер НеСпасибо, [04.08.2024 0:14]
self.setLayout(layout)
    
    def get_response(self):
        user_input = self.text_input.toPlainText().strip()
        if not user_input:
            return
        
        # Display user message
        self.result_display.append(f"<b>Вы:</b> {user_input}")
        
        model = self.model_combo.currentText()
        response = self.client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": user_input}],
        )
        
        # Display AI response with separation
        self.result_display.append(f"<b>ИИ:</b> {response.choices[0].message.content}")
        self.result_display.append("")  # Add an empty line for separation
        self.text_input.clear()
    
    def clear_text(self):
        self.result_display.clear()

if name == "main":
    app = QApplication(sys.argv)
    chat_app = ChatApp()
    chat_app.show()
    sys.exit(app.exec_())

Сбер НеСпасибо, [04.08.2024 0:18]
СДЕЛАЙ КНОПКИ СЕРАМИ, УЛУЧШИ ИНТЕРФЕЙС
СДЕЛАЙ РАЗДЕЛЕНИЕ НА СТРОЧКИ ЧТОБЫ ИИ МОГУ ОТПРАВИТЬ КОД