Skip to content

Commit

Permalink
added error messages, adjusted config
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenhuth committed Mar 26, 2023
1 parent 9ec3d84 commit 4515ba3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
59 changes: 44 additions & 15 deletions dalamud-chatgpt/ChatGPTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private void GPTCommand(string command, string args)
private async Task SendPrompt(string input)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configuration.ApiKey);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configKey);

var requestBody = $"{{\"model\": \"{Configuration.Model}\", \"prompt\": \"{input}\", \"max_tokens\": {configuration.MaxTokens}}}";
var requestBody = $"{{\"model\": \"{Configuration.Model}\", \"prompt\": \"{input}\", \"max_tokens\": {configMaxTokens}}}";
var content = new StringContent(requestBody, Encoding.UTF8, "application/json");

var response = await client.PostAsync(Configuration.Endpoint, content);
Expand All @@ -92,11 +92,30 @@ private async Task SendPrompt(string input)
chunks = chunks.ToList();

if(configAdditionalInfo)
chatGui.Print($"ChatGPT \nprompt: {input}\nmodel: {Configuration.Model}\nmax_tokens: {configMaxTokens}\nresponse length: {text.Length}\nchunks: {chunks.Count()}");
chatGui.Print($"ChatGPT>>\nprompt: {input}" +
$"\nmodel: {Configuration.Model}" +
$"\nmax_tokens: {configMaxTokens}" +
$"\nresponse length: {text.Length}" +
$"\nchunks: {chunks.Count()}");

foreach (var chunk in chunks)
chatGui.Print($"ChatGPT: {chunk}");
}
else
{
var errorMessage = "ChatGPT>> Error: text is null";

if (configAdditionalInfo)
{
errorMessage += $"\nmodel: {Configuration.Model}" +
$"\nmax_tokens: {configMaxTokens}" +
$"\nresponse code: {(int) response.StatusCode} - {response.StatusCode}";
}
else
errorMessage += "\nYou can enable additional info in the configuration. If the issue persists, please report it on github.";

chatGui.Print(errorMessage);
}
}

#region configuration
Expand All @@ -108,22 +127,32 @@ private void DrawConfiguration()

ImGui.Begin($"{Name} Configuration", ref drawConfiguration);

ImGui.Separator();
ImGui.Checkbox("remove line breaks from responses", ref configLineBreaks);
ImGui.Checkbox("show additional info", ref configAdditionalInfo);
ImGui.InputInt("max_tokens", ref configMaxTokens);
ImGui.InputText("API Key", ref configKey, 60, ImGuiInputTextFlags.Password);

if (ImGui.Button("Get API Key"))
ImGui.Text("currently used model:");
ImGui.SameLine();
if (ImGui.SmallButton($"GPT-3.5/{Configuration.Model}"))
{
const string modelsDocs = "https://platform.openai.com/docs/models/gpt-3-5";
Util.OpenLink(modelsDocs);
}
ImGui.Spacing();
ImGui.InputText("API key", ref configKey, 60, ImGuiInputTextFlags.Password);
ImGui.SameLine();
if (ImGui.SmallButton("get API key"))
{
const string apiKeysUrl = "https://platform.openai.com/account/api-keys";
Util.OpenLink(apiKeysUrl);
}

ImGui.Separator();



ImGui.Spacing();
ImGui.SliderInt("max_tokens", ref configMaxTokens, 8, 4096);
ImGui.SameLine();
if (ImGui.SmallButton("learn more"))
{
const string conceptsDocs = "https://platform.openai.com/docs/introduction/key-concepts";
Util.OpenLink(conceptsDocs);
}
ImGui.Separator();
ImGui.Checkbox("remove line breaks from responses", ref configLineBreaks);
ImGui.Checkbox("show additional info", ref configAdditionalInfo);
if (ImGui.Button("Save and Close"))
{
SaveConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion dalamud-chatgpt/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace xivgpt
public class Configuration : IPluginConfiguration
{
public int Version { get; set; }
public bool RemoveLineBreaks { get; set; } = false;
public bool RemoveLineBreaks { get; set; }
public bool ShowAdditionalInfo { get; set; }
public string ApiKey { get; set; } = "";
public int MaxTokens { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion dalamud-chatgpt/dalamud-chatgpt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(AppData)\Eisenhuth\DalamudDevPlugins\ChatGPTPlugin\</OutputPath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AssemblyVersion>1.0.4.0</AssemblyVersion>
<AssemblyVersion>1.0.5.0</AssemblyVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<PackageProjectUrl>https://github.com/Eisenhuth/dalamud-chatgpt</PackageProjectUrl>
Expand Down

0 comments on commit 4515ba3

Please sign in to comment.