-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollama_scraper.py
37 lines (26 loc) · 1.34 KB
/
ollama_scraper.py
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
import ollama
def parse_context(system_content, context):
prompt_text = [{'role': 'system', 'content': system_content}, {'role':'user', 'content': context}]
response = ollama.chat(model='llama3:8b', messages=prompt_text)
return response['message']['content']
txt_file = 'save_output.txt'
with open(txt_file, 'r') as file:
content = file.read()
contexts = content.split('-----------------------------------------------------------------------------------------------------')
parsed_contexts = []
system_content = """You are the text scraper. I will provide you a context and you will capture it contents by the following sections:
1. ID, the id of the context,
2. Problem Statement, it might be in the section of Problem Statment or Problem or description,
3. Solution, could be solutions or workaround, you have to capture all the text in this section,
4. Keywords,
The output format I want is JSON with string value. You should show only output in the JSON format without any comment or explanation."""
i = 0
with open('results/ollama_20240529.json', 'w') as json_file:
for context in contexts:
context = context.strip()
if context:
parsed_context = parse_context(system_content, context)
json_file.write(parsed_context)
json_file.write(',')
print(i)
i += 1