Spaces:
Build error
Build error
Update loop_model.py
Browse files- loop_model.py +14 -23
loop_model.py
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from openai import OpenAI
|
| 2 |
import os
|
| 3 |
from datetime import datetime
|
|
|
|
|
|
|
| 4 |
|
| 5 |
EMOTION_MAP = {
|
| 6 |
"grief": ["loss", "death", "gone", "hurt", "grieve", "funeral"],
|
|
@@ -53,27 +61,10 @@ def get_recent_entries(limit=5):
|
|
| 53 |
return []
|
| 54 |
|
| 55 |
def get_echo_response(user_input):
|
| 56 |
-
|
| 57 |
-
return "Speak... or stay silent forever."
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
memory_block = "\n".join(memories)
|
| 65 |
-
|
| 66 |
-
try:
|
| 67 |
-
response = client.chat.completions.create(
|
| 68 |
-
model="gpt-3.5-turbo",
|
| 69 |
-
messages=[
|
| 70 |
-
{"role": "system", "content": emotion_prompt(emotion)},
|
| 71 |
-
{"role": "system", "content": f"Here are some of the user's previous thoughts:\n{memory_block}"},
|
| 72 |
-
{"role": "user", "content": user_input}
|
| 73 |
-
]
|
| 74 |
-
)
|
| 75 |
-
reply = response.choices[0].message.content
|
| 76 |
-
log_interaction(user_input, reply, emotion, voice_mode)
|
| 77 |
-
return reply
|
| 78 |
-
except Exception as e:
|
| 79 |
-
return f"Loop disrupted: {e}"
|
|
|
|
| 1 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")
|
| 2 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 3 |
+
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 4 |
+
torch_dtype=torch.float16,
|
| 5 |
+
device_map="auto"
|
| 6 |
+
)
|
| 7 |
from openai import OpenAI
|
| 8 |
import os
|
| 9 |
from datetime import datetime
|
| 10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 11 |
+
import torch
|
| 12 |
|
| 13 |
EMOTION_MAP = {
|
| 14 |
"grief": ["loss", "death", "gone", "hurt", "grieve", "funeral"],
|
|
|
|
| 61 |
return []
|
| 62 |
|
| 63 |
def get_echo_response(user_input):
|
| 64 |
+
prompt = f"[INST] You are EchoLoop, a reflective AI mirror. Respond with emotion and insight: {user_input} [/INST]"
|
|
|
|
| 65 |
|
| 66 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 67 |
+
outputs = model.generate(**inputs, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 68 |
+
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 69 |
+
|
| 70 |
+
return reply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|