Mercurial > repos > bgruening > chatgpt_openai_api
annotate chatgpt.py @ 2:dab494dce303 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
author | bgruening |
---|---|
date | Fri, 23 Aug 2024 10:21:21 +0000 |
parents | 08c658e9aa9e |
children | 7770a4bd42e2 |
rev | line source |
---|---|
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
1 import os |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
2 import sys |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
3 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
4 from openai import OpenAI |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
5 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
6 context_files = sys.argv[1].split(",") |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
7 question = sys.argv[2] |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
8 model = sys.argv[3] |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
9 with open(sys.argv[4], "r") as f: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
10 openai_api_key = f.read().strip() |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
11 if not openai_api_key: |
1
08c658e9aa9e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 13c168a7d6a2d5050c04253754fb86321ad57d54
bgruening
parents:
0
diff
changeset
|
12 print("OpenAI API key is not provided in user preferences!") |
08c658e9aa9e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 13c168a7d6a2d5050c04253754fb86321ad57d54
bgruening
parents:
0
diff
changeset
|
13 sys.exit(1) |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
14 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
15 client = OpenAI(api_key=openai_api_key) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
16 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
17 file_search_sup_ext = [ |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
18 "c", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
19 "cs", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
20 "cpp", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
21 "doc", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
22 "docx", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
23 "html", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
24 "java", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
25 "json", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
26 "md", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
27 "pdf", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
28 "php", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
29 "pptx", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
30 "py", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
31 "rb", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
32 "tex", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
33 "txt", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
34 "css", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
35 "js", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
36 "sh", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
37 "ts", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
38 ] |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
39 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
40 vision_sup_ext = ["jpg", "jpeg", "png", "webp", "gif"] |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
41 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
42 file_search_file_streams = [] |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
43 image_files = [] |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
44 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
45 for path in context_files: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
46 ext = path.split(".")[-1].lower() |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
47 if ext in vision_sup_ext: |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
48 if os.path.getsize(path) > 20 * 1024 * 1024: |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
49 print(f"File {path} exceeds the 20MB limit and will not be processed.") |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
50 sys.exit(1) |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
51 file = client.files.create(file=open(path, "rb"), purpose="vision") |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
52 promt = {"type": "image_file", "image_file": {"file_id": file.id}} |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
53 image_files.append(promt) |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
54 elif ext in file_search_sup_ext: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
55 file_search_file_streams.append(open(path, "rb")) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
56 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
57 assistant = client.beta.assistants.create( |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
58 instructions="You will receive questions about files from file searches and image files. For file search queries, identify and retrieve the relevant files based on the question. For image file queries, analyze the image content and provide relevant information or insights based on the image data.", |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
59 model=model, |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
60 tools=[{"type": "file_search"}] if file_search_file_streams else [], |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
61 ) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
62 if file_search_file_streams: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
63 vector_store = client.beta.vector_stores.create() |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
64 file_batch = client.beta.vector_stores.file_batches.upload_and_poll( |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
65 vector_store_id=vector_store.id, files=file_search_file_streams |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
66 ) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
67 assistant = client.beta.assistants.update( |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
68 assistant_id=assistant.id, |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
69 tool_resources={"file_search": {"vector_store_ids": [vector_store.id]}}, |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
70 ) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
71 |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
72 messages = [ |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
73 { |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
74 "role": "user", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
75 "content": [ |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
76 { |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
77 "type": "text", |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
78 "text": question, |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
79 }, |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
80 *image_files, |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
81 ], |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
82 } |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
83 ] |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
84 thread = client.beta.threads.create(messages=messages) |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
85 run = client.beta.threads.runs.create_and_poll( |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
86 thread_id=thread.id, assistant_id=assistant.id |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
87 ) |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
88 assistant_messages = list( |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
89 client.beta.threads.messages.list(thread_id=thread.id, run_id=run.id) |
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
90 ) |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
91 |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
92 message_content = assistant_messages[0].content[0].text.value |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
93 print("Output has been saved!") |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
94 with open("output.txt", "w") as f: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
95 f.write(message_content) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
96 |
2
dab494dce303
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit d2d08c3866c0f4a2f10372ae15c5dac5ea2d0bf0
bgruening
parents:
1
diff
changeset
|
97 for image in image_files: |
0
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
98 client.files.delete(image["image_file"]["file_id"]) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
99 if file_search_file_streams: |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
100 client.beta.vector_stores.delete(vector_store.id) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
101 client.beta.threads.delete(thread.id) |
f256dc85e1a0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chatgpt commit 840e66e7f23cf775ebd3083c6e07d1819b17f74c
bgruening
parents:
diff
changeset
|
102 client.beta.assistants.delete(assistant.id) |