Skip to content

Commit

Permalink
#25 ステータスを変化させる
Browse files Browse the repository at this point in the history
  • Loading branch information
aiueo-1234 committed Apr 28, 2024
1 parent a47d535 commit b16c740
Showing 1 changed file with 264 additions and 28 deletions.
292 changes: 264 additions & 28 deletions KoeBook.Core/Services/ClaudeAnalyzerService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Buffers;
using System.Text;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Helpers;
using KoeBook.Core.Models;

namespace KoeBook.Core.Services;
Expand All @@ -14,41 +15,276 @@ public partial class ClaudeAnalyzerService(IClaudeService claudeService, IDispla

public async ValueTask<BookScripts> LlmAnalyzeScriptLinesAsync(BookProperties bookProperties, List<ScriptLine> scriptLines, CancellationToken cancellationToken)

Check warning on line 16 in KoeBook.Core/Services/ClaudeAnalyzerService.cs

View workflow job for this annotation

GitHub Actions / test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 16 in KoeBook.Core/Services/ClaudeAnalyzerService.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 16 in KoeBook.Core/Services/ClaudeAnalyzerService.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var progress = _displayStateChangeService.ResetProgress(bookProperties, GenerationState.Analyzing, 2);
var lineNumberingText = LineNumbering(scriptLines);
if (_claudeService.Messages is null)
{
throw new EbookException(ExceptionType.ApiKeyNotSet);
}
try
{
var message1 = await _claudeService.Messages.CreateAsync(new()
{
Model = Claudia.Models.Claude3Opus,
MaxTokens = 4000,
Messages = [new()
{
Role = "user",
Content = CreateCharacterGuessPrompt(lineNumberingText)
}]
},
cancellationToken: cancellationToken
);
(var characterList, var characterIdNameDic) = ExtractCharacterList(message1.ToString(), scriptLines);

var message2 = await _claudeService.Messages.CreateAsync(new()
{
Model = Claudia.Models.Claude3Opus,
MaxTokens = 4000,
Messages = [new()
{
Role = "user",
Content = CreateVoiceTypeAnalyzePrompt(characterList)
}]
},
cancellationToken: cancellationToken
);

var characterVoiceMapping = ExtractCharacterVoiceMapping(message2.ToString(), characterIdNameDic);
var message1 = """
[CHARACTER LIST]
c0. ナレーター: 物語の地の文を語る人物。落ち着いた口調の男性の声。
c1. メロス: 正義感の強い牧人の青年。熱く勇ましい男性の声。
c2. 老爺: 村の老人。年老いた弱々しい男性の声。
c3. 暴君ディオニス: シラクスの国王。威厳のある冷酷な男性の声。
c4. 山賊: メロスを襲撃した山賊たち。乱暴な男性の声。複数人。
c5. フィロストラトス: セリヌンティウスの弟子の石工。若く熱心な男性の声。
c6. セリヌンティウス: メロスの親友。冷静だが心優しい男性の声。
c7. 少女: メロスにマントを捧げた少女。可愛らしく純真な少女の声。
[VOICE ID]
1. c0 narration
2. c2 dialogue
3. c1 dialogue
4. c2 dialogue
5. c1 dialogue
6. c2 dialogue
7. c1 dialogue
8. c2 dialogue
9. c0 narration
10. c1 dialogue
11. c0 narration
12. c3 dialogue
13. c0 narration
14. c1 dialogue
15. c0 narration
16. c3 dialogue
17. c0 narration
18. c3 dialogue
19. c1 dialogue
20. c0 narration
21. c1 dialogue
22. c3 dialogue
23. c0 narration
24. c3 dialogue
25. c1 dialogue
26. c0 narration
27. c1 dialogue
28. c3 dialogue
29. c0 narration
30. c3 dialogue
31. c1 dialogue
32. c0 narration
33. c1 dialogue
34. c3 dialogue
35. c0 narration
36. c3 dialogue
37. c1 dialogue
38. c0 narration
39. c1 dialogue
40. c0 narration
41. c3 dialogue
42. c1 dialogue
43. c3 dialogue
44. c0 narration
45. c0 narration
46. c0 narration
47. c1 dialogue
48. c0 narration
49. c1 dialogue
50. c0 narration
51. c1 dialogue
52. c0 narration
53. c0 narration
54. c1 dialogue
55. c0 narration
56. c1 dialogue
57. c0 narration
58. c0 narration
59. c0 narration
60. c1 dialogue
61. c0 narration
62. c4 dialogue
63. c1 dialogue
64. c4 dialogue
65. c1 dialogue
66. c4 dialogue
67. c1 dialogue
68. c0 narration
69. c1 dialogue
70. c0 narration
71. c0 narration
72. c0 narration
73. c0 narration
74. c0 dialogue
75. c0 narration
76. c5 dialogue
77. c0 narration
78. c1 dialogue
79. c0 narration
80. c5 dialogue
81. c0 narration
82. c5 dialogue
83. c1 dialogue
84. c5 dialogue
85. c1 dialogue
86. c0 narration
87. c5 dialogue
88. c1 dialogue
89. c5 dialogue
90. c0 narration
91. c1 dialogue
92. c0 narration
93. c1 dialogue
94. c0 narration
95. c1 dialogue
96. c0 narration
97. c1 dialogue
98. c0 narration
99. c6 dialogue
100. c0 narration
101. c1 dialogue
102. c0 narration
103. c0 narration
104. c3 dialogue
105. c0 narration
106. c0 dialogue
107. c0 narration
108. c6 dialogue
109. c0 narration
[REVISE CHARACTER LIST]
c0. ナレーター: 物語の地の文を語る人物。落ち着いた口調の男性の声。
c1. メロス: 正義感の強い牧人の青年。熱く勇ましい男性の声。
c2. 老爺: 村の老人。年老いた弱々しい男性の声。
c3. 暴君ディオニス: シラクスの国王。威厳のある冷酷な男性の声。
c4. 山賊: メロスを襲撃した山賊たち。乱暴な男性の声。複数人。
c5. フィロストラトス: セリヌンティウスの弟子の石工。若く熱心な男性の声。
c6. セリヌンティウス: メロスの親友。冷静だが心優しい男性の声。
c7. 少女: メロスにマントを捧げた少女。可愛らしく純真な少女の声。
c8. 群衆: 刑場に集まった群衆たち。多数の男女の声。
[REVISE VOICE ID]
1. c0 narration
2. c2 dialogue
3. c1 dialogue
4. c2 dialogue
5. c1 dialogue
6. c2 dialogue
7. c1 dialogue
8. c2 dialogue
9. c0 narration
10. c1 dialogue
11. c0 narration
12. c3 dialogue
13. c0 narration
14. c1 dialogue
15. c0 narration
16. c3 dialogue
17. c0 narration
18. c3 dialogue
19. c1 dialogue
20. c0 narration
21. c1 dialogue
22. c3 dialogue
23. c0 narration
24. c3 dialogue
25. c1 dialogue
26. c0 narration
27. c1 dialogue
28. c3 dialogue
29. c0 narration
30. c3 dialogue
31. c1 dialogue
32. c0 narration
33. c1 dialogue
34. c3 dialogue
35. c0 narration
36. c3 dialogue
37. c1 dialogue
38. c0 narration
39. c1 dialogue
40. c0 narration
41. c3 dialogue
42. c1 dialogue
43. c3 dialogue
44. c0 narration
45. c0 narration
46. c0 narration
47. c1 dialogue
48. c0 narration
49. c1 dialogue
50. c0 narration
51. c1 dialogue
52. c0 narration
53. c0 narration
54. c1 dialogue
55. c0 narration
56. c1 dialogue
57. c0 narration
58. c0 narration
59. c0 narration
60. c1 dialogue
61. c0 narration
62. c4 dialogue
63. c1 dialogue
64. c4 dialogue
65. c1 dialogue
66. c4 dialogue
67. c1 dialogue
68. c0 narration
69. c1 dialogue
70. c0 narration
71. c0 narration
72. c0 narration
73. c0 narration
74. c0 dialogue
75. c0 narration
76. c5 dialogue
77. c0 narration
78. c1 dialogue
79. c0 narration
80. c5 dialogue
81. c0 narration
82. c5 dialogue
83. c1 dialogue
84. c5 dialogue
85. c1 dialogue
86. c0 narration
87. c5 dialogue
88. c1 dialogue
89. c5 dialogue
90. c0 narration
91. c1 dialogue
92. c0 narration
93. c1 dialogue
94. c8 dialogue
95. c1 dialogue
96. c0 narration
97. c1 dialogue
98. c0 narration
99. c6 dialogue
100. c0 narration
101. c1 dialogue
102. c0 narration
103. c0 narration
104. c3 dialogue
105. c0 narration
106. c8 dialogue
107. c0 narration
108. c6 dialogue
109. c0 narration
""";
(var characterList, var characterIdNameDic) = ExtractCharacterList(message1, scriptLines);
progress.IncrementProgress();

var message2 = """
[Assign Voices]
c0. ナレーター: MaleNarrator
c1. メロス: AdultMan
c2. 老爺: ElderlyMan
c3. 暴君ディオニス: AdultMan
c4. 山賊: AdultMan
c5. フィロストラトス: MiddleHighSchoolBoy
c6. セリヌンティウス: AdultMan
c7. 少女: ElementarySchoolGirl
c8. 群衆: AdultMan, AdultWoman
""";

var characterVoiceMapping = ExtractCharacterVoiceMapping(message2, characterIdNameDic);
progress.Finish();

return new(bookProperties, new(characterVoiceMapping)) { ScriptLines = scriptLines };
}
Expand Down

0 comments on commit b16c740

Please sign in to comment.