Joshua Sundance Bailey
commited on
Commit
·
030f7e5
1
Parent(s):
1dd02fc
ui fixes
Browse files
langchain-streamlit-demo/app.py
CHANGED
@@ -12,7 +12,6 @@ from langchain.callbacks.tracers.run_collector import RunCollectorCallbackHandle
|
|
12 |
from langchain.chat_models import ChatOpenAI, ChatAnyscale, ChatAnthropic
|
13 |
from langchain.memory import ConversationBufferMemory, StreamlitChatMessageHistory
|
14 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
15 |
-
from langchain.schema.runnable import RunnableConfig
|
16 |
from langsmith.client import Client
|
17 |
from streamlit_feedback import streamlit_feedback
|
18 |
|
@@ -32,25 +31,10 @@ def st_init_null(*variable_names) -> None:
|
|
32 |
st_init_null(
|
33 |
"chain",
|
34 |
"client",
|
35 |
-
"feedback",
|
36 |
-
"feedback_option",
|
37 |
-
"feedback_record",
|
38 |
-
"feedback_type_str",
|
39 |
-
"feedback_update",
|
40 |
-
"full_response",
|
41 |
"llm",
|
42 |
"ls_tracer",
|
43 |
-
"
|
44 |
-
"prompt",
|
45 |
-
"provider",
|
46 |
-
"provider_api_key",
|
47 |
-
"retriever",
|
48 |
-
"run_collector",
|
49 |
"run_id",
|
50 |
-
"runnable_config",
|
51 |
-
"score",
|
52 |
-
"stream_handler",
|
53 |
-
"system_prompt",
|
54 |
"trace_link",
|
55 |
)
|
56 |
|
@@ -102,10 +86,7 @@ DEFAULT_TEMP = float(os.environ.get("DEFAULT_TEMPERATURE", 0.7))
|
|
102 |
MIN_MAX_TOKENS = int(os.environ.get("MIN_MAX_TOKENS", 1))
|
103 |
MAX_MAX_TOKENS = int(os.environ.get("MAX_MAX_TOKENS", 100000))
|
104 |
DEFAULT_MAX_TOKENS = int(os.environ.get("DEFAULT_MAX_TOKENS", 1000))
|
105 |
-
DEFAULT_LANGSMITH_PROJECT = os.environ.get(
|
106 |
-
"LANGCHAIN_PROJECT",
|
107 |
-
"langchain-streamlit-demo",
|
108 |
-
)
|
109 |
PROVIDER_KEY_DICT = {
|
110 |
"OpenAI": os.environ.get("OPENAI_API_KEY", ""),
|
111 |
"Anthropic": os.environ.get("ANTHROPIC_API_KEY", ""),
|
@@ -276,14 +257,11 @@ if st.session_state.llm:
|
|
276 |
if st.session_state.ls_tracer:
|
277 |
callbacks.append(st.session_state.ls_tracer)
|
278 |
|
279 |
-
runnable_config = RunnableConfig(
|
280 |
-
callbacks=callbacks,
|
281 |
-
tags=["Streamlit Chat"],
|
282 |
-
)
|
283 |
try:
|
284 |
-
full_response = st.session_state.chain
|
285 |
{"input": prompt},
|
286 |
-
|
|
|
287 |
)["text"]
|
288 |
except (openai.error.AuthenticationError, anthropic.AuthenticationError):
|
289 |
st.error(
|
|
|
12 |
from langchain.chat_models import ChatOpenAI, ChatAnyscale, ChatAnthropic
|
13 |
from langchain.memory import ConversationBufferMemory, StreamlitChatMessageHistory
|
14 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
|
15 |
from langsmith.client import Client
|
16 |
from streamlit_feedback import streamlit_feedback
|
17 |
|
|
|
31 |
st_init_null(
|
32 |
"chain",
|
33 |
"client",
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
"llm",
|
35 |
"ls_tracer",
|
36 |
+
"run",
|
|
|
|
|
|
|
|
|
|
|
37 |
"run_id",
|
|
|
|
|
|
|
|
|
38 |
"trace_link",
|
39 |
)
|
40 |
|
|
|
86 |
MIN_MAX_TOKENS = int(os.environ.get("MIN_MAX_TOKENS", 1))
|
87 |
MAX_MAX_TOKENS = int(os.environ.get("MAX_MAX_TOKENS", 100000))
|
88 |
DEFAULT_MAX_TOKENS = int(os.environ.get("DEFAULT_MAX_TOKENS", 1000))
|
89 |
+
DEFAULT_LANGSMITH_PROJECT = os.environ.get("LANGCHAIN_PROJECT")
|
|
|
|
|
|
|
90 |
PROVIDER_KEY_DICT = {
|
91 |
"OpenAI": os.environ.get("OPENAI_API_KEY", ""),
|
92 |
"Anthropic": os.environ.get("ANTHROPIC_API_KEY", ""),
|
|
|
257 |
if st.session_state.ls_tracer:
|
258 |
callbacks.append(st.session_state.ls_tracer)
|
259 |
|
|
|
|
|
|
|
|
|
260 |
try:
|
261 |
+
full_response = st.session_state.chain(
|
262 |
{"input": prompt},
|
263 |
+
callbacks=callbacks,
|
264 |
+
tags=["Streamlit Chat"],
|
265 |
)["text"]
|
266 |
except (openai.error.AuthenticationError, anthropic.AuthenticationError):
|
267 |
st.error(
|