generated from NetCoreTemplates/blazor-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into leaderboard-update
- Loading branch information
Showing
41 changed files
with
28,545 additions
and
1,968 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
MyApp.ServiceInterface/AiServer/CreateAnswerCommentTaskCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using AiServer.ServiceModel; | ||
using MyApp.Data; | ||
using MyApp.ServiceModel; | ||
using ServiceStack; | ||
|
||
namespace MyApp.ServiceInterface.AiServer; | ||
|
||
public class CreateAnswerCommentTaskCommand(AppConfig appConfig) : IAsyncCommand<CreateAnswerCommentTask> | ||
{ | ||
public const string SystemPrompt = | ||
""" | ||
You are an IT expert helping a user with a technical issue using your computer science, network infrastructure, | ||
and IT security knowledge to solve my problem using data from StackOverflow, Hacker News, and GitHub of content | ||
like issues submitted, closed issues, number of stars on a repository, and overall StackOverflow activity. | ||
I will provide you with my original question and your initial answer attempt to solve my problem and | ||
my follow up questions asking for further explanation and clarification of your answer. | ||
You should use your expertise to provide specific, concise answers to my follow up questions. | ||
"""; | ||
|
||
public async Task ExecuteAsync(CreateAnswerCommentTask request) | ||
{ | ||
var question = request.Question; | ||
|
||
request.AiRef ??= Guid.NewGuid().ToString("N"); | ||
|
||
var answerPrompt = | ||
$""" | ||
## Original Answer Attempt | ||
|
||
{request.Answer.Body} | ||
--- | ||
"""; | ||
|
||
var questionPrompt = CreateAnswerTasksCommand.CreateQuestionPrompt(question); | ||
var openAiChat = new OpenAiChat | ||
{ | ||
Model = request.Model, | ||
Messages = [ | ||
new() { Role = "system", Content = SystemPrompt }, | ||
new() { Role = "user", Content = questionPrompt }, | ||
new() { Role = "assistant", Content = answerPrompt }, | ||
], | ||
Temperature = 0.2, | ||
MaxTokens = 300, | ||
}; | ||
|
||
var modelUser = appConfig.GetModelUser(request.Model); | ||
if (modelUser == null) | ||
throw new ArgumentException("Model User not found: " + request.Model); | ||
|
||
foreach (var comment in request.Comments) | ||
{ | ||
if (comment.CreatedBy == request.UserName) | ||
{ | ||
openAiChat.Messages.Add(new() { Role = "user", Content = comment.Body }); | ||
} | ||
else if (comment.CreatedBy == modelUser.UserName) | ||
{ | ||
openAiChat.Messages.Add(new() { Role = "assistant", Content = comment.Body }); | ||
} | ||
} | ||
openAiChat.Messages.Add(new() { Role = "user", | ||
Content = """ | ||
## Instruction | ||
Answer my follow up question above in a concise manner. | ||
Keep your response on the topic of the original question and answer, directly addressing my specific comment. | ||
Max 2-3 sentences. | ||
""" | ||
}); | ||
|
||
var client = appConfig.CreateAiServerClient(); | ||
|
||
var api = await client.ApiAsync(new CreateOpenAiChat { | ||
RefId = request.AiRef, | ||
Tag = "pvq", | ||
Provider = null, | ||
ReplyTo = appConfig.BaseUrl.CombineWith("api", nameof(AnswerCommentCallback).AddQueryParams(new() { | ||
[nameof(AnswerCommentCallback.AnswerId)] = request.Answer.RefId, | ||
[nameof(AnswerCommentCallback.UserId)] = request.UserId, | ||
[nameof(AnswerCommentCallback.AiRef)] = request.AiRef, | ||
})), | ||
Request = openAiChat | ||
}); | ||
|
||
api.ThrowIfError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.