@@ -11,6 +11,21 @@ interface FormState {
1111const ChatSchema = z . object ( {
1212 userQuestion : z . string ( ) . min ( 1 , { message : "メッセージを入力してください。" } ) ,
1313 documentContent : z . string ( ) . min ( 1 , { message : "コンテキストとなるドキュメントがありません。" } ) ,
14+ replOutputs : z . array ( z . object ( {
15+ command : z . string ( ) ,
16+ output : z . array ( z . object ( {
17+ type : z . enum ( [ "stdout" , "stderr" , "error" , "return" , "trace" , "system" ] ) ,
18+ message : z . string ( ) ,
19+ } ) ) ,
20+ } ) ) . optional ( ) ,
21+ fileContents : z . array ( z . object ( {
22+ name : z . string ( ) ,
23+ content : z . string ( ) ,
24+ } ) ) . optional ( ) ,
25+ execResults : z . record ( z . string ( ) , z . array ( z . object ( {
26+ type : z . enum ( [ "stdout" , "stderr" , "error" , "return" , "trace" , "system" ] ) ,
27+ message : z . string ( ) ,
28+ } ) ) ) . optional ( ) ,
1429} ) ;
1530
1631type ChatParams = z . input < typeof ChatSchema > ;
@@ -25,22 +40,62 @@ export async function askAI(params: ChatParams): Promise<FormState> {
2540 } ;
2641 }
2742
28- const { userQuestion, documentContent } = parseResult . data ;
43+ const { userQuestion, documentContent, replOutputs , fileContents , execResults } = parseResult . data ;
2944
3045 try {
46+ // ターミナルログの文字列を構築
47+ let terminalLogsSection = "" ;
48+ if ( replOutputs && replOutputs . length > 0 ) {
49+ terminalLogsSection = "\n# ターミナルのログ(ユーザーが入力したコマンドとその実行結果)\n" ;
50+ for ( const replCmd of replOutputs ) {
51+ terminalLogsSection += `\n## コマンド: ${ replCmd . command } \n` ;
52+ terminalLogsSection += "```\n" ;
53+ for ( const output of replCmd . output ) {
54+ terminalLogsSection += `${ output . message } \n` ;
55+ }
56+ terminalLogsSection += "```\n" ;
57+ }
58+ }
59+
60+ // ファイルエディターの内容を構築
61+ let fileContentsSection = "" ;
62+ if ( fileContents && fileContents . length > 0 ) {
63+ fileContentsSection = "\n# ファイルエディターの内容\n" ;
64+ for ( const file of fileContents ) {
65+ fileContentsSection += `\n## ファイル: ${ file . name } \n` ;
66+ fileContentsSection += "```\n" ;
67+ fileContentsSection += file . content ;
68+ fileContentsSection += "\n```\n" ;
69+ }
70+ }
71+
72+ // ファイル実行結果を構築
73+ let execResultsSection = "" ;
74+ if ( execResults && Object . keys ( execResults ) . length > 0 ) {
75+ execResultsSection = "\n# ファイルの実行結果\n" ;
76+ for ( const [ filename , outputs ] of Object . entries ( execResults ) ) {
77+ execResultsSection += `\n## ファイル: ${ filename } \n` ;
78+ execResultsSection += "```\n" ;
79+ for ( const output of outputs ) {
80+ execResultsSection += `${ output . message } \n` ;
81+ }
82+ execResultsSection += "```\n" ;
83+ }
84+ }
3185
3286 const prompt = `
3387以下のPythonチュートリアルのドキュメントの内容を正確に理解し、ユーザーからの質問に対して、初心者にも分かりやすく、丁寧な解説を提供してください。
3488
3589# ドキュメント
3690${ documentContent }
37-
91+ ${ terminalLogsSection } ${ fileContentsSection } ${ execResultsSection }
3892# ユーザーからの質問
3993${ userQuestion }
4094
4195# 指示
4296- 回答はMarkdown形式で記述し、コードブロックを適切に使用してください。
4397- ドキュメントの内容に基づいて回答してください。
98+ - ユーザーが入力したターミナルのコマンドやファイルの内容、実行結果を参考にして回答してください。
4499- ユーザーへの回答のみを出力してください。
45100- 必要であれば、具体的なコード例を提示してください。
46101-
0 commit comments