Update index.html
Browse files- index.html +89 -51
index.html
CHANGED
@@ -211,6 +211,16 @@ def extract_pages_from_page_tag(document_with_page_tag):
|
|
211 |
|
212 |
|
213 |
def add_s(values):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
return "s" if len(values) > 1 else ""
|
215 |
|
216 |
|
@@ -256,7 +266,6 @@ def count_characters(document_with_tag):
|
|
256 |
Returns:
|
257 |
str: 文字数とトークン数の情報を含む文字列
|
258 |
"""
|
259 |
-
|
260 |
text = "".join([page.content for page in extract_pages_from_page_tag(document_with_tag)])
|
261 |
|
262 |
tokens = OPENAI_TOKENIZER.encode(text)
|
@@ -264,6 +273,9 @@ def count_characters(document_with_tag):
|
|
264 |
|
265 |
|
266 |
class SearchEngine:
|
|
|
|
|
|
|
267 |
def __init__(self, engine, pages):
|
268 |
self.engine = engine
|
269 |
self.pages = pages
|
@@ -272,6 +284,12 @@ class SearchEngine:
|
|
272 |
SEARCH_ENGINE = None
|
273 |
|
274 |
def create_search_engine(context):
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
global SEARCH_ENGINE
|
276 |
|
277 |
pages = extract_pages_from_page_tag(context)
|
@@ -293,6 +311,16 @@ def create_search_engine(context):
|
|
293 |
|
294 |
|
295 |
def search_pages(keywords, page_limit):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
global SEARCH_ENGINE
|
297 |
if SEARCH_ENGINE is None:
|
298 |
return []
|
@@ -306,6 +334,15 @@ def search_pages(keywords, page_limit):
|
|
306 |
|
307 |
|
308 |
def load_pages(page_numbers):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
global SEARCH_ENGINE
|
310 |
if SEARCH_ENGINE is None:
|
311 |
return []
|
@@ -315,6 +352,55 @@ def load_pages(page_numbers):
|
|
315 |
return found_pages
|
316 |
|
317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
async def process_prompt(prompt, history, context, platform, endpoint, azure_deployment, azure_api_version, api_key, model_name, max_tokens, temperature):
|
319 |
"""
|
320 |
ユーザーのプロンプトを処理し、ChatGPTによる生成結果を返す。
|
@@ -340,54 +426,6 @@ async def process_prompt(prompt, history, context, platform, endpoint, azure_dep
|
|
340 |
if pages:
|
341 |
context = "".join([page.content for page in pages])
|
342 |
|
343 |
-
tools = [
|
344 |
-
# ページ検索
|
345 |
-
{
|
346 |
-
"type": "function",
|
347 |
-
"function": {
|
348 |
-
"name": "search_pages",
|
349 |
-
"description": "与えられたキーワードを含むページを検索します。",
|
350 |
-
"parameters": {
|
351 |
-
"type": "object",
|
352 |
-
"properties": {
|
353 |
-
"keywords": {
|
354 |
-
"type": "string",
|
355 |
-
"description": "半角空白区切りの複数の検索キーワード, 例: Artificial General Intelligence 自律エージェント"
|
356 |
-
},
|
357 |
-
"page_limit": {
|
358 |
-
"type": "number",
|
359 |
-
"description": "検索するページ数, 例: 3",
|
360 |
-
"minimum": 1
|
361 |
-
}
|
362 |
-
}
|
363 |
-
},
|
364 |
-
"required": ["keywords"]
|
365 |
-
}
|
366 |
-
},
|
367 |
-
# ページ取得
|
368 |
-
{
|
369 |
-
"type": "function",
|
370 |
-
"function": {
|
371 |
-
"name": "load_pages",
|
372 |
-
"description": "与えられたページ番号のページを取得します。",
|
373 |
-
"parameters": {
|
374 |
-
"type": "object",
|
375 |
-
"properties": {
|
376 |
-
"page_numbers": {
|
377 |
-
"type": "array",
|
378 |
-
"items": {
|
379 |
-
"type": "number"
|
380 |
-
},
|
381 |
-
"minItems": 1,
|
382 |
-
"description": "取得するページのページ番号のリスト"
|
383 |
-
}
|
384 |
-
}
|
385 |
-
},
|
386 |
-
"required": ["page_numbers"]
|
387 |
-
}
|
388 |
-
}
|
389 |
-
]
|
390 |
-
|
391 |
try:
|
392 |
messages = []
|
393 |
for user_message, assistant_message in history:
|
@@ -419,7 +457,7 @@ async def process_prompt(prompt, history, context, platform, endpoint, azure_dep
|
|
419 |
model=model_name,
|
420 |
max_tokens=max_tokens,
|
421 |
temperature=temperature,
|
422 |
-
tools=
|
423 |
tool_choice="auto",
|
424 |
stream=False
|
425 |
)
|
@@ -603,7 +641,7 @@ def main():
|
|
603 |
}
|
604 |
}'''
|
605 |
|
606 |
-
#
|
607 |
examples = {
|
608 |
"要約 (論文)": '''制約条件に従い、以下の研究論文で提案されている技術や手法について要約してください。
|
609 |
|
|
|
211 |
|
212 |
|
213 |
def add_s(values):
|
214 |
+
"""
|
215 |
+
複数形のsを必要に応じて付けるために用いる関数。
|
216 |
+
与えられたリストの要素数が2以上なら"s"を返し、それ以外は""を返す。
|
217 |
+
|
218 |
+
Args:
|
219 |
+
values (list[any]): リスト
|
220 |
+
|
221 |
+
Returns:
|
222 |
+
str: 要素数が複数なら"s"、それ以外は""
|
223 |
+
"""
|
224 |
return "s" if len(values) > 1 else ""
|
225 |
|
226 |
|
|
|
266 |
Returns:
|
267 |
str: 文字数とトークン数の情報を含む文字列
|
268 |
"""
|
|
|
269 |
text = "".join([page.content for page in extract_pages_from_page_tag(document_with_tag)])
|
270 |
|
271 |
tokens = OPENAI_TOKENIZER.encode(text)
|
|
|
273 |
|
274 |
|
275 |
class SearchEngine:
|
276 |
+
"""
|
277 |
+
検索エンジン
|
278 |
+
"""
|
279 |
def __init__(self, engine, pages):
|
280 |
self.engine = engine
|
281 |
self.pages = pages
|
|
|
284 |
SEARCH_ENGINE = None
|
285 |
|
286 |
def create_search_engine(context):
|
287 |
+
"""
|
288 |
+
検索エンジンを作る。
|
289 |
+
|
290 |
+
Args:
|
291 |
+
context (str): 検索対象となるテキスト。ただし、テキストはchatpdf:pageというタグでページが括られているとする。
|
292 |
+
"""
|
293 |
global SEARCH_ENGINE
|
294 |
|
295 |
pages = extract_pages_from_page_tag(context)
|
|
|
311 |
|
312 |
|
313 |
def search_pages(keywords, page_limit):
|
314 |
+
"""
|
315 |
+
与えられたキーワードを含むページを検索する。
|
316 |
+
|
317 |
+
Args:
|
318 |
+
keywords (str): 検索キーワード
|
319 |
+
page_limit (int): 検索するページ数
|
320 |
+
|
321 |
+
Returns:
|
322 |
+
list[Page]: ヒットしたページ
|
323 |
+
"""
|
324 |
global SEARCH_ENGINE
|
325 |
if SEARCH_ENGINE is None:
|
326 |
return []
|
|
|
334 |
|
335 |
|
336 |
def load_pages(page_numbers):
|
337 |
+
"""
|
338 |
+
与えられたページ番号のページを取得する。
|
339 |
+
|
340 |
+
Args:
|
341 |
+
page_numbers (list[int]): 取得するページ番号
|
342 |
+
|
343 |
+
Returns:
|
344 |
+
list[Page]: 取得したページ
|
345 |
+
"""
|
346 |
global SEARCH_ENGINE
|
347 |
if SEARCH_ENGINE is None:
|
348 |
return []
|
|
|
352 |
return found_pages
|
353 |
|
354 |
|
355 |
+
CHAT_TOOLS = [
|
356 |
+
# ページ検索
|
357 |
+
{
|
358 |
+
"type": "function",
|
359 |
+
"function": {
|
360 |
+
"name": "search_pages",
|
361 |
+
"description": "与えられたキーワードを含むページを検索します。",
|
362 |
+
"parameters": {
|
363 |
+
"type": "object",
|
364 |
+
"properties": {
|
365 |
+
"keywords": {
|
366 |
+
"type": "string",
|
367 |
+
"description": "半角空白区切りの複数の検索キーワード, 例: Artificial General Intelligence 自律エージェント"
|
368 |
+
},
|
369 |
+
"page_limit": {
|
370 |
+
"type": "number",
|
371 |
+
"description": "検索するページ数, 例: 3",
|
372 |
+
"minimum": 1
|
373 |
+
}
|
374 |
+
}
|
375 |
+
},
|
376 |
+
"required": ["keywords"]
|
377 |
+
}
|
378 |
+
},
|
379 |
+
# ページ取得
|
380 |
+
{
|
381 |
+
"type": "function",
|
382 |
+
"function": {
|
383 |
+
"name": "load_pages",
|
384 |
+
"description": "与えられたページ番号のページを取得します。",
|
385 |
+
"parameters": {
|
386 |
+
"type": "object",
|
387 |
+
"properties": {
|
388 |
+
"page_numbers": {
|
389 |
+
"type": "array",
|
390 |
+
"items": {
|
391 |
+
"type": "number"
|
392 |
+
},
|
393 |
+
"minItems": 1,
|
394 |
+
"description": "取得するページのページ番号のリスト"
|
395 |
+
}
|
396 |
+
}
|
397 |
+
},
|
398 |
+
"required": ["page_numbers"]
|
399 |
+
}
|
400 |
+
}
|
401 |
+
]
|
402 |
+
|
403 |
+
|
404 |
async def process_prompt(prompt, history, context, platform, endpoint, azure_deployment, azure_api_version, api_key, model_name, max_tokens, temperature):
|
405 |
"""
|
406 |
ユーザーのプロンプトを処理し、ChatGPTによる生成結果を返す。
|
|
|
426 |
if pages:
|
427 |
context = "".join([page.content for page in pages])
|
428 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
try:
|
430 |
messages = []
|
431 |
for user_message, assistant_message in history:
|
|
|
457 |
model=model_name,
|
458 |
max_tokens=max_tokens,
|
459 |
temperature=temperature,
|
460 |
+
tools=CHAT_TOOLS,
|
461 |
tool_choice="auto",
|
462 |
stream=False
|
463 |
)
|
|
|
641 |
}
|
642 |
}'''
|
643 |
|
644 |
+
# メッセージ例
|
645 |
examples = {
|
646 |
"要約 (論文)": '''制約条件に従い、以下の研究論文で提案されている技術や手法について要約してください。
|
647 |
|