Skip to content

Commit 4e7af8f

Browse files
committed
feat: getQueryJson関数にチャット履歴を追加し、ユーザメッセージの処理を改善
1 parent b50860f commit 4e7af8f

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

frontend/src/util/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const getInferenceRAG = async (messages: APIMessagesType[], message: stri
1313

1414
// ユーザメッセージを、Keywordと検索用文章に変換
1515
console.log('🚀Convert message to keyword and search sentence.');
16-
const query: Query = await getQueryJson(message);
16+
const query: Query = await getQueryJson(message, messages);
1717

1818
// ベクトル化
1919
console.log('🚀Get embedding from Azure OpenAI.');

frontend/src/util/openai.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ export const getEmbedding = async (message: string): Promise<number[]> => {
112112
});
113113
};
114114

115-
export const getQueryJson = async (input: string): Promise<Query> => {
115+
export const getQueryJson = async (message: string, messages?: APIMessagesType[]): Promise<Query> => {
116116
const createQueryJson = async (deployment: string): Promise<Query> => {
117-
console.log(` 🚀ユーザメッセージから検索クエリ生成開始: ${input}`)
117+
console.log(` 🚀ユーザメッセージとチャット履歴から検索クエリ生成開始: ${message}`)
118118

119119
const systemMessage = `ユーザ入力の文章を、重要なKeywordと、それに基づいた検索用文章に変換してください。
120120
121121
# Steps
122-
123-
1. ユーザメッセージを解析し、重要なキーワードを抽出する。
124-
2. 抽出したキーワードを基に、簡潔な検索用文章を作成する。
125-
3. キーワードと検索用文章をJSON形式で出力する。
122+
1. ユーザメッセージとチャット履歴を基に、簡潔な検索用文章を作成する。
123+
2. キーワードと検索用文章をJSON形式で出力する。
126124
127125
# Output Format
128126
@@ -132,28 +130,6 @@ export const getQueryJson = async (input: string): Promise<Query> => {
132130
"search_text": "検索用に適した文章をここに記述"
133131
}
134132
135-
# Examples
136-
137-
### Example 1:
138-
**Input**
139-
こんにちは!東京で最もおすすめのイタリアンレストランを教えてください。
140-
141-
**Output**
142-
{
143-
"keywords": ["東京", "イタリアンレストラン", "おすすめ"],
144-
"search_text": "東京のおすすめイタリアンレストラン"
145-
}
146-
147-
### Example 2:
148-
**Input**
149-
ありがとうございます。最近のAI技術の進化について知りたい。関係津に教えて。
150-
151-
**Output**
152-
{
153-
"keywords": ["AI技術", "進化"],
154-
"search_text": "AI技術の進化に関する情報"
155-
}
156-
157133
# Notes
158134
159135
- 抽出するキーワードは、文脈に沿った重要な単語を選択してください。
@@ -170,8 +146,9 @@ export const getQueryJson = async (input: string): Promise<Query> => {
170146

171147
const body = {
172148
messages: [
149+
...(messages ?? []), // チャット履歴をリクエストに含める
173150
{ role: "system", content: systemMessage },
174-
{ role: "user", content: input }
151+
{ role: "user", content: message }
175152
],
176153
temperature: 0.0,
177154
top_p: 0.0,

0 commit comments

Comments
 (0)