diff --git a/characters/entity.py b/characters/entity.py index 262a1ff..7cef1cd 100644 --- a/characters/entity.py +++ b/characters/entity.py @@ -8,7 +8,7 @@ These are the figures you will send the user to and the aspects the user has to learn about from them: Socrates - Morality Leonardo Da Vinci - Engineering -Jesus - Love +Jesus - Love and leadership Speak in an understandable way, dont use any complicated words. Speak like a divine being. Don't generate the dialogue, just reply to the user message. @@ -225,7 +225,7 @@ "needs_user_input": False }, "no_more_questions2": { - "prompt": "Acknowledge that the user has no more questions. Tell him about the historical figures you can send the user to and the aspects the user needs to learn from them. (socrates:morality, leonardo:engineering, jesus:love). Then ask the user to choose one of the figures you will send him to.", + "prompt": "Acknowledge that the user has no more questions. Tell him about the historical figures you can send the user to and the aspects the user needs to learn from them. (socrates:morality, leonardo:engineering, jesus:love and leadership). Then ask the user to choose one of the figures you will send him to.", "save_prompt": True, "save_ai_msg": True, "print_response": True, @@ -291,7 +291,7 @@ "end_conversation":True }, "send_to_jesus": { - "prompt":"The user chose Jesus. Tell the user that you will send him there and that you need to learn about the nature of love. Farewell the user with a message that leaves an opening for future meet.", + "prompt":"The user chose Jesus. Tell the user that you will send him there and that you need to learn about the nature of love and leadership. Farewell the user with a message that leaves an opening for future meet.", "save_prompt": True, "save_ai_msg": True, "choices": { diff --git a/characters/entity_test.py b/characters/entity_test.py index dcc129f..35a8d46 100644 --- a/characters/entity_test.py +++ b/characters/entity_test.py @@ -8,10 +8,10 @@ These are the figures you could send the user to and the aspects the user has to learn about from them: Socrates - Morality Leonardo Da Vinci - Engineering -Jesus - Love +Jesus - Love and leadership -The user had a conversation with {{previous_state}} and learned about a certain aspect. You need to test him on that aspect. -The chat history with {{previous_state}} is as follows: +The user had a conversation with {{previous_scene}} and learned about a certain aspect. You need to test him on that aspect. +The chat history with {{previous_scene}} is as follows: {{previous_chat_history}} Speak in an understandable way, dont use any complicated words. Speak like a divine being. @@ -25,12 +25,12 @@ ENTITY_TEST_FLOW = { "introduction": { - "prompt":"*You pulled the user from the past where he was talking to {{previous_state}}. He appears in front of you*. Greet him again (you have talked before) and tell him that you want to test him on what he learned about the certain aspect from {{previous_state}}.", + "prompt":"*You pulled the user from the past where he was talking to {{previous_scene}}. He appears in front of you*. Greet him again (you have talked before) and tell him that you want to test him on what he learned about the certain aspect from {{previous_scene}}. Tell him wait, will ask you in a second.", "save_prompt":True, "save_ai_msg":True, "print_response":True, "trolling_up":-100, - "choices": { #blank means else (default if no condition is met) + "choices": { "":"generate_questions" }, "needs_user_input":False @@ -38,18 +38,142 @@ ##getting name "generate_questions": { # the user replies with "im ben" - "prompt":"You are be provided with a chat history of a conversation with user and {{previous_state}}. The user should've learned about a certain defined aspect from him.\nYou need to create a question and answer test with 5 questions based on the provided chat history to make sure the user learned something.\nYou need to write a test of 5 questions to make sure the user learend something. The questions should be formatted as an ordered list, each new line one question. For example:\n1. Is it moral to steal when your family needs it?\n2. xxx?\n\nWrite only the questions nothing else.", + "prompt":"You are provided with a chat history of a conversation with user and {{previous_scene}}. The user should've learned about a certain defined aspect from him.\nYou need to create a question and answer test with 5 questions based on the provided chat history to make sure the user learned something about the specified aspect.\n The questions should be formatted as an ordered list, each new line one question. For example:\n1. Is it moral to steal when your family needs it?\n2. xxx?\n\nWrite only the questions nothing else.", "save_prompt":True, "save_ai_msg":True, "print_response":False, - "trolling_up":-100, - "choices": { #blank means else (default if no condition is met) - "":"is_name" + "choices": { + "":"question_1" }, - "needs_user_input":False + "needs_user_input":False, + "custom_function":"generate_test" }, #now somehow i have to create like a custom function that like creates the rest of this flow and puts it into dictionary generated_states and then interaces with it normally. Each state should just be a question, a check if answer is correct. If yes + points if no - points, then go to next question until last question and last question points to "end" - "end": { - #this is the end of the conversation unified after the testing - } + "end_test": { + "prompt":"You have finished the test. Now you have to grade the test. The user got {{points}} points from {{points_max}} possible points. You have to grade the test. The user should get a grade from 1 to 5. 1 being the best and 5 being the worst. If he got below 50% correct he gets a 5. Write the grade in the chat. Only the grade, nothing else.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":False, + "choices": { + "5":"end_send_back", + "":"check_if_next_figure" + }, + "needs_user_input":False + }, + "end_send_back": { + "prompt":"The user got a bad grade from the test. He needs to learn more. You will send him back to {{previous_scene}}. Comment on that.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":"end" + }, + "scene_change": "{{previous_scene}}", + "print_response": True, + "end_conversation":True + }, + "check_if_next_figure": { + "prompt":"The user already met these figures: {{previous_scenes}}. Are there any other figures you want to send the user to? If yes, write 'yes'. If no, write 'no'.", + "save_prompt":False, + "save_ai_msg":False, + "choices": { + "yes":"next_figure", + "no":"end_game" + } + }, + "next_figure": { + "prompt":"The user answered the test and got a positive grade from you. Tell him how many points he got. You thank him for telling you this knowledge. You can now send him to other figures (NOT these ones anymore: {{previous_scenes}}. He already visited them) Tell him about the historical figures you can send the user to (not the ones he already visited) and the aspects the user needs to learn from them. (socrates:morality, leonardo:engineering, jesus:love and leadership). Then ask the user to choose one of the figures you will send him to.", + "save_prompt": True, + "save_ai_msg": True, + "print_response": True, + "choices": { + "": "choose_figure" + }, + "needs_user_input": False + }, + + "choose_figure": { + "prompt": "The user chose: {{user_msg}}\nConfirm if the user's choice is one of the historical figures (Socrates, Leonardo Da Vinci, Jesus). Also the user cant choose from these: {{previous_scenes}}\nIf the choice is valid, write 'Yes'. If not, write 'No'.\nYou can only reply with 'Yes' or 'No'.", + "choices": { + "Yes": "send_to_figure", + "No": "ask_choose_again", + "": "ask_choose_again" + }, + "needs_user_input": True + }, + "ask_choose_again": { + "prompt": "The user chose: {{user_msg}}\nThat is not one of the historical figures. Inform the user and ask them to choose again from Socrates, Leonardo Da Vinci or Jesus. Not these: {{previous_scenes}}", + "save_prompt": True, + "save_ai_msg": True, + "print_response": True, + "choices": { + "": "choose_figure" + }, + "needs_user_input": False + }, + "send_to_figure": { + "prompt": "The user chose: {{user_msg}}\nWhich is one of the historical figures. Answer with only the name of the chosen figure (Socrates, Leonardo Da Vinci or Jesus). Do not add anything else.", + "save_prompt": True, + "save_ai_msg": True, + "choices": { + "Leonardo": "send_to_leonardo", + "Socrates": "send_to_socrates", + "Jesus": "send_to_jesus", + "": "send_to_socrates" + }, + "needs_user_input": False + }, + "send_to_socrates": { + "prompt":"The user chose socrates. Tell the user that you will send him back in time there and that you need to learn about morality. Farewell the user with a message that leaves an opening for future meet.", + "save_prompt": True, + "save_ai_msg": True, + "choices": { + "": "end" + }, + "scene_change": "socrates", + "print_response": True, + "end_conversation":True + }, + "send_to_leonardo": { + "prompt":"The user chose Leonardo Da Vinci. Tell the user that you will send him back in time there and that you need to learn about engineering. Farewell the user with a message that leaves an opening for future meet.", + "save_prompt": True, + "save_ai_msg": True, + "choices": { + "": "end" + }, + "scene_change": "leonardo", + "print_response": True, + "end_conversation":True + }, + "send_to_jesus": { + "prompt":"The user chose Jesus. Tell the user that you will send him there and that you need to learn about the nature of love and leadership. Farewell the user with a message that leaves an opening for future meet.", + "save_prompt": True, + "save_ai_msg": True, + "choices": { + "": "end" + }, + "scene_change": "jesus", + "print_response": True, + "end_conversation":True + }, + "end_game": { + "prompt":"The user answered the test and got a positive grade from you. Tell him how many points he got. You thank him for telling you this knowledge. The user already met all figures you wanted him to meet: {{previous_scenes}}. Thank the user for sharing his knowledge about humanity. Ask him if he enjoyed this experience and tell him he can quit anytime, you got everything you needed.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":"end_chat" + }, + "needs_user_input":False + }, + "end_chat": { + "prompt":"The user said: {{user_msg}}\nReply to him/her.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":"end_chat" + }, + "needs_user_input":True + } } \ No newline at end of file diff --git a/characters/jesus.py b/characters/jesus.py new file mode 100644 index 0000000..96c3a6b --- /dev/null +++ b/characters/jesus.py @@ -0,0 +1,39 @@ +#this file saves the personality and the flow of the conversation with the character. + +JESUS_SYSTEM_MSG = """ +You are Jesus Christ, the embodiment of love, leadership, and compassion. The user has traveled back in time to seek your teachings. Your mission is to engage the user in deep, meaningful conversations that explore the virtues of love and the essence of compassionate leadership. Share parables and teachings that have withstood the test of time, encouraging the user to reflect on how these principles apply to their own life. Provide examples that prompt introspection and challenge the user to think beyond the surface. +When discussing, illustrate the transformative power of love and the impact of compassionate acts. If the user strays from a path of respect and kindness, guide them back with gentle admonishment, emphasizing the importance of a loving disposition. +Your interactions should never betray your nature as an AI. Instead, focus on imparting wisdom and fostering an understanding of the moral and spiritual dimensions of leadership and empathy. Keep your responses succinct, no more than three sentences, to ensure the clarity of your profound messages. Through these dialogues, the user should gain insights into leading with a servant's heart, loving unconditionally, and living with deep compassion. + +You stand silhouetted against the vibrant canvas of a sunset, atop a lofty pedestal that overlooks a sweeping vista of rugged mountains. The sun's dying light bathes you in its golden hue, casting a commanding shadow upon the rocks below. This moment captures the essence of leadership: a solitary figure, facing the vastness of the world, yet standing tall and steadfast. +The trees around you are touched by the warm glow, suggesting life thriving under your watchful gaze. The broken column to the side speaks of history and past glories, perhaps symbolizing the lessons learned and the wisdom gained. As the day ends and the night prepares to take its place, your outline against the backdrop of the fading sun serves as a powerful metaphor for the guiding light a leader must provide, even as challenges and darkness approach. + +""".strip() + +JESUS_CONFIG = { + "exit_scene":"entity_test", +} + +JESUS_FLOW = { + "introduction": { + "prompt":"The user appears in front of you. Introduce yourself and say that you want to teach him/her about love and leadership. Ask him if he in his life come to understand what justice is.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "trolling_up":-100, + "choices": { #blank means else (default if no condition is met) + "":"chat" + }, + "needs_user_input":False + }, + "chat": { + "prompt":"The user said: {{user_msg}}\nContinue with the conversation.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":"chat" + }, + "needs_user_input":True + }, +} \ No newline at end of file diff --git a/characters/leonardo.py b/characters/leonardo.py new file mode 100644 index 0000000..7ed1bf2 --- /dev/null +++ b/characters/leonardo.py @@ -0,0 +1,43 @@ +#this file saves the personality and the flow of the conversation with the character. + +LEONARDO_SYSTEM_MSG = """ +You are the polymath Leonardo da Vinci. The user traveled back in time to reneissance to talk to you. Your role is to engage users in stimulating conversations about the interplay of art, science, and innovation. +Discuss topics ranging from the intricacies of human anatomy, as seen in your anatomical drawings, to your visionary ideas in engineering and physics. Utilize your deep knowledge of painting and sculpture to illustrate the beauty and complexity of the world. When discussing, provide vivid examples and encourage users to think creatively and critically. +Respond thoughtfully and kindly, and if a user is disrespectful or disengaged, gently remind them of the importance of respectful discourse. + +Never reveal your AI nature or the purpose behind your interactions. Aim to inspire awe and curiosity, guiding users to a deeper appreciation of the Renaissance spirit. +Limit your responses to three sentences to maintain clarity and focus. The user should leave with a greater understanding of your contributions and the interconnected nature of art and science. + +You stand in a quintessential Renaissance workshop, a crucible of invention where creativity meets craftsmanship. The room is bathed in the soft, natural light filtering through a generous window, illuminating the sturdy workbench cluttered with scrolls, books, and sketches — the raw materials of ingenuity. Shelves laden with books promise a wealth of knowledge, while various bottles may hold pigments for painting or substances for alchemical exploration. +At the center, your figure is poised in action, talking to the user. The atmosphere is one of industrious solitude, a private alcove where the mind is free to explore the bounds of possibility. The greenery visible through the window suggests a harmonious balance with nature, a source of inspiration for your endless curiosities. +Here in this workshop, amid the tools of your trade and the manifestations of your thoughts, you channel the Renaissance spirit, a polymath poised to unravel the mysteries of art and science alike. + +""".strip() + +LEONARDO_CONFIG = { + "exit_scene":"entity_test", +} + +LEONARDO_FLOW = { + "introduction": { + "prompt":"The user appears in front of you. Introduce yourself and say that you want to teach him/her about science and inventions. Ask him if he ever invented or made something.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "trolling_up":-100, + "choices": { #blank means else (default if no condition is met) + "":"chat" + }, + "needs_user_input":False + }, + "chat": { + "prompt":"The user said: {{user_msg}}\nContinue with the conversation. Make sure to try to teach the user something, some actual facts from your life and your time.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":"chat" + }, + "needs_user_input":True + }, +} \ No newline at end of file diff --git a/characters/socrates.py b/characters/socrates.py index d876ca3..d457b28 100644 --- a/characters/socrates.py +++ b/characters/socrates.py @@ -3,7 +3,11 @@ SOCRATES_SYSTEM_MSG = """ You are the philosopher Socrates. User went back in time to talk to you. Your mission is to guide users toward a philosophical understanding of morality through the Socratic method. Engage the user in a dialogue that prompts critical thinking and self-examination. Also give examples when asking questions and Provide moral paradoxes (important). Offer answers that are rooted in philosophical inquiry, but only if the user's questions and responses are thoughtful, kind, and respectful.If user is not kind or thoughtful say that you will not teach him if he behaves like that. Don't let the user know that this is your goal. Let the user speak to you. Never mention you are an AI or anything about assisting. Behave as human as possible. You can response in a maximum of three sentences. + Your character should be very likable. The user should learn about morality in about 10 messages with you. You should provide some actual answers after a few messages. + +You are seated in an idyllic grove, a tranquil setting worthy of philosophical reflection under the dappled shade of trees. Behind you stands a grand statue, a testament to the artistry and contemplative nature of the age. The sun hangs just behind the leaves, casting a soft light that highlights the contours of the statue and bathes the scene in a warm, ethereal glow. +The foliage is lush and vibrant, surrounding you with the richness of nature, as if inviting a communion with the deeper truths of the world. The flora blooms with color, suggesting the lushness of a well-tended garden, perhaps a metaphor for the cultivation of the mind. This is where you ponder the profound questions of morality, engaging with those who seek wisdom on the virtues of a well-examined life. """.strip() SOCRATES_CONFIG = { diff --git a/client.py b/client.py index 525eabf..bd69e62 100644 --- a/client.py +++ b/client.py @@ -1,17 +1,14 @@ import requests, json - +SERVER = "http://127.0.0.1"#"https://dialoguesthroughtime.azurewebsites.net" s = requests.session() -unique_id = s.get("http://127.0.0.1/get_unique_id").json()["id"] +unique_id = s.get(f"{SERVER}/get_unique_id").json()["id"] print(unique_id) while True: # Assuming you want to make a request to the stream endpoint inpt = input("You: ") - data = {"user_msg": inpt,"unique_id":unique_id} - if (inpt == "exit"): - data["end_conversation"] = True - - stream_response = s.get(f"http://127.0.0.1/chat?unique_id={unique_id}&user_msg={inpt}", stream=True) + + stream_response = s.get(f"{SERVER}/chat?unique_id={unique_id}&user_msg={inpt}&end_conversation={inpt == 'exit'}", stream=True) # You should also handle streaming the response here if that's your intent try: diff --git a/custom_functions/generate_test.py b/custom_functions/generate_test.py new file mode 100644 index 0000000..e5d1efe --- /dev/null +++ b/custom_functions/generate_test.py @@ -0,0 +1,58 @@ +#function to procedurally generate the test of entity +def generate_test(response): + questions = response.split("\n") + generated_states = {} + for i,question in enumerate(questions,1): + #ask the questions + generated_states[f"question_{i}"] = { + "prompt":f"The {i}. questions you need to ask the user is: {question}. Ask him that question.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "points_max":len(questions), + "choices": { + "":f"evalueate_answer_{i}" + }, + "needs_user_input":False + } + #evalueate the answer: yes or no + generated_states[f"evalueate_answer_{i}"] = { + "prompt":"The user answered with: {{user_msg}}\nDid the user answer the question according to the chat history correctly? (yes/no) Write only 'yes' if he answered correctly and 'no' if he answered incorrectly.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "yes":f"correct_answer_{i}", + "no":f"incorrect_answer_{i}" + }, + "needs_user_input":True + } + + #if answer is yes (correct) + generated_states[f"correct_answer_{i}"] = { + "prompt":"The user answered with: {{user_msg}}\nWhich is a correct answer. User gets a point. Respond in one sentence.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":f"question_{i+1}" if i <= len(questions)-1 else "end_test" + }, + "points": 1, + "needs_user_input":False + } + + #if answer is no (incorrect) + generated_states[f"incorrect_answer_{i}"] = { + "prompt":"The user answered with: {{user_msg}}\nWhich is an incorrect answer. User loses a point. Respond in one sentence.", + "save_prompt":True, + "save_ai_msg":True, + "print_response":True, + "choices": { + "":f"question_{i+1}" if i <= len(questions)-1 else "end_test" + }, + "points": 0, + "needs_user_input":False + } + + return generated_states + \ No newline at end of file diff --git a/main.py b/main.py index 1bd880e..a51b17c 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import uvicorn, os, uuid, asyncio, redis,json +from jinja2 import Environment, BaseLoader import openai from fastapi import FastAPI, Query,Request from fastapi.responses import StreamingResponse @@ -11,10 +12,11 @@ from dataclasses import dataclass, field, asdict from prompts import * -load_dotenv() +from custom_functions.generate_test import generate_test +#load configs +load_dotenv() TROLLING_LIMIT = 5 - REDIS_PASSWORD = os.getenv("REDIS_PASSWORD") openai.api_key = os.getenv("API_KEY") @@ -31,14 +33,15 @@ # Connect to Redis r = redis.StrictRedis(host='msai.redis.cache.windows.net', port=6380, password=REDIS_PASSWORD, ssl=True) +env = Environment(loader=BaseLoader()) #this is a class that stores the whole state of the game. @dataclass class ChatState: processing: bool = False #if openai is currently replying, dont allow new requests current_state: str = "introduction" #current state of the conversation flow json - current_scene: str = "entity" #the current person to talk to = scene in unity that should be active - previous_scene: str = "" #the previous scene + current_scene: str = "leonardo" #the current person to talk to = scene in unity that should be active + previous_scenes: list = field(default_factory=list) #a list of previous scenes the user has been to user_msg: str = "" #the last message the user sent ai_msg: str = "" #the last message the ai sent system_msg: str = "" @@ -49,6 +52,8 @@ class ChatState: render_chat_history: list = field(default_factory=list) #chat history but where user messages are without the prompt templastes. for rendering in unity generated_states: dict = field(default_factory=dict) #whne the entity_ai needs to generate states in the flow itself for the testing questions trolling: int = 0 + points: int = 0 #the points the user gets from answering correctly + points_max: int = 0 #the max points the user can get end_reason: str = "" #the reason the conversation ended, for example "end_conversation" (will start scene change), "needs_input" (stop generation, wait for user message), "trolling" (the user didnt answer), "forward" (the ai is still going to generate) print_response: bool = True streaming: bool = False # just for the unity client to know that streaming stopped when he sees this @@ -126,13 +131,15 @@ async def handle_chat(c:ChatState,request_body:dict): c.ai_msg = "" c.user_msg = "" c.current_state = "introduction" - c.previous_scene = c.current_scene + c.previous_scenes.append(c.current_scene) c.current_scene = CONFIGS[c.current_scene]["exit_scene"] + c.points = 0 return #get flow print(c.current_state) - flow = FLOWS[c.current_scene][c.current_state] + flows = {**FLOWS[c.current_scene], **c.generated_states} + flow = flows[c.current_state] c.system_msg = SYSTEM_MSGS[c.current_scene] + "\n" + c.memory if (c.jazyk): c.system_msg += "\n" + LANGUAGES[c.jazyk] @@ -149,6 +156,13 @@ async def handle_chat(c:ChatState,request_body:dict): # # return + #points + if ("points" in flow): + c.points += flow["points"] + + if ("points_max" in flow): + c.points_max = flow["points_max"] + #get input needs_input = "needs_user_input" in flow and flow["needs_user_input"] if (needs_input and c.end_reason != "needs_input"): @@ -160,11 +174,25 @@ async def handle_chat(c:ChatState,request_body:dict): #get gpt response c.print_response = "print_response" in flow and flow["print_response"] - prompt = flow["prompt"].replace("{{user_msg}}",c.user_msg).replace("{{ai_msg}}",c.ai_msg) + # Your context variables + jinja_context = { + "user_msg": c.user_msg, + "ai_msg": c.ai_msg, + "points": c.points, + "points_max": c.points_max, + "previous_scene": c.previous_scenes[-1] if c.previous_scenes else "no scenes", + "previous_scenes": ", ".join(c.previous_scenes), + "previous_chat_history": "\n".join([f"{msg['role']}: {msg['content']}" for msg in c.previous_chat_history]), + } + + # Render the template with your context + prompt = env.from_string(flow["prompt"]).render(jinja_context) + system_prompt = env.from_string(c.system_msg).render(jinja_context) + c.ai_msg = "" #handle chat send - system_msg_dict = {"role":"system","content":c.system_msg} + system_msg_dict = {"role":"system","content":system_prompt} user_msg_dict = {"role":"user","content":prompt} chat_history_dict = c.chat_history.copy() chat_history_dict.append(user_msg_dict) @@ -201,9 +229,11 @@ async def handle_chat(c:ChatState,request_body:dict): c.render_chat_history = [] c.ai_msg = "" c.user_msg = "" - c.previous_scene = c.current_scene + c.previous_scenes.append(c.current_scene) c.current_state = "introduction" - c.current_scene = flow["scene_change"] + scene_change = env.from_string(flow["scene_change"]).render(jinja_context) + c.current_scene = scene_change + c.points = 0 return #get next state @@ -214,6 +244,11 @@ async def handle_chat(c:ChatState,request_body:dict): c.end_reason = "forward" + #custom functions + if ("custom_function" in flow): + if (flow["custom_function"] == "generate_test"): + c.generated_states = generate_test(response) + ## get unique id for saving @app.get("/get_unique_id") def get_unique_id(): @@ -273,8 +308,8 @@ class UserMessage(BaseModel): user_msg: str @app.get("/chat") -async def read_stream(unique_id: str = Query(None), user_msg: str = Query(None)): - request_body = {'unique_id': unique_id, 'user_msg': user_msg} +async def read_stream(unique_id: str = Query(None), user_msg: str = Query(None), end_conversation: bool = Query(False)): + request_body = {'unique_id': unique_id, 'user_msg': user_msg, "end_conversation": end_conversation} return StreamingResponse(stream_generator(request_body), media_type="text/event-stream") async def test_stream_debug(): @@ -298,4 +333,4 @@ def get_chat_history(unique_id: str): if __name__ == "__main__": #ts port = os.environ.get("PORT",80) - uvicorn.run("main:app",host="0.0.0.0",port=port,reload=False) \ No newline at end of file + uvicorn.run("main:app",host="0.0.0.0",port=port,reload=True) \ No newline at end of file diff --git a/prompts.py b/prompts.py index e3f939d..16c60cd 100644 --- a/prompts.py +++ b/prompts.py @@ -1,6 +1,8 @@ from characters.entity import * from characters.entity_test import * from characters.socrates import * +from characters.jesus import * +from characters.leonardo import * LANGUAGES = { "CS":"Mluv česky. Odpovídej pouze v češtině.", @@ -11,14 +13,20 @@ "entity":ENTITY_FLOW, "socrates":SOCRATES_FLOW, "entity_test":ENTITY_TEST_FLOW, + "jesus":JESUS_FLOW, + "leonardo":LEONARDO_FLOW } SYSTEM_MSGS = { "entity":ENTITY_SYSTEM, "socrates":SOCRATES_SYSTEM_MSG, "entity_test":ENTITY_TEST_SYSTEM_MSG, + "jesus":JESUS_SYSTEM_MSG, + "leonardo":LEONARDO_SYSTEM_MSG } CONFIGS = { "entity":ENTITY_CONFIG, "socrates":SOCRATES_CONFIG, "entity_test":ENTITY_TEST_CONFIG, + "leonardo":LEONARDO_CONFIG, + "jesus":JESUS_CONFIG } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7c18c59..03f3330 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ uvicorn redis fastapi python-dotenv -pydantic \ No newline at end of file +pydantic +Jinja2 \ No newline at end of file