tmp
This commit is contained in:
@@ -4,8 +4,8 @@ namespace Service.AI;
|
||||
|
||||
public interface IOpenAiService
|
||||
{
|
||||
Task<string?> ChatAsync(string systemPrompt, string userPrompt);
|
||||
Task<string?> ChatAsync(string prompt);
|
||||
Task<string?> ChatAsync(string systemPrompt, string userPrompt, int timeoutSeconds = 15);
|
||||
Task<string?> ChatAsync(string prompt, int timeoutSeconds = 15);
|
||||
IAsyncEnumerable<string> ChatStreamAsync(string systemPrompt, string userPrompt);
|
||||
IAsyncEnumerable<string> ChatStreamAsync(string prompt);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class OpenAiService(
|
||||
ILogger<OpenAiService> logger
|
||||
) : IOpenAiService
|
||||
{
|
||||
public async Task<string?> ChatAsync(string systemPrompt, string userPrompt)
|
||||
public async Task<string?> ChatAsync(string systemPrompt, string userPrompt, int timeoutSeconds = 15)
|
||||
{
|
||||
var cfg = aiSettings.Value;
|
||||
if (string.IsNullOrWhiteSpace(cfg.Endpoint) ||
|
||||
@@ -27,7 +27,7 @@ public class OpenAiService(
|
||||
}
|
||||
|
||||
using var http = new HttpClient();
|
||||
http.Timeout = TimeSpan.FromSeconds(15);
|
||||
http.Timeout = TimeSpan.FromSeconds(timeoutSeconds);
|
||||
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", cfg.Key);
|
||||
|
||||
var payload = new
|
||||
@@ -72,7 +72,7 @@ public class OpenAiService(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string?> ChatAsync(string prompt)
|
||||
public async Task<string?> ChatAsync(string prompt, int timeoutSeconds = 15)
|
||||
{
|
||||
var cfg = aiSettings.Value;
|
||||
if (string.IsNullOrWhiteSpace(cfg.Endpoint) ||
|
||||
@@ -84,7 +84,7 @@ public class OpenAiService(
|
||||
}
|
||||
|
||||
using var http = new HttpClient();
|
||||
http.Timeout = TimeSpan.FromSeconds(60 * 5);
|
||||
http.Timeout = TimeSpan.FromSeconds(timeoutSeconds);
|
||||
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", cfg.Key);
|
||||
|
||||
var payload = new
|
||||
|
||||
Reference in New Issue
Block a user