kenken999 commited on
Commit
c143567
1 Parent(s): a4db5ec
ccccc.txt ADDED
File without changes
chat_history.db CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6bfd28555a291346aa21f1668245bd3d5a3107d8a12a636dc3ffea9b99fd3506
3
- size 1654784
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5b1c00709344baaaf62b270c72c860e1ff6f73786f70ddb82689ad9ee77d341
3
+ size 1658880
controllers/gra_02_openInterpreter/OpenInterpreter.py CHANGED
@@ -5,6 +5,30 @@ import mysite.interpreter.interpreter_config # インポートするだけで
5
  import duckdb
6
  #from logger import logger
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def format_response(chunk, full_response):
9
  # Message
10
  if chunk["type"] == "message":
@@ -12,11 +36,21 @@ def format_response(chunk, full_response):
12
  if chunk.get("end", False):
13
  full_response += "\n"
14
 
15
- # Code
16
  if chunk["type"] == "code":
 
 
 
17
  if chunk.get("start", False):
18
- full_response += "```python\n"
19
- full_response += chunk.get("content", "").replace("`", "")
 
 
 
 
 
 
 
20
  if chunk.get("end", False):
21
  full_response += "\n```\n"
22
 
 
5
  import duckdb
6
  #from logger import logger
7
 
8
+ def detect_language(code: str) -> str:
9
+ """
10
+ 簡易的な言語判別関数。
11
+ Python、Bash、HTML、CSSを判別する。
12
+ """
13
+ python_keywords = ['import ', 'def ', 'class ', 'print(']
14
+ bash_keywords = ['ls ', 'cd ', 'mkdir ', 'echo ']
15
+ html_keywords = ['<html>', '<head>', '<body>']
16
+ css_keywords = ['width:', 'height:', 'color:']
17
+
18
+ if any(kw in code for kw in python_keywords):
19
+ return 'python'
20
+ elif any(kw in code for kw in bash_keywords):
21
+ return 'bash'
22
+ elif any(kw in code for kw in html_keywords):
23
+ return 'html'
24
+ elif any(kw in code for kw in css_keywords):
25
+ return 'css'
26
+ else:
27
+ return '' # 言語指定なし
28
+
29
+
30
+
31
+
32
  def format_response(chunk, full_response):
33
  # Message
34
  if chunk["type"] == "message":
 
36
  if chunk.get("end", False):
37
  full_response += "\n"
38
 
39
+ # コードブロックの処理
40
  if chunk["type"] == "code":
41
+ content = chunk.get("content", "")
42
+ language = detect_language(content)
43
+
44
  if chunk.get("start", False):
45
+ if language:
46
+ full_response += f"```{language}\n"
47
+ else:
48
+ full_response += "```\n"
49
+
50
+ # バッククオートを削除
51
+ content = content.replace("`", "")
52
+ full_response += content
53
+
54
  if chunk.get("end", False):
55
  full_response += "\n```\n"
56