-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
5,982 additions
and
2,133 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-211 KB
data_input/OrfPathHealth/TheBattleAgainstAntimicrobialResistance.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,73 @@ | ||
import sys | ||
sys.path.append('..') | ||
from yachalk import chalk | ||
sys.path.append("..") | ||
|
||
import json | ||
import ollama.client as client | ||
|
||
def extractConcepts(prompt: str, metadata = {}, model="mistral-openorca:latest"): | ||
|
||
def extractConcepts(prompt: str, metadata={}, model="mistral-openorca:latest"): | ||
SYS_PROMPT = ( | ||
"Your task is extract the key concepts (and non personal entities) mentioned in the given text. " | ||
"Your task is extract the key concepts (and non personal entities) mentioned in the given context. " | ||
"Extract only the most important and atomistic concepts, if needed break the concepts down to the simpler concepts." | ||
"Categorize the concepts in one of the following categories: " | ||
"[event, concept, place, object, document, organisation, condition, misc]\n" | ||
"Format your output as a list of json with the following format:\n" | ||
"[\n" | ||
" {\n" | ||
' "entity": The Concept,\n' | ||
' "importance": The contextual importance of the concept on a scale of 1 to 5 (5 being the highest),\n' | ||
' "importance": The concontextual importance of the concept on a scale of 1 to 5 (5 being the highest),\n' | ||
' "category": The Type of Concept,\n' | ||
" }, \n" | ||
"{ }, \n" | ||
"]\n" | ||
) | ||
response, _ = client.generate( | ||
model_name=model, system=SYS_PROMPT, prompt=prompt | ||
response, _ = client.generate(model_name=model, system=SYS_PROMPT, prompt=prompt) | ||
try: | ||
result = json.loads(response) | ||
result = [dict(item, **metadata) for item in result] | ||
except: | ||
print("\n\nERROR ### Here is the buggy response: ", response, "\n\n") | ||
result = None | ||
return result | ||
|
||
|
||
def graphPrompt(input: str, metadata={}, model="mistral-openorca:latest"): | ||
if model == None: | ||
model = "mistral-openorca:latest" | ||
|
||
# model_info = client.show(model_name=model) | ||
# print( chalk.blue(model_info)) | ||
|
||
SYS_PROMPT = ( | ||
"You are a network graph maker who extracts terms and their relations from a given context" | ||
"You are provided with a context chunk (delimited by ```) Your task is to extract the ontology " | ||
"of terms mentioned in the given context. These terms should represent the key concepts as per the context. \n" | ||
"Thought 1: While travelling through every sentence, Think about the key terms mentioned in it.\n" | ||
"\tTerms may include object, entity, location, organization, person, \n" | ||
"\tcondition, acronym, documents, service, concept, etc.\n" | ||
"\tTerms should be as atomistic as possible\n\n" | ||
"Thought 3: Think about how these terms can have one on one relation with other terms.\n" | ||
"\tTerms that are mentioned in same sentence or the same paragraph are typically related to each other.\n" | ||
"\tTerms can be related to many other terms\n\n" | ||
"Thought 4: Find out the relation between each such related pair of terms. \n\n" | ||
"Format your output as a list of json. Each element of the list contains a pair of terms" | ||
"and the relation between them, like the follwing: \n" | ||
"[\n" | ||
" {\n" | ||
' "node_1": "A concept from extracted ontology",\n' | ||
' "node_2": "A related concept from extracted ontology",\n' | ||
' "edge": "relationship between the two concepts, node_1 and node_2 in one or two sentences"\n' | ||
" }, {...}\n" | ||
"]" | ||
) | ||
|
||
USER_PROMPT = f"context: ```{input}``` \n\n output: " | ||
response, _ = client.generate(model_name=model, system=SYS_PROMPT, prompt=USER_PROMPT) | ||
try: | ||
result = json.loads(response) | ||
result = [dict(item, **metadata) for item in result] | ||
except: | ||
print("\n\nERROR ### Here is the buggy response: ", response, "\n\n") | ||
result = None | ||
return result | ||
return result |
Oops, something went wrong.