Funcionando con el markup y el --Chat

This commit is contained in:
Miguel 2024-04-29 11:32:37 +02:00
parent d9ee5208f0
commit fe707ea7fb
3 changed files with 53 additions and 16 deletions

View File

@ -1,12 +1,17 @@
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:md="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml"
xmlns:av="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="av" x:Class="GTPCorrgir.Chat"
Title="Chat with OpenAI" Height="300" Width="300"
ResizeMode="CanResizeWithGrip" WindowStyle="None"
Background="Transparent" AllowsTransparency="True"
MouseEnter="Window_MouseEnter" MouseLeave="Window_MouseLeave" KeyDown="Window_KeyDown"
Opacity="0.8" av:DesignHeight="320.439" av:DesignWidth="609.769">
<Window.Resources>
<md:Markdown x:Key="MarkdownConverter" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
@ -36,25 +41,22 @@
<!-- Área de Respuesta -->
<FlowDocumentScrollViewer Name="markdownViewer" Grid.Row="1" IsReadOnly="True">
<FlowDocumentScrollViewer.Resources>
<md:Markdown x:Key="markdown" />
</FlowDocumentScrollViewer.Resources>
<FlowDocument>
<Paragraph>
<ContentControl Content="{Binding Source={StaticResource markdown}, Path=Transform}"
Content="{Binding YourMarkdownText}"/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
<Grid Grid.Row="1" Margin="1">
<RichTextBox Name="responseArea" IsReadOnly="True" Grid.Row="1">
<RichTextBox.Resources>
<md:Markdown x:Key="Markdown" />
</RichTextBox.Resources>
</RichTextBox>
<Button x:Name="clearButton" Content="Limpiar" Width="40" Height="24"
HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0" Click="clearButton_Click" />
</Grid>
<!-- Área de Pregunta con Botón Superpuesto -->
<Grid Grid.Row="2" Margin="1">
<TextBox x:Name="questionArea" Padding="10"
VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" Background="White" PreviewKeyDown="QuestionArea_PreviewKeyDown"/>
<Button x:Name="sendButton" Content="Enviar" Width="40" Height="24"
HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0" Click="SendButton_Click"/>
HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0" Click="SendButton_Click"/>
</Grid>
</Grid>
</Window>

View File

@ -8,6 +8,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@ -27,13 +28,17 @@ namespace GTPCorrgir
public partial class Chat : Window
{
gtpask AI_API;
string respuestas;
public Chat(gtpask GTP)
{
InitializeComponent();
PositionWindow();
// Inicializar componentes de la UI, por ejemplo, llenar el ComboBox
AI_API = GTP;
questionArea.Text = ""; //GTP.TextoACorregir;
respuestas = "";
foreach (KeyValuePair<LLM_a_Usar, string> kvp in Opciones.Instance.nombreLLM)
{
ComboBoxItem item = new ComboBoxItem();
@ -58,8 +63,6 @@ namespace GTPCorrgir
}
private void Window_MouseEnter(object sender, MouseEventArgs e)
{
// Hacer la ventana opaca cuando el ratón esté sobre ella
@ -117,6 +120,8 @@ namespace GTPCorrgir
{
System.Windows.Clipboard.SetText(AI_API.TextoCorregido);
//responseArea. .Text += AI_API.TextoCorregido + "\r\n";
AddMarkdownContent(AI_API.TextoCorregido + "\r\n");
Mouse.OverrideCursor = null; // Restaurar el cursor normal
sendButton.IsEnabled = true; // Habilitar el botón de envío
}
@ -126,6 +131,30 @@ namespace GTPCorrgir
}
}
public void AddMarkdownContent(string markdownText)
{
// Transforma el texto Markdown a un FlowDocument
var markdown = new Markdown.Xaml.Markdown();
respuestas += markdownText + "\r\n";
responseArea.Document = markdown.Transform(respuestas);
}
private void PositionWindow()
{
// Obtener la posición del cursor
var cursorPosition = System.Windows.Forms.Cursor.Position;
// Determinar en qué pantalla está el cursor
var screen = Screen.FromPoint(cursorPosition);
// Calcular la ubicación central en la pantalla actual
this.Left = (screen.WorkingArea.Width - this.Width) / 2 + screen.WorkingArea.Left;
this.Top = (screen.WorkingArea.Height - this.Height) / 2 + screen.WorkingArea.Top;
}
private void CambiarModelo(object sender, SelectionChangedEventArgs e)
{
ComboBox comboBox = sender as ComboBox;
@ -136,5 +165,11 @@ namespace GTPCorrgir
Opciones.Instance.LLM = selectedEnum; // Suponiendo que hay una propiedad para establecerlo
}
}
private void clearButton_Click(object sender, RoutedEventArgs e)
{
respuestas = "";
AddMarkdownContent("");
}
}
}

View File

@ -39,7 +39,7 @@ namespace GTPCorrgir
{
_instance = new Opciones();
_instance.LLM = LLM_a_Usar.OpenAI;
_instance.modo = modoDeUso.Chat;
_instance.modo = modoDeUso.Corregir;
}
return _instance;
}