Skip to content

Commit

Permalink
limit image generation prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
NicklausBrain committed Dec 1, 2024
1 parent 1046cda commit 7afb8d8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions My1kWordsEe/Services/Ai/OpenAiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace My1kWordsEe.Services
public class OpenAiClient
{
public const string ApiSecretKey = "Secrets:OpenAiKey";
public const string Model = "gpt-4o-mini";

private readonly IConfiguration config;
private readonly ILogger logger;
Expand All @@ -31,7 +32,7 @@ public async Task<Result<string>> CompleteAsync(string instructions, string inpu
return Result.Failure<string>("Open AI API key is missing");
};

ChatClient client = new(model: "gpt-4o", this.config[ApiSecretKey]);
ChatClient client = new(model: Model, this.config[ApiSecretKey]);

Check warning on line 35 in My1kWordsEe/Services/Ai/OpenAiClient.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'key' in 'ApiKeyCredential.implicit operator ApiKeyCredential(string key)'.

try
{
Expand Down Expand Up @@ -104,7 +105,9 @@ public static async Task<Result<string>> GetDallEPrompt(this OpenAiClient openAi
return await openAiClient.CompleteAsync(prompt, sentence, new ChatCompletionOptions
{
ResponseFormat = ChatResponseFormat.Text,
Temperature = (float)Math.PI / 2
Temperature = (float)Math.PI / 2,
// limit the number of tokens to avoid long prompts that crush stability ai
MaxTokens = 400,
});
}

Expand Down

0 comments on commit 7afb8d8

Please sign in to comment.