Skip to content

Commit 2570ad5

Browse files
Update ChatGpt.cs with better flow
1 parent 478475a commit 2570ad5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

CSharp/OpenAi/ChatGpt.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ChatGpt()
2323
_httpClient.DefaultRequestHeaders.Add(AcceptHeaderRequest, ApplicationJsonMediaTypeRequest);
2424
}
2525

26-
public async Task<List<string>?> GetReasonsToMyBitch()
26+
public async Task<List<string>> GetReasonsToMyBitch()
2727
{
2828
const string prompt = "Return only a CSV list separated by semicolons, of phrases with various reasons that justify " +
2929
"my delay in leaving work, to my wife. Do not repeat this question in your response. " +
@@ -32,16 +32,16 @@ public ChatGpt()
3232
return await DoRequest(prompt);
3333
}
3434

35-
public async Task<List<string>?> GetExcusesToMyMates()
35+
public async Task<List<string>> GetExcusesToMyBoss()
3636
{
3737
const string prompt = "Return only a CSV list separated by semicolons, of phrases with various reasons that " +
38-
"justify why I can't go out for a drink with my friends. Do not repeat this question in " +
38+
"justify why I can't go out for a drink with my boss. Do not repeat this question in " +
3939
"your response. Only the raw CSV. No double quotes. Just raw CSV";
4040

4141
return await DoRequest(prompt);
4242
}
4343

44-
private async Task<List<string>?> DoRequest(string prompt)
44+
private async Task<List<string>> DoRequest(string prompt)
4545
{
4646
var promptJson = new CompletionChatRequest
4747
{
@@ -58,6 +58,15 @@ public ChatGpt()
5858
var responseContent = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
5959

6060
var response = JsonSerializer.Deserialize<CompletionChatResponse>(responseContent, _serializerOptions);
61-
return response?.Content?.Split(";").ToList();
61+
62+
if (response?.Content != null)
63+
{
64+
return response.Content.Split(";").ToList();
65+
}
66+
67+
return new List<string>
68+
{
69+
"Talk to you later"
70+
};
6271
}
6372
}

0 commit comments

Comments
 (0)