-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_app.py
More file actions
42 lines (34 loc) · 1.52 KB
/
Copy pathcli_app.py
File metadata and controls
42 lines (34 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
from dotenv import load_dotenv
from langchain_core.messages import AIMessageChunk, AIMessage, HumanMessage
from langchain_core.runnables import RunnableConfig
from langgraph.checkpoint.memory import InMemorySaver
from src.main.agents.chain_flow import ChainFlow
from src.main.common.logging import enable_logging
from src.main.common.util import get_llm_chat_model
from src.main.common.util import get_message_chunk
from src.main.datasources.database import Database
from src.main.persona import Persona
from src.main.constants import DRIVER_TABLE_FILTER, DRIVER_EXAMPLES
def main():
driver_persona = Persona(table_filter=DRIVER_TABLE_FILTER, examples=DRIVER_EXAMPLES)
model_name = os.environ.get('model', default="")
chat_model = get_llm_chat_model(model_name)
database = Database()
memory = InMemorySaver()
app = ChainFlow(persona=driver_persona, llm=chat_model, datasource=database, checkpointer=memory,
output_format="rounded_grid")
app.draw_state_graph("./chain_flow_state.png")
while True:
question = input("\nQuestion: >>")
config: RunnableConfig = {"configurable": {"thread_id": "123"}}
stream = app.generate_response(question, config)
for retries, chunk in stream:
content = get_message_chunk(chunk)
message_type = type(chunk[0])
end = "" if message_type is AIMessageChunk else "\n"
print(content, end=end, flush=True)
if __name__ == '__main__':
load_dotenv()
enable_logging()
main()