File size: 2,046 Bytes
4633927 a4bb63c 265c2d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
---
license: apache-2.0
datasets:
- kishida/CompileError-Java-JP-cheerful
base_model:
- unsloth/Qwen3-4B-Instruct-2507
---
Javaのコンパイルエラーを明るく解説します。
```python
from llama_cpp import Llama
# model load
base_model = "qwen3-4b"
quant = "Q4_K_M"
llm = Llama.from_pretrained(
repo_id=f"kishida/java-error-explainer-jp-cheerful-{base_model}",
filename=f"java-error-explainer-jp-cheerful-{base_model}.{quant}.gguf",
seed=1234,
)
# streaming
def chat(msg):
res = llm.create_chat_completion(
messages=[
{"role": "system", "content": "You are a Java compile error explainer."},
{"role": "user", "content": msg},
],
temperature=0.7,
)
return res["choices"][0]["message"]["content"]
source = """
void main() {
IO.println(LocalDateTime.now());
IO.println("Hello")
}
"""
error = """
HelloWithError.java:3: エラー: ';'がありません
IO.println("Hello")
^
エラー1個
"""
template = """
source:
{}
compile error:
{}
"""
print("source + error")
print(chat(template.format(source, error)))
"""
あら、コンパイルエラーだね〜!これは単純なセミコロンの不足でしょ。
3行目のコード「IO.println("Hello")」の最後にセミコロン(;)がついていないのが原因よ。Javaでは、一行の文を終わらせるために必ずセミコロンが必要なの。
このエラーを解決するには、3行目のコードの最後に「;」を追加して「IO.println("Hello");」にするだけなの。とても簡単な修正だから、大丈夫だと思うよ〜!
"""
print("error only")
print(chat(error))
"""
あら、このコードに問題が見えるわ!`IO.println("Hello")`の行でセミコロンの忘れちゃってるのね。Javaでは文末には必ずセミコロンを付けないといけないんだから。この一行を`IO.println("Hello");`に直せばエラーは消えるわ。プログラミング、結構気をつけてね!
"""
``` |