added chatgpt3.5 api
This commit is contained in:
parent
ac8b51031b
commit
cb5842a32b
@ -1,5 +1,22 @@
|
||||
namespace LLMApi.Data.Contracts.ChatGpt3_5;
|
||||
|
||||
public record ChatCompletionResponse(
|
||||
string Id
|
||||
string Id,
|
||||
string Object,
|
||||
int Created,
|
||||
string Model,
|
||||
Choice[] Choices,
|
||||
Usage Usage
|
||||
);
|
||||
|
||||
public record Choice(
|
||||
int Index,
|
||||
Message Message,
|
||||
string FinishReason
|
||||
);
|
||||
|
||||
public record Usage(
|
||||
int PromptTokens,
|
||||
int CompletionTokens,
|
||||
int TotalTokens
|
||||
);
|
@ -9,7 +9,10 @@ public class ChatGpt3_5Service : ILlmApiService
|
||||
private readonly HttpClient _client;
|
||||
private static readonly JsonSerializerSettings jsonSerializerSettings = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
ContractResolver = new DefaultContractResolver()
|
||||
{
|
||||
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
}
|
||||
};
|
||||
private const string API_TOKEN = "";
|
||||
private const string VERSION_IDENTIFIER = "gpt-3.5-turbo";
|
||||
@ -31,14 +34,13 @@ public class ChatGpt3_5Service : ILlmApiService
|
||||
new("user", "Hello!"),
|
||||
});
|
||||
|
||||
// var serialzed = JsonConvert.SerializeObject(requestContract, jsonSerializerSettings);
|
||||
|
||||
var response = await _client.PostAsJsonAsync("/v1/chat/completions", requestContract);
|
||||
|
||||
Console.WriteLine(await response.Content.ReadAsStringAsync());
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(await response.RequestMessage.Content.ReadAsStringAsync());
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return JsonConvert.SerializeObject(response);
|
||||
var obj = JsonConvert.DeserializeObject<ChatCompletionResponse>(content, jsonSerializerSettings);
|
||||
|
||||
return obj!.ToString() + Environment.NewLine + string.Join(", ", obj!.Choices.Select(c => c.ToString()));
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user