0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[AI Coding Challenge] AIにジョークを言ってもらうアプリを作ってみた!

0
Last updated at Posted at 2025-12-11

はじめに

毎日ひとつ、AIアプリをつくる。
日替わりでテーマに沿って小さなアプリを開発します。Claudeで。

この記事は :calendar_spiral: AI Code Challenge Advent Calender 2025 の 12 日目の記事です!

:arrow_left: 11日目の記事:AIが提案してくれるやることルーレットアプリを作ってみた!
  13日目の記事:音から音符に変換するアプリを作ってみた! :arrow_right:

AI アプリ

概要

:speech_balloon:
AIにもお笑いはわかるのだろうか?

AIにおもしろいジョーク言ってもらうアプリを作ろう! :grinning:
お手並み拝見!

AI 実装

Claude Desktopでプロンプトを与えて実装してもらいます。

:boy_tone1: プロンプト:

AIがジョークをおしえてくれるアプリ
テーマを与えたら、AIがジョークを言ってくれる。

:robot:

AIがジョークを生成してくれるアプリを作成しました!

完成したアプリ

できました!

  :robot: AIジョークメーカー

:point_down: のリンクからアプリを確認できます:sparkles:

使い方:

  • テーマを入力すると、AIがそのテーマに関連したジョークを日本語で生成
  • おすすめテーマボタンで簡単にテーマ選択

こんなイメージです。

image.png

試しに「こども」をテーマにジョークを言ってもらいました。

image.png

:joy:

プログラム解説

ポイントとなるプログラムを解説します。

const generateJoke = async () => {
  if (!theme.trim()) return;

  setLoading(true);
  setJoke('');

  try {
    const response = await fetch('https://api.anthropic.com/v1/messages', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        model: 'claude-sonnet-4-20250514',
        max_tokens: 500,
        messages: [
          {
            role: 'user',
            content: `
「${theme}」というテーマで、面白いジョークを1つ考えてください。日本語で、短くて分かりやすいジョークをお願いします。ジョークだけを返してください。
`,
          },
        ],
      }),
    });

    const data = await response.json();
    const generatedJoke = data.content[0].text;

    setJoke(generatedJoke);
  } catch (error) {
    console.error('Error generating joke:', error);
    setJoke(
      'ジョークの生成中にエラーが発生しました。もう一度お試しください。'
    );
  } finally {
    setLoading(false);
  }
};
  • ClaudeのArtifacts上でAnthropicのAPIを実行します。
response = await fetch("https://api.anthropic.com/v1/messages" ...)
  • 生成AIのモデルは「claude-sonnet-4」です。
model: "claude-sonnet-4-20250514"
  • こちらがClaudeが生成したユーザプロンプトです。
「${theme}」というテーマで、面白いジョークを1つ考えてください。日本語で、短くて分かりやすいジョークをお願いします。ジョークだけを返してください。

おわりに

  • 何回か試してみると、意味のわからないジョークも生まれてくる。
  • 暇つぶしにどうぞ。笑

AI で楽しいアプリ開発を!!

この記事は :calendar_spiral: AI Code Challenge Advent Calender 2025 の 12 日目の記事です!

:arrow_left: 11日目の記事:AIが提案してくれるやることルーレットアプリを作ってみた!
  13日目の記事:音から音符に変換するアプリを作ってみた! :arrow_right:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?