Skip to content

Commit

Permalink
Switched to chatgpt3 turbo model which is cheaper
Browse files Browse the repository at this point in the history
  • Loading branch information
madebygps committed Mar 14, 2023
1 parent 27cee12 commit aa61f9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static async Task GenerateCaptions(string videoUrl, int slices, YoutubeExplode.V
caption = track.Captions[k];
if (!string.IsNullOrWhiteSpace(caption.Text))
{
var captionText = caption.Text.Replace('\n',' ');
var captionText = caption.Text.Replace('\n', ' ');
captions += $"{captionText}" + " ";
}
}
Expand All @@ -94,30 +94,31 @@ static async Task GenerateCaptions(string videoUrl, int slices, YoutubeExplode.V
/// Console.WriteLine($"Characters in caption: +{captions.Length}");
//Console.WriteLine($"Max tokens to use: +{captions.Length/4}");

var completionResult = await openAiService.Completions.CreateCompletion(new CompletionCreateRequest()

var completionResult = await openAiService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
{
Prompt = $"(Tell me the main idea of the following text in 15 words: {captions}",
Model = Models.TextDavinciV3,
Temperature = (float?)0.7,
TopP = 1,
MaxTokens = captions.Length / 4,
FrequencyPenalty = (float?)0.93,
PresencePenalty = (float?)1.03
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are a helpful assistant."),
ChatMessage.FromUser(captions + "\n --- \n Summarize the above text in 15 words:"),

},
Model = Models.ChatGpt3_5Turbo
});

if (completionResult.Successful)
{

summary = "";

if (completionResult.Choices.Count == 0)
{
throw new Exception("No Choices");
} else
}
else
{
summary = completionResult.Choices.FirstOrDefault()!.Text;
summary = completionResult.Choices.First().Message.Content;
}

//Console.WriteLine($"Tokens used: {completionResult.Usage.TotalTokens}");

int index = summary.IndexOf("Index =");
if (index >= 0)
{
Expand All @@ -127,12 +128,19 @@ static async Task GenerateCaptions(string videoUrl, int slices, YoutubeExplode.V
}
else
{
if (completionResult.Error == null)
{
throw new Exception("Unknown Error");
}

if (completionResult.Error == null)
{
throw new Exception("Unknown Error");
}
Console.WriteLine($"{completionResult.Error.Code}: {completionResult.Error.Message}");
}


if (endIndex + captionsPerSlice < track.Captions.Count)
{
startIndex = startIndex + captionsPerSlice;
Expand Down
2 changes: 1 addition & 1 deletion timestamper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Betalgo.OpenAI.GPT3" Version="6.6.7" />
<PackageReference Include="Betalgo.OpenAI.GPT3" Version="6.7.3" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
Expand Down

0 comments on commit aa61f9c

Please sign in to comment.