Spaces:
Running
Running
Mainly formatting updates; to v0.2.5
Browse files- app.py +1 -18
- datasources.py +5 -13
- model.py +6 -16
- publications.py +1 -4
- requirements.txt +2 -1
- ring.py +2 -19
- test.py +0 -3
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import streamlit
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
# st.set_page_config(layout="wide")
|
|
@@ -8,13 +7,12 @@ from ring import LLM_LLAMA2
|
|
| 8 |
|
| 9 |
from ring import PREF_ORDER_LLMS
|
| 10 |
|
| 11 |
-
|
| 12 |
from ring import requires_openai_key
|
| 13 |
from ring import get_openai_api_key
|
| 14 |
from ring import generate_response
|
| 15 |
from ring import generate_panel_response
|
| 16 |
|
| 17 |
-
__version__ = "0.2.
|
| 18 |
|
| 19 |
col1, col2 = st.columns([3, 1])
|
| 20 |
|
|
@@ -40,11 +38,9 @@ tab_free, tab_panel, tab_pubs, tab_data, tab_corpus, tab_model, tab_about = st.t
|
|
| 40 |
|
| 41 |
|
| 42 |
with tab_free:
|
| 43 |
-
|
| 44 |
st.markdown("**Ask individual LLMs questions about _C. elegans_**")
|
| 45 |
|
| 46 |
with st.form("form_free"):
|
| 47 |
-
|
| 48 |
text = st.text_area(
|
| 49 |
"Ask a question related to _C. elegans_:",
|
| 50 |
"What is the primary role of the C. elegans neuron AVBL?",
|
|
@@ -68,11 +64,9 @@ with tab_free:
|
|
| 68 |
st.info(response)
|
| 69 |
|
| 70 |
with tab_panel:
|
| 71 |
-
|
| 72 |
st.markdown("**Get a consensus answer across multiple LLMs**")
|
| 73 |
|
| 74 |
with st.form("form_panel"):
|
| 75 |
-
|
| 76 |
text = st.text_area(
|
| 77 |
"Ask a question related to _C. elegans_:",
|
| 78 |
"What is the typical length of the worm C. elegans?",
|
|
@@ -132,7 +126,6 @@ with tab_panel:
|
|
| 132 |
st.info(response)
|
| 133 |
|
| 134 |
with tab_pubs:
|
| 135 |
-
|
| 136 |
from publications import find_basis_paper
|
| 137 |
|
| 138 |
st.markdown(
|
|
@@ -140,7 +133,6 @@ with tab_pubs:
|
|
| 140 |
)
|
| 141 |
|
| 142 |
with st.form("form_pubs"):
|
| 143 |
-
|
| 144 |
text = st.text_input("Enter a topic:", "C. elegans locomotion")
|
| 145 |
|
| 146 |
num = st.text_input("Number of results", value=10)
|
|
@@ -154,11 +146,9 @@ with tab_pubs:
|
|
| 154 |
|
| 155 |
|
| 156 |
with tab_data:
|
| 157 |
-
|
| 158 |
st.markdown("**Query structured datasets**")
|
| 159 |
|
| 160 |
with st.form("form_data"):
|
| 161 |
-
|
| 162 |
from datasources import DS_WORMNEUROATLAS
|
| 163 |
from datasources import FORMATS
|
| 164 |
from datasources import query_data_source
|
|
@@ -176,7 +166,6 @@ with tab_data:
|
|
| 176 |
st.info(response)
|
| 177 |
|
| 178 |
with tab_corpus:
|
| 179 |
-
|
| 180 |
from corpus_query import run_query
|
| 181 |
|
| 182 |
st.markdown(
|
|
@@ -184,7 +173,6 @@ with tab_corpus:
|
|
| 184 |
)
|
| 185 |
|
| 186 |
with st.form("form_corpus"):
|
| 187 |
-
|
| 188 |
text = st.text_input(
|
| 189 |
"Enter a query:",
|
| 190 |
"What types of ion channels are present in C. elegans neurons?",
|
|
@@ -202,11 +190,9 @@ with tab_corpus:
|
|
| 202 |
st.info(response)
|
| 203 |
|
| 204 |
with tab_model:
|
| 205 |
-
|
| 206 |
st.markdown("**Run a _C. elegans_ cell model**")
|
| 207 |
|
| 208 |
with st.form("form_model"):
|
| 209 |
-
|
| 210 |
from model import run_model
|
| 211 |
from model import MODELS
|
| 212 |
|
|
@@ -219,8 +205,6 @@ with tab_model:
|
|
| 219 |
response, traces, events = run_model(text, model_to_sim)
|
| 220 |
st.info(response)
|
| 221 |
try:
|
| 222 |
-
|
| 223 |
-
import numpy as np
|
| 224 |
import matplotlib.pyplot as plt
|
| 225 |
|
| 226 |
fig, ax = plt.subplots()
|
|
@@ -240,7 +224,6 @@ with tab_model:
|
|
| 240 |
st.info("There was a problem...\n\n%s" % e)
|
| 241 |
|
| 242 |
with tab_about:
|
| 243 |
-
|
| 244 |
st.markdown('### About "Project Sydney"')
|
| 245 |
st.markdown(
|
| 246 |
"This is an initiative by the [OpenWorm project](https://openworm.org) to investigate the use of LLMs for interacting with scientific literature and structured datasets related to _C. elegans_."
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
# st.set_page_config(layout="wide")
|
|
|
|
| 7 |
|
| 8 |
from ring import PREF_ORDER_LLMS
|
| 9 |
|
|
|
|
| 10 |
from ring import requires_openai_key
|
| 11 |
from ring import get_openai_api_key
|
| 12 |
from ring import generate_response
|
| 13 |
from ring import generate_panel_response
|
| 14 |
|
| 15 |
+
__version__ = "0.2.5"
|
| 16 |
|
| 17 |
col1, col2 = st.columns([3, 1])
|
| 18 |
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
with tab_free:
|
|
|
|
| 41 |
st.markdown("**Ask individual LLMs questions about _C. elegans_**")
|
| 42 |
|
| 43 |
with st.form("form_free"):
|
|
|
|
| 44 |
text = st.text_area(
|
| 45 |
"Ask a question related to _C. elegans_:",
|
| 46 |
"What is the primary role of the C. elegans neuron AVBL?",
|
|
|
|
| 64 |
st.info(response)
|
| 65 |
|
| 66 |
with tab_panel:
|
|
|
|
| 67 |
st.markdown("**Get a consensus answer across multiple LLMs**")
|
| 68 |
|
| 69 |
with st.form("form_panel"):
|
|
|
|
| 70 |
text = st.text_area(
|
| 71 |
"Ask a question related to _C. elegans_:",
|
| 72 |
"What is the typical length of the worm C. elegans?",
|
|
|
|
| 126 |
st.info(response)
|
| 127 |
|
| 128 |
with tab_pubs:
|
|
|
|
| 129 |
from publications import find_basis_paper
|
| 130 |
|
| 131 |
st.markdown(
|
|
|
|
| 133 |
)
|
| 134 |
|
| 135 |
with st.form("form_pubs"):
|
|
|
|
| 136 |
text = st.text_input("Enter a topic:", "C. elegans locomotion")
|
| 137 |
|
| 138 |
num = st.text_input("Number of results", value=10)
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
with tab_data:
|
|
|
|
| 149 |
st.markdown("**Query structured datasets**")
|
| 150 |
|
| 151 |
with st.form("form_data"):
|
|
|
|
| 152 |
from datasources import DS_WORMNEUROATLAS
|
| 153 |
from datasources import FORMATS
|
| 154 |
from datasources import query_data_source
|
|
|
|
| 166 |
st.info(response)
|
| 167 |
|
| 168 |
with tab_corpus:
|
|
|
|
| 169 |
from corpus_query import run_query
|
| 170 |
|
| 171 |
st.markdown(
|
|
|
|
| 173 |
)
|
| 174 |
|
| 175 |
with st.form("form_corpus"):
|
|
|
|
| 176 |
text = st.text_input(
|
| 177 |
"Enter a query:",
|
| 178 |
"What types of ion channels are present in C. elegans neurons?",
|
|
|
|
| 190 |
st.info(response)
|
| 191 |
|
| 192 |
with tab_model:
|
|
|
|
| 193 |
st.markdown("**Run a _C. elegans_ cell model**")
|
| 194 |
|
| 195 |
with st.form("form_model"):
|
|
|
|
| 196 |
from model import run_model
|
| 197 |
from model import MODELS
|
| 198 |
|
|
|
|
| 205 |
response, traces, events = run_model(text, model_to_sim)
|
| 206 |
st.info(response)
|
| 207 |
try:
|
|
|
|
|
|
|
| 208 |
import matplotlib.pyplot as plt
|
| 209 |
|
| 210 |
fig, ax = plt.subplots()
|
|
|
|
| 224 |
st.info("There was a problem...\n\n%s" % e)
|
| 225 |
|
| 226 |
with tab_about:
|
|
|
|
| 227 |
st.markdown('### About "Project Sydney"')
|
| 228 |
st.markdown(
|
| 229 |
"This is an initiative by the [OpenWorm project](https://openworm.org) to investigate the use of LLMs for interacting with scientific literature and structured datasets related to _C. elegans_."
|
datasources.py
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
#
|
| 3 |
#
|
| 4 |
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
|
| 8 |
FORMAT_TEXT = "Text"
|
| 9 |
FORMAT_DICT = "Dict"
|
|
@@ -13,16 +13,12 @@ FORMATS = (FORMAT_TEXT, FORMAT_DICT)
|
|
| 13 |
|
| 14 |
DS_WORMNEUROATLAS = "WormNeuroAtlas"
|
| 15 |
|
| 16 |
-
import wormneuroatlas as wa
|
| 17 |
-
import pprint
|
| 18 |
|
| 19 |
-
pp =
|
| 20 |
|
| 21 |
|
| 22 |
def query_data_source(text, source, format):
|
| 23 |
-
|
| 24 |
if source == DS_WORMNEUROATLAS:
|
| 25 |
-
|
| 26 |
atlas = wa.NeuroAtlas()
|
| 27 |
ds, ss = atlas.everything_about(
|
| 28 |
text, return_values=True, return_text=True, print_text=False
|
|
@@ -37,16 +33,12 @@ def query_data_source(text, source, format):
|
|
| 37 |
info += """```%s```""" % ss
|
| 38 |
elif format == FORMAT_DICT:
|
| 39 |
info = """```
|
| 40 |
-
%s```""" % pp.pformat(
|
| 41 |
-
ds
|
| 42 |
-
)
|
| 43 |
elif format == FORMAT_JSON:
|
| 44 |
import json
|
| 45 |
|
| 46 |
jj = json.dumps(ds)
|
| 47 |
info = """```
|
| 48 |
-
%s```""" % pp.pformat(
|
| 49 |
-
jj
|
| 50 |
-
)
|
| 51 |
|
| 52 |
return info
|
|
|
|
| 2 |
#
|
| 3 |
#
|
| 4 |
|
| 5 |
+
import wormneuroatlas as wa
|
| 6 |
+
from pprint import PrettyPrinter
|
| 7 |
|
| 8 |
FORMAT_TEXT = "Text"
|
| 9 |
FORMAT_DICT = "Dict"
|
|
|
|
| 13 |
|
| 14 |
DS_WORMNEUROATLAS = "WormNeuroAtlas"
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
pp = PrettyPrinter(depth=6)
|
| 18 |
|
| 19 |
|
| 20 |
def query_data_source(text, source, format):
|
|
|
|
| 21 |
if source == DS_WORMNEUROATLAS:
|
|
|
|
| 22 |
atlas = wa.NeuroAtlas()
|
| 23 |
ds, ss = atlas.everything_about(
|
| 24 |
text, return_values=True, return_text=True, print_text=False
|
|
|
|
| 33 |
info += """```%s```""" % ss
|
| 34 |
elif format == FORMAT_DICT:
|
| 35 |
info = """```
|
| 36 |
+
%s```""" % pp.pformat(ds)
|
|
|
|
|
|
|
| 37 |
elif format == FORMAT_JSON:
|
| 38 |
import json
|
| 39 |
|
| 40 |
jj = json.dumps(ds)
|
| 41 |
info = """```
|
| 42 |
+
%s```""" % pp.pformat(jj)
|
|
|
|
|
|
|
| 43 |
|
| 44 |
return info
|
model.py
CHANGED
|
@@ -2,9 +2,6 @@
|
|
| 2 |
#
|
| 3 |
#
|
| 4 |
|
| 5 |
-
import os
|
| 6 |
-
import re
|
| 7 |
-
|
| 8 |
from neuromllite.utils import load_simulation_json
|
| 9 |
from neuromllite.utils import load_network_json
|
| 10 |
from neuromllite.NetworkGenerator import generate_and_run
|
|
@@ -22,7 +19,6 @@ MODELS = {
|
|
| 22 |
|
| 23 |
|
| 24 |
def run_model(text, model, verbose=False):
|
| 25 |
-
|
| 26 |
info = """Running [%s] with parameter: [%s]...
|
| 27 |
|
| 28 |
""" % (
|
|
@@ -41,18 +37,12 @@ def run_model(text, model, verbose=False):
|
|
| 41 |
net.parameters["stim_amp"] = text.strip()
|
| 42 |
|
| 43 |
if verbose:
|
| 44 |
-
info +=
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
"""
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
info += (
|
| 51 |
-
"""```%s```
|
| 52 |
-
|
| 53 |
-
"""
|
| 54 |
-
% net.to_json()
|
| 55 |
-
)
|
| 56 |
|
| 57 |
traces, events = generate_and_run(
|
| 58 |
sim,
|
|
|
|
| 2 |
#
|
| 3 |
#
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
from neuromllite.utils import load_simulation_json
|
| 6 |
from neuromllite.utils import load_network_json
|
| 7 |
from neuromllite.NetworkGenerator import generate_and_run
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def run_model(text, model, verbose=False):
|
|
|
|
| 22 |
info = """Running [%s] with parameter: [%s]...
|
| 23 |
|
| 24 |
""" % (
|
|
|
|
| 37 |
net.parameters["stim_amp"] = text.strip()
|
| 38 |
|
| 39 |
if verbose:
|
| 40 |
+
info += """```%s```
|
| 41 |
+
|
| 42 |
+
""" % sim.to_json()
|
| 43 |
+
info += """```%s```
|
| 44 |
+
|
| 45 |
+
""" % net.to_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
traces, events = generate_and_run(
|
| 48 |
sim,
|
publications.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
#
|
| 4 |
|
| 5 |
import os
|
| 6 |
-
import re
|
| 7 |
import traceback
|
| 8 |
|
| 9 |
import requests
|
|
@@ -13,7 +12,6 @@ result_limit = 10
|
|
| 13 |
|
| 14 |
|
| 15 |
def find_basis_paper(query, result_limit=10):
|
| 16 |
-
|
| 17 |
papers = None
|
| 18 |
info = """Search results:
|
| 19 |
|
|
@@ -59,7 +57,7 @@ def get_element(paper, part):
|
|
| 59 |
if part in simple_parts:
|
| 60 |
if part in paper and paper[part] is not None:
|
| 61 |
v = paper[part]
|
| 62 |
-
return v.strip() if
|
| 63 |
else:
|
| 64 |
return "???"
|
| 65 |
|
|
@@ -91,7 +89,6 @@ def format_paper_list(all_papers, result_limit):
|
|
| 91 |
|
| 92 |
print(sorted_papers)
|
| 93 |
for idx, paper in enumerate(sorted_papers):
|
| 94 |
-
|
| 95 |
list += f"{idx}: **{get_element(paper, 'authors')} et al. {get_element(paper, 'year')}**, [{get_element(paper, 'journal')}]({get_element(paper, 'url')}) {get_element(paper, 'title')}. Cited by {get_element(paper, 'citationCount')}\n\n"
|
| 96 |
if paper["tldr"] and paper["tldr"]["text"]:
|
| 97 |
list += f"> _{paper['tldr']['text'].strip()}_ \n\n"
|
|
|
|
| 3 |
#
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 6 |
import traceback
|
| 7 |
|
| 8 |
import requests
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
def find_basis_paper(query, result_limit=10):
|
|
|
|
| 15 |
papers = None
|
| 16 |
info = """Search results:
|
| 17 |
|
|
|
|
| 57 |
if part in simple_parts:
|
| 58 |
if part in paper and paper[part] is not None:
|
| 59 |
v = paper[part]
|
| 60 |
+
return v.strip() if isinstance(v, str) else v
|
| 61 |
else:
|
| 62 |
return "???"
|
| 63 |
|
|
|
|
| 89 |
|
| 90 |
print(sorted_papers)
|
| 91 |
for idx, paper in enumerate(sorted_papers):
|
|
|
|
| 92 |
list += f"{idx}: **{get_element(paper, 'authors')} et al. {get_element(paper, 'year')}**, [{get_element(paper, 'journal')}]({get_element(paper, 'url')}) {get_element(paper, 'title')}. Cited by {get_element(paper, 'citationCount')}\n\n"
|
| 93 |
if paper["tldr"] and paper["tldr"]["text"]:
|
| 94 |
list += f"> _{paper['tldr']['text'].strip()}_ \n\n"
|
requirements.txt
CHANGED
|
@@ -13,4 +13,5 @@ paper-qa
|
|
| 13 |
langchain-google-genai
|
| 14 |
langchain_ai21
|
| 15 |
langchain_anthropic
|
| 16 |
-
langchain_cohere
|
|
|
|
|
|
| 13 |
langchain-google-genai
|
| 14 |
langchain_ai21
|
| 15 |
langchain_anthropic
|
| 16 |
+
langchain_cohere
|
| 17 |
+
streamlit
|
ring.py
CHANGED
|
@@ -27,15 +27,13 @@ PREF_ORDER_LLMS = (
|
|
| 27 |
|
| 28 |
|
| 29 |
def requires_openai_key(llm_ver):
|
| 30 |
-
|
| 31 |
return llm_ver in OPENAI_LLMS
|
| 32 |
|
| 33 |
|
| 34 |
def get_openai_api_key():
|
| 35 |
-
|
| 36 |
# if openai_api_key_sb == None or len(openai_api_key_sb)==0:
|
| 37 |
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
| 38 |
-
if openai_api_key
|
| 39 |
openai_api_key = str(open("../oaik", "r").readline())
|
| 40 |
# else:
|
| 41 |
# openai_api_key = openai_api_key_sb
|
|
@@ -44,42 +42,36 @@ def get_openai_api_key():
|
|
| 44 |
|
| 45 |
|
| 46 |
def get_llamaapi_key():
|
| 47 |
-
|
| 48 |
llamaapi_key = os.environ.get("LLAMAAPI_KEY")
|
| 49 |
|
| 50 |
return llamaapi_key
|
| 51 |
|
| 52 |
|
| 53 |
def get_gemini_api_key():
|
| 54 |
-
|
| 55 |
gemini_api_key = os.environ.get("GEMINIAPI_KEY")
|
| 56 |
|
| 57 |
return gemini_api_key
|
| 58 |
|
| 59 |
|
| 60 |
def get_ai21_api_key():
|
| 61 |
-
|
| 62 |
ai21_api_key = os.environ.get["AI21_API_KEY"]
|
| 63 |
|
| 64 |
return ai21_api_key
|
| 65 |
|
| 66 |
|
| 67 |
def get_anthropic_key():
|
| 68 |
-
|
| 69 |
anthropic_api_key = os.environ.get["ANTHROPIC_API_KEY"]
|
| 70 |
|
| 71 |
return anthropic_api_key
|
| 72 |
|
| 73 |
|
| 74 |
def get_cohere_key():
|
| 75 |
-
|
| 76 |
cohere_api_key = os.environ.get["COHERE_API_KEY"]
|
| 77 |
|
| 78 |
return cohere_api_key
|
| 79 |
|
| 80 |
|
| 81 |
def get_llm(llm_ver, temperature):
|
| 82 |
-
|
| 83 |
if llm_ver == LLM_GPT35:
|
| 84 |
from langchain_openai import OpenAI
|
| 85 |
|
|
@@ -119,7 +111,6 @@ def get_llm(llm_ver, temperature):
|
|
| 119 |
llm = ChatLlamaAPI(client=llama)
|
| 120 |
|
| 121 |
elif llm_ver == LLM_GEMINI:
|
| 122 |
-
|
| 123 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 124 |
|
| 125 |
llm = ChatGoogleGenerativeAI(
|
|
@@ -127,19 +118,16 @@ def get_llm(llm_ver, temperature):
|
|
| 127 |
)
|
| 128 |
|
| 129 |
elif llm_ver == LLM_AI21:
|
| 130 |
-
|
| 131 |
from langchain_ai21 import AI21LLM
|
| 132 |
|
| 133 |
llm = AI21LLM(model="j2-ultra")
|
| 134 |
|
| 135 |
elif llm_ver == LLM_CLAUDE2:
|
| 136 |
-
|
| 137 |
from langchain_anthropic import AnthropicLLM
|
| 138 |
|
| 139 |
llm = AnthropicLLM(model="claude-2.1")
|
| 140 |
|
| 141 |
elif llm_ver == LLM_COHERE:
|
| 142 |
-
|
| 143 |
from langchain_cohere import ChatCohere
|
| 144 |
|
| 145 |
llm = ChatCohere()
|
|
@@ -160,7 +148,6 @@ GENERAL_QUERY_LIMITED_PROMPT_TEMPLATE = """You are a neuroscientist who is answe
|
|
| 160 |
|
| 161 |
|
| 162 |
def generate_response(input_text, llm_ver, temperature, only_celegans):
|
| 163 |
-
|
| 164 |
template = (
|
| 165 |
GENERAL_QUERY_LIMITED_PROMPT_TEMPLATE
|
| 166 |
if only_celegans
|
|
@@ -181,11 +168,9 @@ def generate_response(input_text, llm_ver, temperature, only_celegans):
|
|
| 181 |
|
| 182 |
|
| 183 |
def generate_panel_response(input_text, llm_panelists, llm_panel_chair, temperature):
|
| 184 |
-
|
| 185 |
responses = {}
|
| 186 |
|
| 187 |
for llm_ver in llm_panelists:
|
| 188 |
-
|
| 189 |
prompt = PromptTemplate(
|
| 190 |
template=GENERAL_QUERY_PROMPT_TEMPLATE, input_variables=["question"]
|
| 191 |
)
|
|
@@ -199,9 +184,7 @@ def generate_panel_response(input_text, llm_panelists, llm_panel_chair, temperat
|
|
| 199 |
panel_chair_prompt = """You are a neuroscientist chairing a panel discussion on the nematode C. elegans. A researcher has asked the following question:
|
| 200 |
{question}
|
| 201 |
and %i experts on the panel have give their answers.
|
| 202 |
-
""" % (
|
| 203 |
-
len(llm_panelists)
|
| 204 |
-
)
|
| 205 |
|
| 206 |
for llm_ver in llm_panelists:
|
| 207 |
panel_chair_prompt += """
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def requires_openai_key(llm_ver):
|
|
|
|
| 30 |
return llm_ver in OPENAI_LLMS
|
| 31 |
|
| 32 |
|
| 33 |
def get_openai_api_key():
|
|
|
|
| 34 |
# if openai_api_key_sb == None or len(openai_api_key_sb)==0:
|
| 35 |
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
| 36 |
+
if openai_api_key is None:
|
| 37 |
openai_api_key = str(open("../oaik", "r").readline())
|
| 38 |
# else:
|
| 39 |
# openai_api_key = openai_api_key_sb
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def get_llamaapi_key():
|
|
|
|
| 45 |
llamaapi_key = os.environ.get("LLAMAAPI_KEY")
|
| 46 |
|
| 47 |
return llamaapi_key
|
| 48 |
|
| 49 |
|
| 50 |
def get_gemini_api_key():
|
|
|
|
| 51 |
gemini_api_key = os.environ.get("GEMINIAPI_KEY")
|
| 52 |
|
| 53 |
return gemini_api_key
|
| 54 |
|
| 55 |
|
| 56 |
def get_ai21_api_key():
|
|
|
|
| 57 |
ai21_api_key = os.environ.get["AI21_API_KEY"]
|
| 58 |
|
| 59 |
return ai21_api_key
|
| 60 |
|
| 61 |
|
| 62 |
def get_anthropic_key():
|
|
|
|
| 63 |
anthropic_api_key = os.environ.get["ANTHROPIC_API_KEY"]
|
| 64 |
|
| 65 |
return anthropic_api_key
|
| 66 |
|
| 67 |
|
| 68 |
def get_cohere_key():
|
|
|
|
| 69 |
cohere_api_key = os.environ.get["COHERE_API_KEY"]
|
| 70 |
|
| 71 |
return cohere_api_key
|
| 72 |
|
| 73 |
|
| 74 |
def get_llm(llm_ver, temperature):
|
|
|
|
| 75 |
if llm_ver == LLM_GPT35:
|
| 76 |
from langchain_openai import OpenAI
|
| 77 |
|
|
|
|
| 111 |
llm = ChatLlamaAPI(client=llama)
|
| 112 |
|
| 113 |
elif llm_ver == LLM_GEMINI:
|
|
|
|
| 114 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 115 |
|
| 116 |
llm = ChatGoogleGenerativeAI(
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
elif llm_ver == LLM_AI21:
|
|
|
|
| 121 |
from langchain_ai21 import AI21LLM
|
| 122 |
|
| 123 |
llm = AI21LLM(model="j2-ultra")
|
| 124 |
|
| 125 |
elif llm_ver == LLM_CLAUDE2:
|
|
|
|
| 126 |
from langchain_anthropic import AnthropicLLM
|
| 127 |
|
| 128 |
llm = AnthropicLLM(model="claude-2.1")
|
| 129 |
|
| 130 |
elif llm_ver == LLM_COHERE:
|
|
|
|
| 131 |
from langchain_cohere import ChatCohere
|
| 132 |
|
| 133 |
llm = ChatCohere()
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def generate_response(input_text, llm_ver, temperature, only_celegans):
|
|
|
|
| 151 |
template = (
|
| 152 |
GENERAL_QUERY_LIMITED_PROMPT_TEMPLATE
|
| 153 |
if only_celegans
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
def generate_panel_response(input_text, llm_panelists, llm_panel_chair, temperature):
|
|
|
|
| 171 |
responses = {}
|
| 172 |
|
| 173 |
for llm_ver in llm_panelists:
|
|
|
|
| 174 |
prompt = PromptTemplate(
|
| 175 |
template=GENERAL_QUERY_PROMPT_TEMPLATE, input_variables=["question"]
|
| 176 |
)
|
|
|
|
| 184 |
panel_chair_prompt = """You are a neuroscientist chairing a panel discussion on the nematode C. elegans. A researcher has asked the following question:
|
| 185 |
{question}
|
| 186 |
and %i experts on the panel have give their answers.
|
| 187 |
+
""" % (len(llm_panelists))
|
|
|
|
|
|
|
| 188 |
|
| 189 |
for llm_ver in llm_panelists:
|
| 190 |
panel_chair_prompt += """
|
test.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
from ring import LLM_GPT35
|
| 2 |
-
from ring import LLM_GPT4
|
| 3 |
from ring import LLM_GPT4o
|
| 4 |
from ring import LLM_LLAMA2
|
| 5 |
from ring import LLM_GEMINI
|
|
@@ -7,7 +5,6 @@ from ring import LLM_AI21
|
|
| 7 |
from ring import LLM_CLAUDE2
|
| 8 |
from ring import LLM_COHERE
|
| 9 |
|
| 10 |
-
from ring import PREF_ORDER_LLMS
|
| 11 |
|
| 12 |
from ring import generate_response
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 1 |
from ring import LLM_GPT4o
|
| 2 |
from ring import LLM_LLAMA2
|
| 3 |
from ring import LLM_GEMINI
|
|
|
|
| 5 |
from ring import LLM_CLAUDE2
|
| 6 |
from ring import LLM_COHERE
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
from ring import generate_response
|
| 10 |
|