Spaces:
Running
Running
Replace LLMChain with pipes
Browse files
app.py
CHANGED
|
@@ -87,7 +87,7 @@ with tab_panel:
|
|
| 87 |
elif submitted:
|
| 88 |
response = generate_panel_response(
|
| 89 |
text,
|
| 90 |
-
llm_panelists=[LLM_GPT35, LLM_GPT4
|
| 91 |
llm_panel_chair=LLM_GPT4o,
|
| 92 |
temperature=temperature,
|
| 93 |
)
|
|
|
|
| 87 |
elif submitted:
|
| 88 |
response = generate_panel_response(
|
| 89 |
text,
|
| 90 |
+
llm_panelists=[LLM_GPT35, LLM_GPT4],
|
| 91 |
llm_panel_chair=LLM_GPT4o,
|
| 92 |
temperature=temperature,
|
| 93 |
)
|
ring.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
from langchain_openai import OpenAI
|
| 4 |
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
-
from
|
| 7 |
|
| 8 |
|
| 9 |
LLM_GPT35 = "GPT3.5"
|
|
@@ -104,9 +104,9 @@ def generate_response(input_text, llm_ver, temperature, only_celegans):
|
|
| 104 |
|
| 105 |
llm = get_llm(llm_ver, temperature)
|
| 106 |
|
| 107 |
-
llm_chain =
|
| 108 |
|
| 109 |
-
response = llm_chain.invoke(input_text)
|
| 110 |
|
| 111 |
return response
|
| 112 |
|
|
@@ -123,8 +123,9 @@ def generate_panel_response(input_text, llm_panelists, llm_panel_chair, temperat
|
|
| 123 |
|
| 124 |
llm = get_llm(llm_ver, temperature)
|
| 125 |
|
| 126 |
-
llm_chain =
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
panel_chair_prompt = """You are a neuroscientist chairing a panel discussion on the nematode C. elegans. A researcher has asked the following question:
|
| 130 |
{question}
|
|
@@ -153,8 +154,9 @@ Please generate a brief answer to the researcher's question based on their respo
|
|
| 153 |
|
| 154 |
llm = get_llm(llm_panel_chair, temperature)
|
| 155 |
|
| 156 |
-
llm_chain =
|
| 157 |
-
|
|
|
|
| 158 |
|
| 159 |
response = """**%s**: %s""" % (llm_panel_chair, response_chair)
|
| 160 |
|
|
|
|
| 3 |
from langchain_openai import OpenAI
|
| 4 |
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 7 |
|
| 8 |
|
| 9 |
LLM_GPT35 = "GPT3.5"
|
|
|
|
| 104 |
|
| 105 |
llm = get_llm(llm_ver, temperature)
|
| 106 |
|
| 107 |
+
llm_chain = prompt | llm | StrOutputParser()
|
| 108 |
|
| 109 |
+
response = llm_chain.invoke(input_text)
|
| 110 |
|
| 111 |
return response
|
| 112 |
|
|
|
|
| 123 |
|
| 124 |
llm = get_llm(llm_ver, temperature)
|
| 125 |
|
| 126 |
+
llm_chain = prompt | llm | StrOutputParser()
|
| 127 |
+
|
| 128 |
+
responses[llm_ver] = llm_chain.invoke(input_text)
|
| 129 |
|
| 130 |
panel_chair_prompt = """You are a neuroscientist chairing a panel discussion on the nematode C. elegans. A researcher has asked the following question:
|
| 131 |
{question}
|
|
|
|
| 154 |
|
| 155 |
llm = get_llm(llm_panel_chair, temperature)
|
| 156 |
|
| 157 |
+
llm_chain = prompt | llm | StrOutputParser()
|
| 158 |
+
|
| 159 |
+
response_chair = llm_chain.invoke(input_text)
|
| 160 |
|
| 161 |
response = """**%s**: %s""" % (llm_panel_chair, response_chair)
|
| 162 |
|
test.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 PREF_ORDER_LLMS
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
from ring import generate_response
|
| 9 |
+
|
| 10 |
+
question = "What is the most common type of neuron in the brain?"
|
| 11 |
+
|
| 12 |
+
llm_ver = LLM_GPT4o
|
| 13 |
+
|
| 14 |
+
print("--------------------------------------------------------")
|
| 15 |
+
print("Asking question:\n %s" % question)
|
| 16 |
+
print("--------------------------------------------------------")
|
| 17 |
+
|
| 18 |
+
response = generate_response(question, llm_ver, temperature=0, only_celegans=False)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
print("--------------------------------------------------------")
|
| 22 |
+
print("Answer:\n %s" % response)
|
| 23 |
+
print("--------------------------------------------------------")
|
| 24 |
+
print()
|