Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,8 @@ from dotenv import load_dotenv
|
|
17 |
|
18 |
import chainlit as cl
|
19 |
from chainlit import user_session
|
20 |
-
|
|
|
21 |
from langchain import hub
|
22 |
from langchain_openai import OpenAI
|
23 |
from langchain.chains import LLMChain
|
@@ -31,22 +32,22 @@ from langchain_core.messages import BaseMessage
|
|
31 |
from pydantic import BaseModel, Field
|
32 |
from typing import List
|
33 |
|
34 |
-
class InMemoryHistory(BaseChatMessageHistory, BaseModel):
|
35 |
-
messages: List[BaseMessage] = Field(default_factory=list)
|
36 |
|
37 |
-
def add_messages(self, messages: List[BaseMessage]) -> None:
|
38 |
-
self.messages.extend(messages)
|
39 |
|
40 |
-
def clear(self) -> None:
|
41 |
-
self.messages = []
|
42 |
|
43 |
# --storing chat histories
|
44 |
-
chat_histories = {}
|
45 |
|
46 |
-
def get_session_history(session_id: str) -> BaseChatMessageHistory:
|
47 |
-
if session_id not in chat_histories:
|
48 |
-
chat_histories[session_id] = InMemoryHistory()
|
49 |
-
return chat_histories[session_id]
|
50 |
|
51 |
# ---------------------------------------------------for backend looks, example file:----------------------------------
|
52 |
#with open('/home/user/.local/lib/python3.10/site-packages/socketio/async_server.py', 'r') as file:
|
@@ -54,6 +55,7 @@ def get_session_history(session_id: str) -> BaseChatMessageHistory:
|
|
54 |
#print("see line 640:", content)
|
55 |
# ------------------------------------------------------the end--------------------------------------------------------
|
56 |
|
|
|
57 |
load_dotenv()
|
58 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
59 |
auth_token = os.environ.get("DAYSOFF_API_TOKEN")
|
@@ -95,7 +97,7 @@ async def set_starters():
|
|
95 |
),
|
96 |
cl.Starter(
|
97 |
label="Metric Space Self-Identity Framework",
|
98 |
-
message="Explain the Metric Space Self-Identity Framework like I'm
|
99 |
icon="/public/learn.svg",
|
100 |
),
|
101 |
cl.Starter(
|
@@ -112,6 +114,15 @@ async def set_starters():
|
|
112 |
|
113 |
@cl.on_chat_start # <βββββββββββββββββ the Chainlit context
|
114 |
def setup_multiple_chains():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
llm = OpenAI(
|
116 |
model="gpt-3.5-turbo-instruct",
|
117 |
temperature=0.7,
|
|
|
17 |
|
18 |
import chainlit as cl
|
19 |
from chainlit import user_session
|
20 |
+
from chainlit.context import init_ws_context
|
21 |
+
from chainlit.session import WebsocketSession # --'Session is disconnected' rt7E1rI_uhficQm8AAAA
|
22 |
from langchain import hub
|
23 |
from langchain_openai import OpenAI
|
24 |
from langchain.chains import LLMChain
|
|
|
32 |
from pydantic import BaseModel, Field
|
33 |
from typing import List
|
34 |
|
35 |
+
#class InMemoryHistory(BaseChatMessageHistory, BaseModel):
|
36 |
+
#messages: List[BaseMessage] = Field(default_factory=list)
|
37 |
|
38 |
+
#def add_messages(self, messages: List[BaseMessage]) -> None:
|
39 |
+
#self.messages.extend(messages)
|
40 |
|
41 |
+
#def clear(self) -> None:
|
42 |
+
#self.messages = []
|
43 |
|
44 |
# --storing chat histories
|
45 |
+
#chat_histories = {}
|
46 |
|
47 |
+
#def get_session_history(session_id: str) -> BaseChatMessageHistory:
|
48 |
+
#if session_id not in chat_histories:
|
49 |
+
#chat_histories[session_id] = InMemoryHistory()
|
50 |
+
#return chat_histories[session_id]
|
51 |
|
52 |
# ---------------------------------------------------for backend looks, example file:----------------------------------
|
53 |
#with open('/home/user/.local/lib/python3.10/site-packages/socketio/async_server.py', 'r') as file:
|
|
|
55 |
#print("see line 640:", content)
|
56 |
# ------------------------------------------------------the end--------------------------------------------------------
|
57 |
|
58 |
+
|
59 |
load_dotenv()
|
60 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
61 |
auth_token = os.environ.get("DAYSOFF_API_TOKEN")
|
|
|
97 |
),
|
98 |
cl.Starter(
|
99 |
label="Metric Space Self-Identity Framework",
|
100 |
+
message="Explain the Metric Space Self-Identity Framework like I'm six years old.",
|
101 |
icon="/public/learn.svg",
|
102 |
),
|
103 |
cl.Starter(
|
|
|
114 |
|
115 |
@cl.on_chat_start # <βββββββββββββββββ the Chainlit context
|
116 |
def setup_multiple_chains():
|
117 |
+
|
118 |
+
# --config Chainlit logging
|
119 |
+
cl.config.run.log_level = "INFO"
|
120 |
+
print("Session id:", cl.user_session.get("id"))
|
121 |
+
|
122 |
+
#session_id: str
|
123 |
+
#ws_session = WebsocketSession.get_by_id(session_id=session_id)
|
124 |
+
#init_ws_context(ws_session)
|
125 |
+
|
126 |
llm = OpenAI(
|
127 |
model="gpt-3.5-turbo-instruct",
|
128 |
temperature=0.7,
|