Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LangChain導入とGeminiを使った旅行プラン作成のサンプル作成 #9

Merged
merged 30 commits into from
Jan 16, 2025

Conversation

takatea
Copy link
Contributor

@takatea takatea commented Jan 13, 2025

やったこと

差分多くてすまぬ

新規導入系

※ LangChainはLLMを使うのを楽にしてくれるライブラリどす

主に以下3つ

  • src/agents/travelPlanner.ts
    • LLMを実行するためのプロンプト等を定義していたり、呼べるようにするために設定を記述してる
  • src/components/samples/agent/GoogleMapWithDirection.tsx
    • 経路情報を今回追加したファイルように変更したかったため、ほぼ同じなのでみなくてもok
  • src/routes/samples/agent/index.lazy.tsx
    • このファイルでユーザにいろいろ入れてもらってLLMに検索、その結果を使ってもろもろ表示をしている

refactor系

  • sample系のファイルはすべてsamples/に移動させた
    • そろそろ本格的にルーティング切っていくので、sampleは邪魔かなと
  • lazy設定
    • 開いていないのに裏でGoogleMap等が開かれまくってコスト膨らんでいたので。UX的には裏でデータ取得等しているほうがいいけどsampleなのでlazyにしておく

残タスク

あとは宿泊先を取れるようにするために、以下のどちらかを実施したい

  • 別のLLMを作成して、Web検索できるようにしたい
  • なにかしらのAPIを使う(bokking.com 等)

検索画面 検索結果 経路
image image image

実際にリリースする際にはドメインで制限かける
そもそものサンプルコードが改善の余地あり
※ プロンプトはおいおい調整しなきゃいけない
lazyにして先にloadして無駄なAPI叩かないように
chakra-ui v3にかわってめっちゃ使いにくくなった気がする...
※GoogleMapは旅行先だけ
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NOTE]

ui配下の差分はすべて自動生成

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NOTE]

routes/samples配下の差分は
このファイル以外みなくてok!

ただし本当に利用する際にはもう少しチューニングが必要なのでその点だけ気をつけうこと
Copy link
Contributor Author

@takatea takatea Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NOTE]

https://js.langchain.com/v0.1/docs/modules/model_io/output_parsers/types/structured/

このあたり。
zodでjsonの戻り値を定義して、langchainに渡すと、langchain側でいい感じにpromptを作ってLLMになげてくれる。
このおかげで構造化された状態でアプリケーションはもろもろデータを使える。

@@ -20,3 +20,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# for LLM context
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初見やったわ。
Devinもええけど高すぎるし全自動すぎるから、安く自力でできるようにしたい場合はrepomixを使って対話する方が勉強できて良きやな。

Comment on lines +113 to +114
- Google Mapの経路は、旅行先の経由地のみを含めてください。出発地は含めないでください。
- Google Mapの出発地と目的地は、旅行先の出発地と目的地のみを含めてください。
Copy link
Contributor Author

@takatea takatea Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NOTE]

このあたり工夫することでGoogleMapの経路は旅行先だけにしてます。
ただし、旅費は出発地を考慮して出してもらうようにしてます

<具体例>
東京から北海道の2泊3日の旅行は

東京 <-> 北海道
の旅費も必要だけどGoogleMapの経路としては不要

@takatea takatea requested a review from RYoJiy January 13, 2025 08:52
@takatea takatea marked this pull request as ready for review January 13, 2025 08:52
import { z } from "zod";

const model = new ChatGoogleGenerativeAI({
modelName: "gemini-2.0-flash-exp",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini2.0が異常に精度が高いので2.0にしてます
あと2.0がGAになるまではこのmodelは無料で利用できるのでとてもお得

※ ただし学習されちゃうので個人情報はいれないこと

Copy link
Contributor

@RYoJiy RYoJiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ごめん、確認遅くなった!
というか、全部sample作ってくれて、、ほんまにありがとう(なんも実装してなくてごめん)
LGTM!

<Field label={"出発地"} mb={4} required>
<NativeSelectRoot size="sm" width="240px">
<NativeSelectField
placeholder="Select option"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NITS]
必須入力のselect要素でplaceholderが選択できるのが気になったけど、Chakra的には今の実装をsampleとして提供してたし、そもそもこの実装もsampleやしで、一旦気にせんでも良さそうやから、
(動作確認しましたよアピールのために)コメントだけ失礼しま

(旅行先をSelect optionで旅行プランを作成してみたら、沖縄に行くことになってたw)

Copy link
Contributor Author

@takatea takatea Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実は必須に見えて必須になっていないんだよねw
送信できちゃう

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select optionを選択した場合には、ガチャガチャ要素にさせるという逆転の発想やわ。

Copy link
Contributor Author

@takatea takatea Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

旅行先をSelect optionで旅行プランを作成してみたら、沖縄に行くことになってたw
...
ガチャガチャ要素にさせるという逆転の発想やわ。

そういうことか、たしかにそれは良さそうw

@@ -20,3 +20,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# for LLM context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初見やったわ。
Devinもええけど高すぎるし全自動すぎるから、安く自力でできるようにしたい場合はrepomixを使って対話する方が勉強できて良きやな。

@takatea takatea merged commit 2047d99 into main Jan 16, 2025
1 check passed
@takatea takatea deleted the add-llm branch January 16, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants