Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mehaifeng committed Jan 9, 2023
0 parents commit 0ca158b
Show file tree
Hide file tree
Showing 733 changed files with 8,323 additions and 0 deletions.
9 changes: 9 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="VisualChatBot.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VisualChatBot"
StartupUri="Views/VisualChat.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace VisualChatBot
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Binary file added Assets/Fonts/iconfont.ttf
Binary file not shown.
69 changes: 69 additions & 0 deletions Assets/Styles/DefaultStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate TargetType="Button" x:Key="WindowControlButtomTemplate">
<Border
Name="Typebutton"
Background="{x:Null}">
<TextBlock
Text="{Binding Content,RelativeSource={RelativeSource AncestorType=Button,Mode=FindAncestor}}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontFamily="../Fonts/#iconfont"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Typebutton" Property="Background" Value="#44FFFFFF"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Typebutton" Property="Background" Value="#22FFFFFF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate TargetType="Button" x:Key="ConfirmButtonTemplate">
<Border
x:Name="borderBack"
Cursor="Hand"
CornerRadius="5"
BorderBrush="LightGray"
BorderThickness="1">
<TextBlock
x:Name="ButtonName"
Text="{Binding Content, RelativeSource={RelativeSource AncestorType=Button,Mode=FindAncestor}}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="Black"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="borderBack" Property="Background" Value="#C0C0C0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate TargetType="ToggleButton" x:Key="ToggleButtonTemplate">
<Border>
<TextBlock
Text="{Binding Content, RelativeSource={RelativeSource AncestorType=ToggleButton,Mode=FindAncestor}}"
FontFamily="../Fonts/#iconfont"/>
</Border>
</ControlTemplate>
<ControlTemplate TargetType="Button" x:Key="MenuBtnTemplate">
<Border
x:Name="borderBack"
Cursor="Hand"
BorderBrush="LightGray"
BorderThickness="0,0,0,1">
<TextBlock
x:Name="ButtonName"
Text="{Binding Content, RelativeSource={RelativeSource AncestorType=Button,Mode=FindAncestor}}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="Black"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="borderBack" Property="Background" Value="#C0C0C0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ResourceDictionary>
68 changes: 68 additions & 0 deletions Models/HttpGetModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VisualChatBot.Models
{
class HttpGetModel
{
[JsonProperty("id")]
public string? Id { get; set; }

[JsonProperty("object")]
public string? Object { get; set; }

[JsonProperty("created")]
public string? Created { get; set; }

[JsonProperty("model")]
public string? Model { get; set; }

[JsonProperty("choices")]
public List<Choices>? Choicese { get; set; }

[JsonProperty("usage")]
public Usage? Usages { get; set; }

[JsonProperty("error")]
public ErrorInfo? error { get; set; }

public class Choices
{
[JsonProperty("text")]
public string? Text { get; set; }
[JsonProperty("index")]
public string? Index { get; set; }
[JsonProperty("logprobs")]
public string? Logprobs { get; set; }
[JsonProperty("finish_reson")]
public string? Finish_reson { get; set; }
}
public class Usage
{
[JsonProperty("prompt_tokens")]
public string? Prompt_tokens { get; set; }
[JsonProperty("completion_tokens")]
public string? Completion_tokens { get; set; }
[JsonProperty("total_tokens")]
public string? Total_tokens { get; set; }
}
public class ErrorInfo
{
[JsonProperty("message")]
public string? message { get; set; }

[JsonProperty("type")]
public string? type { get; set; }

[JsonProperty("param")]
public string? param { get; set; }

[JsonProperty("code")]
public string? code { get; set; }
}
}
}
44 changes: 44 additions & 0 deletions Tools/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using VisualChatBot.Models;

namespace VisualChatBot.Tools
{
public class WebRequest
{
public async Task<string?> WebRequestMethon(string apikey,string requestUrl,StringContent input)
{
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apikey}");
var response = await client.PostAsync(requestUrl, input);
response.Content.Headers.ContentLength = 1024;
var responseContent = await response.Content.ReadAsStringAsync();
var responType = new HttpGetModel();
responType = JsonConvert.DeserializeObject<HttpGetModel>(responseContent);
if (response.IsSuccessStatusCode == false)
{
string errorInfo = $"\n错误类型:{responType.error.type}\n错误内容:{responType.error.message}\n\n";
return errorInfo;
}

// 返回接收到的内容
return await Task.FromResult(result: responType?.Choicese?.First().Text);
}
}
catch(Exception ex)
{
return $"\n错误:\n{ex}\n";
}
}
}
}
Loading

0 comments on commit 0ca158b

Please sign in to comment.