Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from flask import Flask, request, jsonify
|
3 |
+
from mistralai.client import MistralClient
|
4 |
+
from mistralai.models.chat_completion import ChatMessage
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
# Ensure the environment variable for the API key is set
|
9 |
+
os.environ["MISTRAL_API_KEY"] = "JGKRrtZuxRncvjl32EI0EMFjvBUC10h7"
|
10 |
+
api_key = os.environ.get("MISTRAL_API_KEY")
|
11 |
+
if not api_key:
|
12 |
+
raise ValueError("MISTRAL_API_KEY environment variable not set")
|
13 |
+
|
14 |
+
model = "mistral-tiny"
|
15 |
+
client = MistralClient(api_key=api_key)
|
16 |
+
|
17 |
+
@app.route('/generate-goals', methods=['POST'])
|
18 |
+
def generate_goals():
|
19 |
+
input_var = request.json.get('input_var', '')
|
20 |
+
|
21 |
+
messages = [
|
22 |
+
ChatMessage(role="user", content=f"Generate 10 specific, industry relevant goals for {input_var} using Python and Pundos. Each goal should include a brief name and a one-sentence description of the task or skill. Focus on practical applications in educational assessment, covering areas such as data processing, statistical analysis, visualization, and advanced techniques")
|
23 |
+
]
|
24 |
+
|
25 |
+
# Ensure the model name is correct and exists
|
26 |
+
response = client.chat(model=model, messages=messages)
|
27 |
+
content = response.choices[0].message.content
|
28 |
+
|
29 |
+
return jsonify({'content': content})
|
30 |
+
|
31 |
+
if __name__ == '__main__':
|
32 |
+
app.run(debug=True)
|