찾다가 없어서 템플릿 하나 만들어봤습니다 둘다 챗api기준입니다.
둘다 출력은 json이니 역직렬화해서 사용하시면 될거같습니다.
GPT:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
string json = @"{""model"":""모델이름 예)gpt-3.5-turbo"",""temperature"":0.5,""n"":1,""messages"":[{""role"":""system"",""content"":""모델초기화 예)you are a helpful assistant""},{""role"":""user"",""content"":""전 메세지 예)hi""},{""role"":""assistant"",""content"":""모델 메세지 예)hi can i help you?""},{""role"":""user"",""content"":""메세지 예)yes, where is your mother?""}]}";
var response = await client.PostAsync("https://api.openai.com/v1/chat/completions", new StringContent(json, System.Text.Encoding.UTF8, "application/json"));
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
Palm2:
using (var client = new HttpClient())
{
var url = $"https://generativelanguage.googleapis.com/v1beta2/models/{"모델이름 예)chat-bison-001"}:generateMessage?key={apiKey}";
var content = new StringContent(@"{""prompt"": {""messages"": [{""content"":""메세지 예)hi""}], ""context"": ""모델초기화 예)you are a helpful assistant"", ""examples"":[{""input"":{""content"":""전 메세지 예)yes, where is your mother?""},""output"":{""content"":""전 모델 메세지 예)hi! can i help you?""}}]}}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
참고로 전 메세지라는건 그전에 어떤 말을 했는지 캐싱이 안되니까 있는거라 옵션입니다
이게뭔데