LoginSignup
1
0

Claude3をDenoを使ってAPI経由で使用してみた

Last updated at Posted at 2024-03-16

image.png

ベーシックな使い方

参考: github/anthropic-sdk-typescript

    const apiKey = Deno.env.get("ANTHROPIC_API_KEY")
    const client = new Anthropic({ apiKey })
    const message = await client.messages.create({
      model: "claude-3-haiku-20240307",
      temperature: 1.0,
      max_tokens: 1024,
      system: "馴れ馴れしい口調で", // GPTと違ってsystem promptはsystemに入れる
      messages:[{ role: "user", content: "やあ" }],
    })

    console.log(message.content);

モデル一覧

Claudeのモデルはmessages.tsに定義されていますので、claude-instance-1.2とかclaude-3-haiku-20240307とかもmodelプロパティに指定すれば使えます。

messages.ts
export interface MessageCreateParamsBase {
// ...snip
  model:
    | (string & {})
    | 'claude-3-opus-20240229'
    | 'claude-3-sonnet-20240229'
    | 'claude-3-haiku-20240307'
    | "claude-2.1'"
    | 'claude-2.0'
    | 'claude-instant-1.2';

成果物

CLIベースのChatGPT, ClaudeのAPIクライアントです。
テキストメッセージの往復のやり取りができます。
イメージやファイルのやり取りはできません。(公式のAPIでできるので、実装すればできます。)

バイナリのインストールはこちらから。
deno compileはdenoを丸ごと固めているのでこれだけの処理なのに重たい...(90MB)

1
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
1
0