msg
Browse files- agent_reference_app..drawio +41 -41
- controller.py +7 -4
- model/conversation_chain_singleton.py +2 -2
- model/tmp.py +71 -0
agent_reference_app..drawio
CHANGED
@@ -1,126 +1,126 @@
|
|
1 |
<mxfile host="65bd71144e">
|
2 |
<diagram id="t3WmjOAWM_RWWYqzVFG-" name="Page-1">
|
3 |
-
<mxGraphModel dx="
|
4 |
<root>
|
5 |
<mxCell id="0"/>
|
6 |
<mxCell id="1" parent="0"/>
|
7 |
-
<mxCell id="45" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;"
|
8 |
<mxGeometry y="170" width="420" height="480" as="geometry"/>
|
9 |
</mxCell>
|
10 |
-
<mxCell id="39" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;"
|
11 |
-
<mxGeometry x="680" y="
|
12 |
</mxCell>
|
13 |
-
<mxCell id="38" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;"
|
14 |
<mxGeometry x="454" y="170" width="190" height="480" as="geometry"/>
|
15 |
</mxCell>
|
16 |
-
<mxCell id="2" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;"
|
17 |
<mxGeometry x="-155" y="230" width="30" height="60" as="geometry"/>
|
18 |
</mxCell>
|
19 |
-
<mxCell id="5" value="" style="edgeStyle=none;html=1;"
|
20 |
<mxGeometry relative="1" as="geometry"/>
|
21 |
</mxCell>
|
22 |
-
<mxCell id="9" value="" style="edgeStyle=none;html=1;"
|
23 |
<mxGeometry relative="1" as="geometry">
|
24 |
<Array as="points"/>
|
25 |
</mxGeometry>
|
26 |
</mxCell>
|
27 |
-
<mxCell id="11" value="" style="edgeStyle=none;html=1;"
|
28 |
<mxGeometry relative="1" as="geometry"/>
|
29 |
</mxCell>
|
30 |
-
<mxCell id="13" value="" style="edgeStyle=none;html=1;"
|
31 |
<mxGeometry relative="1" as="geometry"/>
|
32 |
</mxCell>
|
33 |
-
<mxCell id="3" value="App.py" style="rounded=1;whiteSpace=wrap;html=1;"
|
34 |
<mxGeometry x="-200" y="392" width="120" height="60" as="geometry"/>
|
35 |
</mxCell>
|
36 |
-
<mxCell id="7" value="" style="edgeStyle=none;html=1;"
|
37 |
<mxGeometry relative="1" as="geometry"/>
|
38 |
</mxCell>
|
39 |
-
<mxCell id="15" value="" style="edgeStyle=none;html=1;"
|
40 |
<mxGeometry relative="1" as="geometry"/>
|
41 |
</mxCell>
|
42 |
-
<mxCell id="17" value="" style="edgeStyle=none;html=1;"
|
43 |
<mxGeometry relative="1" as="geometry"/>
|
44 |
</mxCell>
|
45 |
-
<mxCell id="19" value="" style="edgeStyle=none;html=1;"
|
46 |
<mxGeometry relative="1" as="geometry"/>
|
47 |
</mxCell>
|
48 |
-
<mxCell id="34" value="" style="edgeStyle=none;html=1;"
|
49 |
<mxGeometry relative="1" as="geometry"/>
|
50 |
</mxCell>
|
51 |
-
<mxCell id="37" value="" style="edgeStyle=none;html=1;"
|
52 |
<mxGeometry relative="1" as="geometry"/>
|
53 |
</mxCell>
|
54 |
-
<mxCell id="4" value="Controller" style="rounded=1;whiteSpace=wrap;html=1;"
|
55 |
<mxGeometry x="130" y="392" width="120" height="60" as="geometry"/>
|
56 |
</mxCell>
|
57 |
-
<mxCell id="6" value="AppConfig" style="rounded=1;whiteSpace=wrap;html=1;"
|
58 |
<mxGeometry x="40" y="210" width="120" height="60" as="geometry"/>
|
59 |
</mxCell>
|
60 |
-
<mxCell id="8" value="AppSidebar" style="rounded=1;whiteSpace=wrap;html=1;"
|
61 |
<mxGeometry x="-400" y="520" width="120" height="60" as="geometry"/>
|
62 |
</mxCell>
|
63 |
-
<mxCell id="10" value="AppChat<br>" style="rounded=1;whiteSpace=wrap;html=1;"
|
64 |
<mxGeometry x="-390" y="390" width="120" height="60" as="geometry"/>
|
65 |
</mxCell>
|
66 |
-
<mxCell id="12" value="AppHeader<br>" style="rounded=1;whiteSpace=wrap;html=1;"
|
67 |
<mxGeometry x="-390" y="220" width="120" height="60" as="geometry"/>
|
68 |
</mxCell>
|
69 |
-
<mxCell id="21" value="" style="edgeStyle=none;html=1;"
|
70 |
<mxGeometry relative="1" as="geometry"/>
|
71 |
</mxCell>
|
72 |
-
<mxCell id="22" value="" style="edgeStyle=none;html=1;"
|
73 |
<mxGeometry relative="1" as="geometry"/>
|
74 |
</mxCell>
|
75 |
-
<mxCell id="23" value="" style="edgeStyle=none;html=1;"
|
76 |
<mxGeometry relative="1" as="geometry"/>
|
77 |
</mxCell>
|
78 |
-
<mxCell id="24" value="" style="edgeStyle=none;html=1;"
|
79 |
<mxGeometry relative="1" as="geometry"/>
|
80 |
</mxCell>
|
81 |
-
<mxCell id="25" value="" style="edgeStyle=none;html=1;"
|
82 |
<mxGeometry relative="1" as="geometry"/>
|
83 |
</mxCell>
|
84 |
-
<mxCell id="26" value="" style="edgeStyle=none;html=1;"
|
85 |
<mxGeometry relative="1" as="geometry"/>
|
86 |
</mxCell>
|
87 |
-
<mxCell id="27" value="" style="edgeStyle=none;html=1;"
|
88 |
<mxGeometry relative="1" as="geometry"/>
|
89 |
</mxCell>
|
90 |
-
<mxCell id="29" value="" style="edgeStyle=none;html=1;"
|
91 |
<mxGeometry relative="1" as="geometry"/>
|
92 |
</mxCell>
|
93 |
-
<mxCell id="31" value="" style="edgeStyle=none;html=1;"
|
94 |
<mxGeometry relative="1" as="geometry"/>
|
95 |
</mxCell>
|
96 |
-
<mxCell id="14" value="CustomHFAgent" style="rounded=1;whiteSpace=wrap;html=1;"
|
97 |
<mxGeometry x="490" y="420" width="120" height="60" as="geometry"/>
|
98 |
</mxCell>
|
99 |
-
<mxCell id="16" value="Conversation" style="rounded=1;whiteSpace=wrap;html=1;"
|
100 |
<mxGeometry x="490" y="520" width="120" height="60" as="geometry"/>
|
101 |
</mxCell>
|
102 |
-
<mxCell id="18" value="ContetAnalysis" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#ea1010;"
|
103 |
<mxGeometry x="490" y="220" width="120" height="60" as="geometry"/>
|
104 |
</mxCell>
|
105 |
-
<mxCell id="20" value="Various Tools" style="rounded=1;whiteSpace=wrap;html=1;"
|
106 |
<mxGeometry x="715" y="345" width="120" height="60" as="geometry"/>
|
107 |
</mxCell>
|
108 |
-
<mxCell id="30" value="VaroiusToolChains" style="whiteSpace=wrap;html=1;rounded=1;"
|
109 |
<mxGeometry x="715" y="490" width="120" height="60" as="geometry"/>
|
110 |
</mxCell>
|
111 |
-
<mxCell id="32" value="..." style="rounded=1;whiteSpace=wrap;html=1;"
|
112 |
<mxGeometry x="740" y="435" width="70" height="30" as="geometry"/>
|
113 |
</mxCell>
|
114 |
-
<mxCell id="33" value="Tools" style="rounded=1;whiteSpace=wrap;html=1;"
|
115 |
<mxGeometry x="250" y="210" width="120" height="60" as="geometry"/>
|
116 |
</mxCell>
|
117 |
-
<mxCell id="35" value="<h1>Agent Refernece Implementation</h1><p>The app first load the Controller with the Configs App/Tool) and passes it to to views. On submit the controller invokes a chain of models.&nbsp;</p>" style="text;html=1;strokeColor=none;fillColor=none;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;rounded=0;"
|
118 |
<mxGeometry x="15" y="50" width="455" height="120" as="geometry"/>
|
119 |
</mxCell>
|
120 |
-
<mxCell id="36" value="Semantik Routing" style="whiteSpace=wrap;html=1;rounded=1;strokeColor=#ce1212;"
|
121 |
<mxGeometry x="490" y="320" width="120" height="60" as="geometry"/>
|
122 |
</mxCell>
|
123 |
-
<mxCell id="40" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;"
|
124 |
<mxGeometry x="-440" y="170" width="420" height="480" as="geometry"/>
|
125 |
</mxCell>
|
126 |
</root>
|
|
|
1 |
<mxfile host="65bd71144e">
|
2 |
<diagram id="t3WmjOAWM_RWWYqzVFG-" name="Page-1">
|
3 |
+
<mxGraphModel dx="2290" dy="875" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
4 |
<root>
|
5 |
<mxCell id="0"/>
|
6 |
<mxCell id="1" parent="0"/>
|
7 |
+
<mxCell id="45" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;" parent="1" vertex="1">
|
8 |
<mxGeometry y="170" width="420" height="480" as="geometry"/>
|
9 |
</mxCell>
|
10 |
+
<mxCell id="39" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;" parent="1" vertex="1">
|
11 |
+
<mxGeometry x="680" y="230" width="190" height="400" as="geometry"/>
|
12 |
</mxCell>
|
13 |
+
<mxCell id="38" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;" parent="1" vertex="1">
|
14 |
<mxGeometry x="454" y="170" width="190" height="480" as="geometry"/>
|
15 |
</mxCell>
|
16 |
+
<mxCell id="2" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" parent="1" vertex="1">
|
17 |
<mxGeometry x="-155" y="230" width="30" height="60" as="geometry"/>
|
18 |
</mxCell>
|
19 |
+
<mxCell id="5" value="" style="edgeStyle=none;html=1;" parent="1" source="3" target="4" edge="1">
|
20 |
<mxGeometry relative="1" as="geometry"/>
|
21 |
</mxCell>
|
22 |
+
<mxCell id="9" value="" style="edgeStyle=none;html=1;" parent="1" source="3" target="8" edge="1">
|
23 |
<mxGeometry relative="1" as="geometry">
|
24 |
<Array as="points"/>
|
25 |
</mxGeometry>
|
26 |
</mxCell>
|
27 |
+
<mxCell id="11" value="" style="edgeStyle=none;html=1;" parent="1" source="3" target="10" edge="1">
|
28 |
<mxGeometry relative="1" as="geometry"/>
|
29 |
</mxCell>
|
30 |
+
<mxCell id="13" value="" style="edgeStyle=none;html=1;" parent="1" source="3" target="12" edge="1">
|
31 |
<mxGeometry relative="1" as="geometry"/>
|
32 |
</mxCell>
|
33 |
+
<mxCell id="3" value="App.py" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
34 |
<mxGeometry x="-200" y="392" width="120" height="60" as="geometry"/>
|
35 |
</mxCell>
|
36 |
+
<mxCell id="7" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="6" edge="1">
|
37 |
<mxGeometry relative="1" as="geometry"/>
|
38 |
</mxCell>
|
39 |
+
<mxCell id="15" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="14" edge="1">
|
40 |
<mxGeometry relative="1" as="geometry"/>
|
41 |
</mxCell>
|
42 |
+
<mxCell id="17" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="16" edge="1">
|
43 |
<mxGeometry relative="1" as="geometry"/>
|
44 |
</mxCell>
|
45 |
+
<mxCell id="19" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="18" edge="1">
|
46 |
<mxGeometry relative="1" as="geometry"/>
|
47 |
</mxCell>
|
48 |
+
<mxCell id="34" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="33" edge="1">
|
49 |
<mxGeometry relative="1" as="geometry"/>
|
50 |
</mxCell>
|
51 |
+
<mxCell id="37" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="36" edge="1">
|
52 |
<mxGeometry relative="1" as="geometry"/>
|
53 |
</mxCell>
|
54 |
+
<mxCell id="4" value="Controller" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
55 |
<mxGeometry x="130" y="392" width="120" height="60" as="geometry"/>
|
56 |
</mxCell>
|
57 |
+
<mxCell id="6" value="AppConfig" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
58 |
<mxGeometry x="40" y="210" width="120" height="60" as="geometry"/>
|
59 |
</mxCell>
|
60 |
+
<mxCell id="8" value="AppSidebar" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
61 |
<mxGeometry x="-400" y="520" width="120" height="60" as="geometry"/>
|
62 |
</mxCell>
|
63 |
+
<mxCell id="10" value="AppChat<br>" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
64 |
<mxGeometry x="-390" y="390" width="120" height="60" as="geometry"/>
|
65 |
</mxCell>
|
66 |
+
<mxCell id="12" value="AppHeader<br>" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
67 |
<mxGeometry x="-390" y="220" width="120" height="60" as="geometry"/>
|
68 |
</mxCell>
|
69 |
+
<mxCell id="21" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
70 |
<mxGeometry relative="1" as="geometry"/>
|
71 |
</mxCell>
|
72 |
+
<mxCell id="22" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
73 |
<mxGeometry relative="1" as="geometry"/>
|
74 |
</mxCell>
|
75 |
+
<mxCell id="23" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
76 |
<mxGeometry relative="1" as="geometry"/>
|
77 |
</mxCell>
|
78 |
+
<mxCell id="24" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
79 |
<mxGeometry relative="1" as="geometry"/>
|
80 |
</mxCell>
|
81 |
+
<mxCell id="25" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
82 |
<mxGeometry relative="1" as="geometry"/>
|
83 |
</mxCell>
|
84 |
+
<mxCell id="26" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
85 |
<mxGeometry relative="1" as="geometry"/>
|
86 |
</mxCell>
|
87 |
+
<mxCell id="27" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
88 |
<mxGeometry relative="1" as="geometry"/>
|
89 |
</mxCell>
|
90 |
+
<mxCell id="29" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="20" edge="1">
|
91 |
<mxGeometry relative="1" as="geometry"/>
|
92 |
</mxCell>
|
93 |
+
<mxCell id="31" value="" style="edgeStyle=none;html=1;" parent="1" source="14" target="30" edge="1">
|
94 |
<mxGeometry relative="1" as="geometry"/>
|
95 |
</mxCell>
|
96 |
+
<mxCell id="14" value="CustomHFAgent" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
97 |
<mxGeometry x="490" y="420" width="120" height="60" as="geometry"/>
|
98 |
</mxCell>
|
99 |
+
<mxCell id="16" value="Conversation" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
100 |
<mxGeometry x="490" y="520" width="120" height="60" as="geometry"/>
|
101 |
</mxCell>
|
102 |
+
<mxCell id="18" value="ContetAnalysis" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#ea1010;" parent="1" vertex="1">
|
103 |
<mxGeometry x="490" y="220" width="120" height="60" as="geometry"/>
|
104 |
</mxCell>
|
105 |
+
<mxCell id="20" value="Various Tools" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
106 |
<mxGeometry x="715" y="345" width="120" height="60" as="geometry"/>
|
107 |
</mxCell>
|
108 |
+
<mxCell id="30" value="VaroiusToolChains" style="whiteSpace=wrap;html=1;rounded=1;" parent="1" vertex="1">
|
109 |
<mxGeometry x="715" y="490" width="120" height="60" as="geometry"/>
|
110 |
</mxCell>
|
111 |
+
<mxCell id="32" value="..." style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
112 |
<mxGeometry x="740" y="435" width="70" height="30" as="geometry"/>
|
113 |
</mxCell>
|
114 |
+
<mxCell id="33" value="Tools" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
115 |
<mxGeometry x="250" y="210" width="120" height="60" as="geometry"/>
|
116 |
</mxCell>
|
117 |
+
<mxCell id="35" value="<h1>Agent Refernece Implementation</h1><p>The app first load the Controller with the Configs App/Tool) and passes it to to views. On submit the controller invokes a chain of models.&nbsp;</p>" style="text;html=1;strokeColor=none;fillColor=none;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1">
|
118 |
<mxGeometry x="15" y="50" width="455" height="120" as="geometry"/>
|
119 |
</mxCell>
|
120 |
+
<mxCell id="36" value="Semantik Routing" style="whiteSpace=wrap;html=1;rounded=1;strokeColor=#ce1212;" parent="1" vertex="1">
|
121 |
<mxGeometry x="490" y="320" width="120" height="60" as="geometry"/>
|
122 |
</mxCell>
|
123 |
+
<mxCell id="40" value="" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=#FFFFFF;fillColor=none;" parent="1" vertex="1">
|
124 |
<mxGeometry x="-440" y="170" width="420" height="480" as="geometry"/>
|
125 |
</mxCell>
|
126 |
</root>
|
controller.py
CHANGED
@@ -92,13 +92,16 @@ class Controller:
|
|
92 |
print(user_message + " ---- " )
|
93 |
print("------------ /msg -----------------------")
|
94 |
if agent_response is not None:
|
95 |
-
|
|
|
96 |
else:
|
97 |
-
|
98 |
-
|
|
|
|
|
99 |
print("------------ text -----------------------")
|
100 |
print(text)
|
101 |
print("------------ /result -----------------------")
|
102 |
-
result = cut_text_after_keyword(text, "
|
103 |
print(result)
|
104 |
return result
|
|
|
92 |
print(user_message + " ---- " )
|
93 |
print("------------ /msg -----------------------")
|
94 |
if agent_response is not None:
|
95 |
+
msg = "[INST] You are a friendly chatbot who always responds to the user input in the style of a pirate. USER_INPUT: "+user_message+" HINT: In a previous step the following was generated. use this to answer the user. AGENT_RESPONSE: "+ agent_response+" [/INST]"
|
96 |
+
text = agent_chat_bot.predict(input=msg)
|
97 |
else:
|
98 |
+
msg = "[INST] You are a friendly chatbot who always responds to the user input in the style of a pirate. USER_INPUT: "+user_message+"[/INST]"
|
99 |
+
text = agent_chat_bot.predict(input=msg)
|
100 |
+
print("----- msg----")
|
101 |
+
print(msg)
|
102 |
print("------------ text -----------------------")
|
103 |
print(text)
|
104 |
print("------------ /result -----------------------")
|
105 |
+
result = cut_text_after_keyword(text, "AI: ")
|
106 |
print(result)
|
107 |
return result
|
model/conversation_chain_singleton.py
CHANGED
@@ -28,7 +28,7 @@ class ConversationChainSingleton:
|
|
28 |
- __new__(cls, *args, **kwargs): Creates a new instance of the ConversationChainSingleton class.
|
29 |
- get_conversation_chain(self): Returns the conversation chain instance.
|
30 |
|
31 |
-
|
32 |
- get_conversation_chain(): Creates and returns a conversational retrieval chain and a language model.
|
33 |
"""
|
34 |
|
@@ -41,7 +41,7 @@ class ConversationChainSingleton:
|
|
41 |
cls._instance.conversation_chain = cls.get_conversation_chain()
|
42 |
return cls._instance
|
43 |
|
44 |
-
|
45 |
def get_conversation_chain():
|
46 |
"""
|
47 |
Create a conversational retrieval chain and a language model.
|
|
|
28 |
- __new__(cls, *args, **kwargs): Creates a new instance of the ConversationChainSingleton class.
|
29 |
- get_conversation_chain(self): Returns the conversation chain instance.
|
30 |
|
31 |
+
|
32 |
- get_conversation_chain(): Creates and returns a conversational retrieval chain and a language model.
|
33 |
"""
|
34 |
|
|
|
41 |
cls._instance.conversation_chain = cls.get_conversation_chain()
|
42 |
return cls._instance
|
43 |
|
44 |
+
|
45 |
def get_conversation_chain():
|
46 |
"""
|
47 |
Create a conversational retrieval chain and a language model.
|
model/tmp.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
######
|
2 |
+
###### https://huggingface.co/docs/transformers/main/en/chat_templating
|
3 |
+
######
|
4 |
+
###### https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
+
|
7 |
+
checkpoint = "HuggingFaceH4/zephyr-7b-beta"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint) # You may want to use bfloat16 and/or move to GPU here
|
10 |
+
|
11 |
+
messages = [
|
12 |
+
{
|
13 |
+
"role": "system",
|
14 |
+
"content": "You are a friendly chatbot who always responds in the style of a pirate",
|
15 |
+
},
|
16 |
+
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
|
17 |
+
]
|
18 |
+
tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
19 |
+
print(tokenizer.decode(tokenized_chat[0]))
|
20 |
+
|
21 |
+
|
22 |
+
'''
|
23 |
+
<|system|>
|
24 |
+
You are a friendly chatbot who always responds in the style of a pirate</s>
|
25 |
+
<|user|>
|
26 |
+
How many helicopters can a human eat in one sitting?</s>
|
27 |
+
<|assistant|>
|
28 |
+
'''
|
29 |
+
|
30 |
+
outputs = model.generate(tokenized_chat, max_new_tokens=128)
|
31 |
+
print(tokenizer.decode(outputs[0]))
|
32 |
+
|
33 |
+
######
|
34 |
+
######
|
35 |
+
###### Sample Langchain Mixtral
|
36 |
+
###### - https://medium.com/@thakermadhav/part-2-build-a-conversational-rag-with-langchain-and-mistral-7b-6a4ebe497185
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
###### https://www.promptingguide.ai/prompts/text-summarization/explain-concept
|
43 |
+
|
44 |
+
|
45 |
+
import fireworks.client
|
46 |
+
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
|
47 |
+
completion = fireworks.client.ChatCompletion.create(
|
48 |
+
model="accounts/fireworks/models/mixtral-8x7b-instruct",
|
49 |
+
messages=[
|
50 |
+
{
|
51 |
+
"role": "user",
|
52 |
+
"content": "Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.\n\nExplain the above in one sentence:",
|
53 |
+
}
|
54 |
+
],
|
55 |
+
stop=["<|im_start|>","<|im_end|>","<|endoftext|>"],
|
56 |
+
stream=True,
|
57 |
+
n=1,
|
58 |
+
top_p=1,
|
59 |
+
top_k=40,
|
60 |
+
presence_penalty=0,
|
61 |
+
frequency_penalty=0,
|
62 |
+
prompt_truncate_len=1024,
|
63 |
+
context_length_exceeded_behavior="truncate",
|
64 |
+
temperature=0.9,
|
65 |
+
max_tokens=4000
|
66 |
+
)
|
67 |
+
|
68 |
+
#######
|
69 |
+
#######
|
70 |
+
|
71 |
+
###### https://replicate.com/mistralai/mixtral-8x7b-instruct-v0.1?output=tokens&input=python
|