Skip to content

Commit ae074dd

Browse files
authored
fix example and type hints (#63)
* fix example and type hints * enhance example to use multiple dialogues
1 parent 810b3e2 commit ae074dd

File tree

6 files changed

+420
-98
lines changed

6 files changed

+420
-98
lines changed

dialog2graph/pipelines/d2g_llm/three_stages_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from langchain.output_parsers import PydanticOutputParser, OutputFixingParser
1515
from langchain.schema import HumanMessage
1616
from langchain_openai import ChatOpenAI
17-
from langchain_community.embeddings import HuggingFaceEmbeddings
17+
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
1818

1919

2020
from dialog2graph import metrics

dialog2graph/pipelines/helpers/parse_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
logger = Logger(__name__)
2121

22-
RawDialogsType = dict | list[list] | list[dict] | Dialog | list[Dialog] | PosixPath
22+
RawDialogsType = dict | list[list] | list[dict] | list[list[dict]] | Dialog | list[Dialog] | PosixPath
2323
ValidatedDialogType = (
2424
List[DialogMessage] | List[List[DialogMessage]] | Dialog | List[Dialog]
2525
)

dialog2graph/pipelines/model_storage.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import yaml
66
import re
77
import dotenv
8-
from pydantic._internal._model_construction import ModelMetaclass
9-
from typing import Union, Dict
8+
from typing import Union, Dict, Type
109
from pathlib import Path
1110
from pydantic import BaseModel, Field, model_validator
1211

13-
from langchain_community.chat_models import ChatOpenAI
12+
from langchain_openai.chat_models import ChatOpenAI
1413
from langchain_core.language_models import BaseChatModel
15-
from langchain_community.embeddings import HuggingFaceEmbeddings
14+
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
1615

1716
from dialog2graph.utils.logger import Logger
1817

@@ -62,7 +61,7 @@ class StoredData(BaseModel):
6261
Attributes:
6362
key (str): Key for the stored model.
6463
config (dict): Configuration for the stored model.
65-
model_type (Union[Literal["llm"], Literal["emb"]]): Type of the stored model, either "llm" (language model) or "emb" (embedding model).
64+
model_type (Type[BaseChatModel | HuggingFaceEmbeddings]): Type of the stored model, for example ChatOpenAI, HuggingFaceEmbeddings.
6665
model (Union[HuggingFaceEmbeddings, BaseChatModel]): The actual model object, which can either be a HuggingFaceEmbeddings instance or a BaseChatModel instance.
6766
6867
Methods:
@@ -76,7 +75,7 @@ class StoredData(BaseModel):
7675

7776
key: str = Field(description="Key for the stored model")
7877
config: dict = Field(description="Configuration for the stored model")
79-
model_type: ModelMetaclass = Field(description="Type of the stored model")
78+
model_type: Type[BaseChatModel | HuggingFaceEmbeddings] = Field(description="Type of the stored model")
8079
model: Union[
8180
HuggingFaceEmbeddings,
8281
BaseChatModel,
@@ -140,7 +139,7 @@ def add(
140139
self,
141140
key: str,
142141
config: dict,
143-
model_type: ModelMetaclass,
142+
model_type: Type[BaseChatModel | HuggingFaceEmbeddings],
144143
overwright: bool = False,
145144
):
146145
"""
@@ -155,7 +154,7 @@ def add(
155154
Args:
156155
key (str): The unique identifier for the model configuration.
157156
config (dict): The configuration dictionary for initializing the model.
158-
model_type (ModelMetaclass): The type name of the model to be added.
157+
model_type (Type[BaseChatModel | HuggingFaceEmbeddings]): The type of the model to be added.
159158
overwright (bool): Whether to overwright model existing under same key
160159
.
161160
Raises:
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
d2g_llm_filling_llm:v1:
1+
my_filling_model:
22
config:
3-
name: o3-mini
4-
temperature: 1
5-
model_type: llm
6-
d2g_llm_grouping_llm:v1:
3+
model_name: gpt-3.5-turbo
4+
model_type: ChatOpenAI
5+
three_stages_llm_formatting_llm:v1:
76
config:
8-
name: gpt-4o-latest
7+
model_name: gpt-4o-mini
98
temperature: 0
10-
model_type: llm
11-
d2g_llm_sim_model:v1:
9+
model_type: ChatOpenAI
10+
three_stages_llm_grouping_llm:v1:
11+
config:
12+
model_name: chatgpt-4o-latest
13+
temperature: 0
14+
model_type: ChatOpenAI
15+
three_stages_llm_sim_model:v1:
1216
config:
1317
model_kwargs:
1418
device: cpu
15-
model_name: cointegrated/LaBSE-en-ru
16-
model_type: emb
17-
my_model:
18-
config:
19-
name: gpt-3.5-turbo
20-
model_type: llm
19+
model_name: BAAI/bge-m3
20+
model_type: HuggingFaceEmbeddings
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
[
2+
[
3+
{
4+
"text": "Hello! How can I assist you with your calendar today?",
5+
"participant": "assistant"
6+
},
7+
{
8+
"text": "I'm having trouble with my calendar not syncing properly.",
9+
"participant": "user"
10+
},
11+
{
12+
"text": "I'm sorry to hear you're experiencing a sync delay. Can you tell me more about the issue?",
13+
"participant": "assistant"
14+
},
15+
{
16+
"text": "Yes, I checked but it still doesn't sync.",
17+
"participant": "user"
18+
},
19+
{
20+
"text": "Could you verify that the time zone settings are properly configured on your devices?",
21+
"participant": "assistant"
22+
},
23+
{
24+
"text": "Alright, please guide me through the steps.",
25+
"participant": "user"
26+
},
27+
{
28+
"text": "Sure, let me guide you through adjusting your time zone settings.",
29+
"participant": "assistant"
30+
},
31+
{
32+
"text": "I want to change the time zone instead.",
33+
"participant": "user"
34+
},
35+
{
36+
"text": "Of course! Which device would you like to adjust the time zone settings on?",
37+
"participant": "assistant"
38+
},
39+
{
40+
"text": "Sure, let's adjust the time zone settings.",
41+
"participant": "user"
42+
},
43+
{
44+
"text": "Sure, let me guide you through adjusting your time zone settings.",
45+
"participant": "assistant"
46+
},
47+
{
48+
"text": "I've followed the steps and it seems to be working now.",
49+
"participant": "user"
50+
},
51+
{
52+
"text": "Great! Is your calendar syncing correctly now?",
53+
"participant": "assistant"
54+
},
55+
{
56+
"text": "Actually, it's still not syncing. I want to try something else.",
57+
"participant": "user"
58+
},
59+
{
60+
"text": "I'm sorry we couldn't resolve the issue. If you need further assistance, feel free to reach out anytime. Have a great day!",
61+
"participant": "assistant"
62+
}
63+
],
64+
[
65+
{
66+
"text": "Hello! How can I assist you with your calendar today?",
67+
"participant": "assistant"
68+
},
69+
{
70+
"text": "I'm having trouble with my calendar not syncing properly.",
71+
"participant": "user"
72+
},
73+
{
74+
"text": "I'm sorry to hear you're experiencing a sync delay. Can you tell me more about the issue?",
75+
"participant": "assistant"
76+
},
77+
{
78+
"text": "Yes, I checked but it still doesn't sync.",
79+
"participant": "user"
80+
},
81+
{
82+
"text": "Have you checked if your time zone settings are correct on all your devices?",
83+
"participant": "assistant"
84+
},
85+
{
86+
"text": "Alright, please guide me through the steps.",
87+
"participant": "user"
88+
},
89+
{
90+
"text": "Sure, let me guide you through adjusting your time zone settings.",
91+
"participant": "assistant"
92+
},
93+
{
94+
"text": "I want to change the time zone instead.",
95+
"participant": "user"
96+
},
97+
{
98+
"text": "Of course! Which device would you like to adjust the time zone settings on?",
99+
"participant": "assistant"
100+
},
101+
{
102+
"text": "Sure, let's adjust the time zone settings.",
103+
"participant": "user"
104+
},
105+
{
106+
"text": "Sure, let me guide you through adjusting your time zone settings.",
107+
"participant": "assistant"
108+
},
109+
{
110+
"text": "I've followed the steps and it seems to be working now.",
111+
"participant": "user"
112+
},
113+
{
114+
"text": "Great! Is your calendar syncing correctly now?",
115+
"participant": "assistant"
116+
},
117+
{
118+
"text": "Actually, it's still not syncing. I want to try something else.",
119+
"participant": "user"
120+
},
121+
{
122+
"text": "I'm sorry we couldn't resolve the issue. If you need further assistance, feel free to reach out anytime. Have a great day!",
123+
"participant": "assistant"
124+
}
125+
],
126+
[
127+
{
128+
"text": "Hello! How can I assist you with your calendar today?",
129+
"participant": "assistant"
130+
},
131+
{
132+
"text": "I'm having trouble with my calendar not syncing properly.",
133+
"participant": "user"
134+
},
135+
{
136+
"text": "I'm sorry to hear you're experiencing a sync delay. Can you tell me more about the issue?",
137+
"participant": "assistant"
138+
},
139+
{
140+
"text": "Yes, I checked but it still doesn't sync.",
141+
"participant": "user"
142+
},
143+
{
144+
"text": "Could you verify that the time zone settings are properly configured on your devices?",
145+
"participant": "assistant"
146+
},
147+
{
148+
"text": "Time zone settings are correct, but the issue persists.",
149+
"participant": "user"
150+
},
151+
{
152+
"text": "If time zone settings are correct, we can try refreshing the calendar app or reinstalling it.",
153+
"participant": "assistant"
154+
},
155+
{
156+
"text": "After adjusting, it still doesn't sync.",
157+
"participant": "user"
158+
},
159+
{
160+
"text": "Great! Is your calendar syncing correctly now?",
161+
"participant": "assistant"
162+
},
163+
{
164+
"text": "Actually, it's still not syncing. I want to try something else.",
165+
"participant": "user"
166+
},
167+
{
168+
"text": "I'm sorry we couldn't resolve the issue. If you need further assistance, feel free to reach out anytime. Have a great day!",
169+
"participant": "assistant"
170+
}
171+
],
172+
[
173+
{
174+
"text": "Hello! How can I assist you with your calendar today?",
175+
"participant": "assistant"
176+
},
177+
{
178+
"text": "I'm having trouble with my calendar not syncing properly.",
179+
"participant": "user"
180+
},
181+
{
182+
"text": "I'm sorry to hear you're experiencing a sync delay. Can you tell me more about the issue?",
183+
"participant": "assistant"
184+
},
185+
{
186+
"text": "Yes, I checked but it still doesn't sync.",
187+
"participant": "user"
188+
},
189+
{
190+
"text": "Have you checked if your time zone settings are correct on all your devices?",
191+
"participant": "assistant"
192+
},
193+
{
194+
"text": "Time zone settings are correct, but the issue persists.",
195+
"participant": "user"
196+
},
197+
{
198+
"text": "If time zone settings are correct, we can try refreshing the calendar app or reinstalling it.",
199+
"participant": "assistant"
200+
},
201+
{
202+
"text": "After adjusting, it still doesn't sync.",
203+
"participant": "user"
204+
},
205+
{
206+
"text": "Great! Is your calendar syncing correctly now?",
207+
"participant": "assistant"
208+
},
209+
{
210+
"text": "Actually, it's still not syncing. I want to try something else.",
211+
"participant": "user"
212+
},
213+
{
214+
"text": "I'm sorry we couldn't resolve the issue. If you need further assistance, feel free to reach out anytime. Have a great day!",
215+
"participant": "assistant"
216+
}
217+
],
218+
[
219+
{
220+
"text": "Hello! How can I assist you with your calendar today?",
221+
"participant": "assistant"
222+
},
223+
{
224+
"text": "I'm having trouble with my calendar not syncing properly.",
225+
"participant": "user"
226+
},
227+
{
228+
"text": "I'm sorry to hear you're experiencing a sync delay. Can you tell me more about the issue?",
229+
"participant": "assistant"
230+
},
231+
{
232+
"text": "I think I'll handle it later. Thanks anyway.",
233+
"participant": "user"
234+
},
235+
{
236+
"text": "I'm sorry we couldn't resolve the issue. If you need further assistance, feel free to reach out anytime. Have a great day!",
237+
"participant": "assistant"
238+
}
239+
]
240+
]

0 commit comments

Comments
 (0)