diff --git a/README.md b/README.md index 0f7e735..8c9d8bf 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,11 @@ $ python make_index.py It outputs like below: -code:: - % python make_index.py - 97%|███████████████████████████████████████████████████████████████████████████████████████████████████▉ | 846/872 [07:06<00:10, 2.59 It/s]The server is currently overloaded with other requests. Sorry about that! You can retry your request, or contact us through our help center at help. openai.com if the error persists. - 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 872/872 [07:45<00:00, 1 .87it/s] +``` +% python make_index.py + 97%|███████████████████████████████████████████████████████████████████████████████████████████████████▉ | 846/872 [07:06<00:10, 2.59 It/s]The server is currently overloaded with other requests. Sorry about that! You can retry your request, or contact us through our help center at help. openai.com if the error persists. +100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 872/872 [07:45<00:00, 1 .87it/s] +``` Ask. diff --git a/ask.py b/ask.py index 506621c..8ca73d4 100644 --- a/ask.py +++ b/ask.py @@ -42,7 +42,7 @@ def ask(input_str, index_file): prompt = PROMPT.format(input=input_str, text=text) print("\nTHINKING...") - response = openai.ChatCompletion.create( + response = openai.OpenAI().chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": prompt} @@ -52,7 +52,7 @@ def ask(input_str, index_file): ) # show question and answer - content = response['choices'][0]['message']['content'] + content = response.choices[0].message.content print("\nANSWER:") print(f">>>> {input_str}") print(">", content) diff --git a/make_index.py b/make_index.py index 32540b7..f870044 100644 --- a/make_index.py +++ b/make_index.py @@ -30,7 +30,7 @@ def embed_text(text, sleep_after_success=1): while True: try: - res = openai.Embedding.create( + res = openai.OpenAI().embeddings.create( input=[text], model="text-embedding-ada-002") time.sleep(sleep_after_success) @@ -40,7 +40,7 @@ def embed_text(text, sleep_after_success=1): continue break - return res["data"][0]["embedding"] + return res.data[0].embedding def update_from_scrapbox(json_file, out_index, in_index=None): diff --git a/requirements.txt b/requirements.txt index bcc8e0a..47ff58c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,24 +1,37 @@ -aiohttp==3.8.4 -aiosignal==1.3.1 -async-timeout==4.0.2 -attrs==22.2.0 -autopep8==2.0.2 -blobfile==2.0.1 -certifi==2022.12.7 -charset-normalizer==3.1.0 -filelock==3.9.0 -frozenlist==1.3.3 -idna==3.4 -lxml==4.9.2 -multidict==6.0.4 -numpy==1.24.2 -openai==0.27.1 -pycodestyle==2.10.0 -pycryptodomex==3.17 -python-dotenv==1.0.0 -regex==2022.10.31 -requests==2.28.2 -tiktoken==0.3.0 -tqdm==4.65.0 -urllib3==1.26.14 -yarl==1.8.2 +aiohappyeyeballs==2.4.4 +aiohttp==3.11.11 +aiosignal==1.3.2 +annotated-types==0.7.0 +anyio==4.8.0 +async-timeout==5.0.1 +attrs==24.3.0 +autopep8==2.3.1 +blobfile==3.0.0 +certifi==2024.12.14 +charset-normalizer==3.4.1 +distro==1.9.0 +filelock==3.16.1 +frozenlist==1.5.0 +h11==0.14.0 +httpcore==1.0.7 +httpx==0.28.1 +idna==3.10 +jiter==0.8.2 +lxml==5.3.0 +multidict==6.1.0 +numpy==2.2.1 +openai==1.59.6 +propcache==0.2.1 +pycodestyle==2.12.1 +pycryptodomex==3.21.0 +pydantic==2.10.5 +pydantic_core==2.27.2 +python-dotenv==1.0.1 +regex==2024.11.6 +requests==2.32.3 +sniffio==1.3.1 +tiktoken==0.8.0 +tqdm==4.67.1 +typing_extensions==4.12.2 +urllib3==2.3.0 +yarl==1.18.3