Spaces:
Sleeping
Sleeping
Doux Thibault
commited on
Commit
·
355c1bd
1
Parent(s):
006c8dd
add router script
Browse files- Modules/router.py +29 -0
Modules/router.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
load_dotenv()
|
| 5 |
+
mistral_api_key = os.getenv("MISTRAL_API_KEY")
|
| 6 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 7 |
+
from langchain_mistralai import ChatMistralAI
|
| 8 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 9 |
+
|
| 10 |
+
router_chain = (
|
| 11 |
+
ChatPromptTemplate.from_template(
|
| 12 |
+
"""Given the user question below, classify it as either being about :
|
| 13 |
+
- `fitness_advices` if the user query is about nutrition or fitness program, exercices
|
| 14 |
+
- `movement_analysis` if the user asks to analyse or give advice on his exercice execution?
|
| 15 |
+
- `smalltalk` if other.
|
| 16 |
+
|
| 17 |
+
Do not respond with more than one word.
|
| 18 |
+
|
| 19 |
+
<question>
|
| 20 |
+
{question}
|
| 21 |
+
</question>
|
| 22 |
+
|
| 23 |
+
Classification:"""
|
| 24 |
+
)
|
| 25 |
+
| ChatMistralAI(model="mistral-large-latest", mistral_api_key=mistral_api_key, temperature=0)
|
| 26 |
+
| StrOutputParser()
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# print(chain.invoke({"question": "Hi AI Bro coach! how are you? I was thinking about going to the gym today. What can i train?"}))
|