GitHub Copilotが有料なので無料のTabnineをVSCodeに入れてみた

使ってみようと思った経緯

現在、手作業でやっていることを、MongoDBにデータを貯めて、自動化しようと思いつきました。こういうホビープログラミングは好きでちょくちょくやっています。そこで、最近「GitHub Copilot」が流行っているので、それを使ってみようと思ったのですが、無料で利用することができないようでした。代替はないかと探してみると、Tabnineというのが見つかり、とりあえずこちらを試してみようかな?となりました。

わたしのポリシーとして、サブスクリプションは必要最小限にしようと考えています。いまはヒキニートでもあるのでなおさらです。

Tabnineのbasic(無料)では、1行に対するサジェストとチャットが使えるようでした。チャットさえ使えれば、いちいちChromeでChatGPTを使わなくてもいいから、少し時短になるかもと考えています。ちなみに、ChatGPTも無料の範囲で利用しています。

こちらはホントは入れたかったやつです。無料利用の方法がないので断念しました。

こちらが、実際に入れたやつです。

インストール

Tabnineのユーザー登録

Tabnineを利用するにはユーザー登録しないといけないようなので、以下のサイトで登録します。

  • 以下のサイトを出して、右上の「Log in」ボタンをクリックすると、サインインのダイアログが出ます。

  • 「Don't have an account? Sign up」の「Sign up」部分にリンクが貼っているのでそれをクリックすると、ユーザー登録のダイアログに切り替わります。

  • ユーザー登録後にアクセストークンのダイアログが出てきましたが、そのトークンはVSCodeの拡張機能を有効化する手順の中では利用しませんでした。いちおうメモはしておきましたが、どこで使うのでしょうか?

拡張機能のインストール

拡張機能「Tabnine」をインストールします。マーケットプレイスの情報は上にリンクしています。下は、VSCodeで見たときのスクリーンショットです。

拡張機能「Tabnine」

インストールすると、右下に「Tabnine: Sign-in is required」と出ているので、それを解決します。

  • 左のアクティビティバーの「Tabnine AI」アイコンをクリックします。

  • サイドバー内に「Sign in」ボタンがあるのでそれをクリックしサインインします。

  • サインインが済むと、最初はどのモデルを使うかを聞いてきました。とりあえず、推奨の「Tabnine Protected」を選択しました。「GPT-4o」も選べるようです。まだ、試していません。

お試し利用

以下のような状態からお試しを開始します。

初期状態
初期状態
  • まずは、以下のような質問をしてみました。

pythonでMongoDBにユーザーを作成するコードはどう書きますか?

質問
質問を書いた直後
質問を書いた直後
質問後

以下が実際の回答です。日本語にして欲しいな!と思いますが、そこは無料なので我慢ということで、日本語の質問で問題なく回答してくれるのでOKとします。このレベルで返してくれると、ChromeでChatGPTに聞く必要はなくなります。

from pymongo import MongoClient

# Create a connection to MongoDB
client = MongoClient(username = "root", password = "password")

# Access the database
db = client["tesdb"]

# Create a new user
db.command("createUser", "new_user", pwd="new_password", roles=["readWrite"])

In this code snippet, we first import the MongoClient from the pymongo library. Then, we establish a connection to MongoDB using the root user's credentials. Afterward, we access the "tesdb" database and use the command method to create a new user named "new_user" with the password "new_password" and the "readWrite" role.

Tabnineの回答
  • 次は以下のような質問をしてみました。複数を対で記載します。

ユーザーをuserで、対象DBをtesdbにして、そのオーナーにする場合はどうですか?

質問

from pymongo import MongoClient

# Create a connection to MongoDB
client = MongoClient(username = "root", password = "password")

# Access the database
db = client["tesdb"]

# Create a new user
db.command("createUser", "user", pwd="password", roles=["dbOwner"])

Show diffIn this code snippet, we first import the MongoClient from the pymongo library. Then, we establish a connection to MongoDB using the root user's credentials. Afterward, we access the "tesdb" database and use the command method to create a new user named "user" with the password "password" and the "dbOwner" role. This role grants full control over the database, including the ability to add or remove other users.

Tabnineの回答

ユーザーuserを削除するのはどうしたらいいですか?

質問

from pymongo import MongoClient

# Set up a connection to MongoDB
client = MongoClient(username = "root", password = "password")

# Access the "tesdb" database
db = client["tesdb"]

# Remove the "user" user
db.command("dropUser", "user")

This code snippet removes the user named "user" from the "tesdb" database. Please replace "root", "password", and "tesdb" with your actual MongoDB credentials.

Tabnineの回答

当然ながら、前回の質問を加味しての回答になっていました。

  • 次は新しいチャットを開いて、また別な質問をしました。複数を対で記載します。

プリント内容を構造的に印字するにはどうすればいいですか?

質問

To print the content of the doc variable in a structured manner, you can use the pprint module from Python's standard library. Here's how you can modify the code:

from pymongo import MongoClient
from pprint import pprint

# データ読み込みテスト
client = MongoClient(username = "root", password = "password")

db = client["tesdb"]

doc = db.tes.find_one()

pprint(doc)

Now, when you run the code, it will print the content of the doc variable in a structured format.

Can you explain the `pprint` module and how it works to format the output?

Tabnineの回答

「Can you explain the `pprint` module and how it works to format the output?」この部分はリンクになっていて、こんな質問はどうですかと?サジェストしてくれているようです。これをクリックするとその質問をしたことになるようでした。

ありがとう!

質問

You're welcome! If you have any other questions or need further assistance, feel free to ask. I'm here to help.

What is the structure of the 'doc' variable when it's printed in a structured format using pprint?

Tabnineの回答

以上

試しにやっただけですが、VSCode内でチャットが完結するので、ChromeとVSCodeをいったりきたりする手間が省けそうです。まあ、マルチディスプレイ環境なのでそれほどの手間ではないのですが。あと、右に出しているソースをそれなりに加味してくれているようです。これはすごく可能性を感じます。

APIリファレンスなどは引数等詳細を理解するために結局はググるのですが、自分がやりたいことを質問するとAPIなどの手法自体を教えてくれるので、その部分の調査時間が極端に減ります。以前は、やりたいことを解決するAPIなどの手法にたどりつくのに、ひと手間かかっていました。このメリットはTabnineだけではなく、コーディングをアシストしてくれるAI全般の話ですね。

参考URL

導入には、以下のサイトを参考にしました。

この記事が気に入ったらサポートをしてみませんか?