2
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?

More than 1 year has passed since last update.

クソみたいに面倒なソースコードの変換をChatGPTにやらせる

Posted at

はじめに

プログラムを書いてると、
仕様変更で、単純な書き換えを大量にやらなきゃいけない… とか、
既存のクラスにすごい似たクラスを作る必要がある…(けど継承とかコピペでは作れない…) とかが時々ある。

例えばこんな感じのクラス。

public string? Capital { get; set; }
public string? Employees { get; set; }
public string? Bank { get; set; }
public string? Url { get; set; }
public string? Address { get; set; }
public string? BusinessPartner { get; set; }
public string? Memo { get; set; }

これ↑を…こんな感じ↓にしないといけないとか。あるよね?
(この例はC#だけど、C#じゃなくてもいいです。)

public string? Capital { get => Company.Capital; set => Company.Capital = value; }
public string? Employees { get => Company.Employees; set => Company.Employees = value; }
public string? Bank { get => Company.Bank; set => Company.Bank = value; }
public string? Url { get => Company.Url; set => Company.Url = value; }
public string? Address { get => Company.Address; set => Company.Address = value; }
public string? BusinessPartner { get => Company.BusinessPartner; set => Company.BusinessPartner = value; }
public string? Memo { get => Company.Memo; set => Company.Memo = value; }

このくらいなら手作業してもいいかもだけど、実際には10倍くらいの量がある巨大なクラスが対象だと、一気にやる気が消滅する。
自分はもっと生産的なことをしたい。

ChatGPTにやらせる

私はAPIにやらせてるけど、普通のChatGPTでもbingでもできる。
長いプロンプトをごちゃごちゃ書く必要はない。
コツは、どれが変換前後の例なのかをわかりやすく示すこと。

例えばこんな感じ。

ユーザが入力するテキストを変換してください。

#ユーザの入力例
public string? Name { get; set; }

#変換例
public string? Name { get => Company.Name; set => Company.Name = value; }

あとは、複数個一気に投げても、複数個一気に変換してくれる。
もし変換がおかしい場合は、例を増やせばOK。
例も、複数行一気に書いていい。

まとめ

ChatGPTを使って、文字列の簡単な変換が一気にできることを示しました。

ChatGPTで生産性を上げる方法をいろいろ考えてます。
いろいろな職業がAIにとってかわられるその日まで、AIを使い倒してやるのです。

2
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
2
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?