Spaces:
Sleeping
Sleeping
Test llamaapi
Browse files- app.py +32 -5
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -7,10 +7,14 @@ from langchain.chains import LLMChain
|
|
| 7 |
|
| 8 |
import os
|
| 9 |
|
|
|
|
|
|
|
| 10 |
LLM_GPT35 = 'GPT3.5'
|
| 11 |
LLM_GPT4 = 'GPT4'
|
|
|
|
| 12 |
|
| 13 |
-
st.title("Project Sydney
|
|
|
|
| 14 |
|
| 15 |
openai_api_key = None
|
| 16 |
|
|
@@ -31,6 +35,14 @@ def get_openai_api_key():
|
|
| 31 |
return openai_api_key
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def generate_response(input_text, llm_ver, temperature):
|
| 35 |
|
| 36 |
template = """Question: {question}
|
|
@@ -40,28 +52,43 @@ def generate_response(input_text, llm_ver, temperature):
|
|
| 40 |
template=template,
|
| 41 |
input_variables=['question']
|
| 42 |
)
|
| 43 |
-
|
| 44 |
|
| 45 |
if llm_ver==LLM_GPT35:
|
| 46 |
llm = OpenAI(temperature=temperature, openai_api_key=get_openai_api_key())
|
| 47 |
-
elif llm_ver==LLM_GPT4:
|
| 48 |
|
|
|
|
| 49 |
from langchain_openai import ChatOpenAI
|
| 50 |
llm = ChatOpenAI(model_name='gpt-4', openai_api_key=get_openai_api_key())
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
llm_chain = LLMChain(
|
| 53 |
prompt=prompt,
|
| 54 |
llm=llm
|
| 55 |
)
|
| 56 |
|
| 57 |
-
response = llm_chain.
|
| 58 |
|
| 59 |
st.info(response)
|
| 60 |
|
| 61 |
|
| 62 |
with st.form("my_form"):
|
| 63 |
text = st.text_area("Enter text:", "What is the primary role of the C. elegans neuron ADAL?")
|
| 64 |
-
llm_ver = st.selectbox('Which LLM version?', (LLM_GPT35, LLM_GPT4))
|
| 65 |
|
| 66 |
temperature = st.text_input("Temperature", value=0.1)
|
| 67 |
|
|
|
|
| 7 |
|
| 8 |
import os
|
| 9 |
|
| 10 |
+
__version__ = '0.1.1'
|
| 11 |
+
|
| 12 |
LLM_GPT35 = 'GPT3.5'
|
| 13 |
LLM_GPT4 = 'GPT4'
|
| 14 |
+
LLM_LLAMA2 = 'LLAMA2'
|
| 15 |
|
| 16 |
+
st.title("Project Sydney")
|
| 17 |
+
st.text("OpenWorm LLM v%s - work in progress!"%__version__)
|
| 18 |
|
| 19 |
openai_api_key = None
|
| 20 |
|
|
|
|
| 35 |
return openai_api_key
|
| 36 |
|
| 37 |
|
| 38 |
+
def get_llamaapi_key():
|
| 39 |
+
|
| 40 |
+
llamaapi_key = os.environ.get('LLAMAAPI_KEY')
|
| 41 |
+
print('key: [%s]'%llamaapi_key)
|
| 42 |
+
|
| 43 |
+
return llamaapi_key
|
| 44 |
+
|
| 45 |
+
|
| 46 |
def generate_response(input_text, llm_ver, temperature):
|
| 47 |
|
| 48 |
template = """Question: {question}
|
|
|
|
| 52 |
template=template,
|
| 53 |
input_variables=['question']
|
| 54 |
)
|
|
|
|
| 55 |
|
| 56 |
if llm_ver==LLM_GPT35:
|
| 57 |
llm = OpenAI(temperature=temperature, openai_api_key=get_openai_api_key())
|
|
|
|
| 58 |
|
| 59 |
+
elif llm_ver==LLM_GPT4:
|
| 60 |
from langchain_openai import ChatOpenAI
|
| 61 |
llm = ChatOpenAI(model_name='gpt-4', openai_api_key=get_openai_api_key())
|
| 62 |
|
| 63 |
+
elif llm_ver==LLM_LLAMA2:
|
| 64 |
+
from llamaapi import LlamaAPI
|
| 65 |
+
import asyncio
|
| 66 |
+
|
| 67 |
+
# Create a new event loop
|
| 68 |
+
loop = asyncio.new_event_loop()
|
| 69 |
+
|
| 70 |
+
# Set the event loop as the current event loop
|
| 71 |
+
asyncio.set_event_loop(loop)
|
| 72 |
+
|
| 73 |
+
llama = LlamaAPI(get_llamaapi_key())
|
| 74 |
+
|
| 75 |
+
from langchain_experimental.llms import ChatLlamaAPI
|
| 76 |
+
|
| 77 |
+
llm = ChatLlamaAPI(client=llama)
|
| 78 |
+
|
| 79 |
llm_chain = LLMChain(
|
| 80 |
prompt=prompt,
|
| 81 |
llm=llm
|
| 82 |
)
|
| 83 |
|
| 84 |
+
response = llm_chain.invoke(input_text)['text']
|
| 85 |
|
| 86 |
st.info(response)
|
| 87 |
|
| 88 |
|
| 89 |
with st.form("my_form"):
|
| 90 |
text = st.text_area("Enter text:", "What is the primary role of the C. elegans neuron ADAL?")
|
| 91 |
+
llm_ver = st.selectbox('Which LLM version?', (LLM_GPT35, LLM_GPT4, LLM_LLAMA2))
|
| 92 |
|
| 93 |
temperature = st.text_input("Temperature", value=0.1)
|
| 94 |
|
requirements.txt
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
langchain-community
|
| 2 |
langchain
|
| 3 |
openai
|
| 4 |
-
langchain_openai
|
|
|
|
|
|
|
|
|
| 1 |
langchain-community
|
| 2 |
langchain
|
| 3 |
openai
|
| 4 |
+
langchain_openai
|
| 5 |
+
llamaapi
|
| 6 |
+
asyncio
|