Skip to content

Commit

Permalink
modify add_topic_poc.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kota-yata committed Dec 11, 2023
1 parent 51d4b38 commit 43a47e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ cython_debug/
#.idea/

.vscode/settings.json

.DS_Store
11 changes: 5 additions & 6 deletions scripts/add_topic_poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
response_sample = """
{
"1700958646329": {
"topics": ["医療, 福祉"...],
"topics": ["医療", "福祉", "政治"],
"language": "en"
}
}
"""

def get_topic(client: OpenAI, note_id: int, tweet: str, note: str) -> Dict[str, List[str]]:
print(f"note id: {note_id}")
with open(os.path.join(os.path.dirname(__file__), "fewshot_sample.json"), "r") as f:
fewshot_sample = json.load(f)

Expand Down Expand Up @@ -61,18 +62,16 @@ def get_topic(client: OpenAI, note_id: int, tweet: str, note: str) -> Dict[str,

return json.loads(chat_completion.choices[0].message.content)


if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("input_file")
# parser.add_argument("output_file")
parser.add_argument("output_file")
args = parser.parse_args()
load_dotenv()
client = OpenAI()
with open(args.input_file, "r", encoding="utf-8") as f:
with open(args.input_file, "r") as f:
notes = json.load(f)
# create output json file with topics. make the file an array of objects which is each response
with open("data/output.json", "w", encoding="utf-8") as f:
with open(args.output_file, "w", encoding="utf-8") as f:
json.dump(
[
get_topic(client, note["noteId"], note["tweetBody"], note["noteBody"])
Expand Down
44 changes: 0 additions & 44 deletions scripts/data_sample.json

This file was deleted.

0 comments on commit 43a47e8

Please sign in to comment.