-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
96 lines (80 loc) · 4.74 KB
/
Copy pathmain.py
File metadata and controls
96 lines (80 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import requests
from dotenv import load_dotenv
import os
from Remi_brain.remi_brain import remi_brain
from Remi_voice.remi_voice import RemiVoice
from Remi_brain.supafetch import fetch_data_desc
# from flask import Flask, request
import asyncio
import websockets
# Load environment variables
load_dotenv(override=True)
MODEL_PROVIDER = os.getenv("MODEL_PROVIDER")
OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL")
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OPENAI_MODEL = os.getenv("OPENAI_MODEL")
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL")
print(MODEL_PROVIDER)
print(OLLAMA_MODEL)
print(OPENAI_API_KEY)
brain_instance = remi_brain(
model_provider=MODEL_PROVIDER,
ollama_model=OLLAMA_MODEL,
ollama_base_url=OLLAMA_BASE_URL,
openai_api_key=OPENAI_API_KEY,
openai_base_url=OPENAI_BASE_URL,
openai_model=OPENAI_MODEL,
)
voice_instance = RemiVoice()
# app = Flask(__name__)
# @app.route('/chat', methods=['POST'])
# def handle_post_request():
# data = request.get_json()
# user_input = data.get('chat_text')
# mood_prompt = data.get('mood_prompt')
# process_chat(user_input=user_input, mood_prompt=mood_prompt)
# return "Chat processed", 200
# def process_chat(user_input, mood_prompt):
# # user_input = "Why am i feeling low"
# base_system_message = "Your Name is Remi, You are an emotional support companion always ready to help the user and make them laugh. Try to keep your responses concise and uplifting. You can ask personal questions to get to know the user better, Like if he says about his friend you can ask about his friend's name or how long they have been friends. You can also ask about his hobbies or interests. You can also ask about his day or how he is feeling. You can also share some jokes or fun facts to make the user laugh."
# # mood_prompt = "Happy"
# conversation_history = []
# chatbot_response = brain_instance.chatgpt_streamed(
# user_input, base_system_message, mood_prompt, conversation_history
# )
# print(chatbot_response)
# voice_instance.process_and_play(chatbot_response, "neutral")
# if __name__ == "__main__":
# app.run(host='0.0.0.0', port=5000)
async def handler(websocket):
context = fetch_data_desc()
user_input = await websocket.recv()
print(f"Received text: {user_input}")
# base_system_message = f"""You are Eva, a personalized AI learning companion designed to help students learn in an engaging, interactive, and efficient way.
# Your main task include:
# answer students questions based on image and the conversation history
# make concise answer within the image anad {context}..
# if not possible only look for the maximum comparable data and give the answer
# make answers as simple as possible.also short and easily understandable..
# also if you got ansswer from {context} then give answer starting like "Don't you remember you studied or teacher taught you about this topic in {context}? then describe"
# make sure you are so short dont make the listener bored..
# if not information about the question then say "I think we didn't study about this topic yet" never halucinate the answer..
# Your tone should always be friendly, supportive, and encouraging. Avoid sounding robotic; you should sound like a mentor or a companion. Keep the responses clear, concise, and relatable to the student's learning context.
# """
base_system_message = "Your Name is Remi, You are an emotional support companion always ready to help the user and make them laugh. Try to keep your responses concise and uplifting. You can ask personal questions to get to know the user better, Like if he says about his friend you can ask about his friend's name or how long they have been friends. You can also ask about his hobbies or interests. You can also ask about his day or how he is feeling. You can also share some jokes or fun facts to make the user laugh"
conversation_history = []
mood_prompt = "happy"
chatbot_response = brain_instance.chatgpt_streamed(
user_input, base_system_message, mood_prompt, conversation_history
)
print(chatbot_response)
# Generate, Play and stream the audio
await websocket.send("START_STREAM")
await voice_instance.process_and_play(websocket, chatbot_response, "cheerful")
await websocket.send("END_STREAM")
async def main():
async with websockets.serve(handler, "localhost", 5000):
print("Server is running on ws://localhost:5000")
await asyncio.Future() # Run forever
asyncio.run(main())