File size: 2,485 Bytes
ce4a4e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import openai
import time
import wikipedia
import random
import re
import requests
from bs4 import BeautifulSoup
import os
import glob
from natsort import natsorted
import requests
from bs4 import BeautifulSoup
import xml.etree.ElementTree as ET
import pandas as pd

wikipedia.set_lang("ja")
# APIキーの設定
openai.api_key = os.environ['OPENAI_API_KEY']
engine="gpt-3.5-turbo"


def generate(system_template,prompt,engine="gpt-3.5-turbo"):
    while True:  #OpenAI APIが落ちてる時に無限リトライするので注意
        try:
            response = openai.ChatCompletion.create(
                model=engine,
                messages=[
                    {"role": "system", "content": system_template},
                    {"role": "user", "content":prompt},
                    ]
            )
            result=response["choices"][0]["message"]["content"]
            return result
        except:
            print("リトライ")
            time.sleep(30)
            pass

def generate_carte(prompt,engine="gpt-3.5-turbo"):
    while True:  #OpenAI APIが落ちてる時に無限リトライするので注意
        try:
            response = openai.ChatCompletion.create(
                model=engine,
                messages=[
                    {"role": "system", "content": "You are useful assistant"},
                    {"role": "user", "content":"%s\n・・・という患者と医師の会話をSOAP形式のカルテとして日本語で端的にまとめて下さい。各セクションはS),O), A),P)として下さい "%prompt},
                    ]
            )
            result=response["choices"][0]["message"]["content"]
            return result
        except:
            print("リトライ")
            time.sleep(30)
            pass
        
def get_selected_fileds(texts):
    input_name = texts.replace(' ' , "+")
    corona_fields = ct.get_study_fields(
    search_expr="%s SEARCH[Location](AREA[LocationCountry]Japan AND AREA[LocationStatus]Recruiting)"%(input_name),
    fields=["NCTId", "Condition", "BriefTitle",'BriefSummary','EligibilityCriteria'],
    max_studies=500,
    fmt="csv")
    return corona_fields

def get_retriever_str(fields):
    retriever_str=''
    for i in range(1,len(fields)):
        colnames = fields[0]
        targetCol = fields[i]
        for f in range(len(fields[0])):
            retriever_str+=colnames[f] + ":" + targetCol[f] +"\n"
        retriever_str+='\n'
    return retriever_str