Edited: 1. agent.py - добавление базового функционала метода stream_responce. 2. Добавлены/отредактированы chat.js, style.css. 3. flask.py добавлен блок инициализации объектов OllamaProvider, Character, Agent
This commit is contained in:
+61
-4
@@ -1,13 +1,70 @@
|
||||
from flask import *
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from core.agent.agent import Agent
|
||||
from core.llm.ollamaapi import OllamaProvider
|
||||
from core.character.character import Character
|
||||
|
||||
ui = Flask(__name__)
|
||||
|
||||
#блок инициализации объектов
|
||||
|
||||
llm = OllamaProvider("gemma3:4b")
|
||||
|
||||
character = Character.load("test_char_001")
|
||||
|
||||
agent = Agent(character, llm, user_name="Alex")
|
||||
|
||||
agent.load_memory()
|
||||
agent.ensure_first_message()
|
||||
|
||||
#база
|
||||
@ui.route("/")
|
||||
@ui.route("/index")
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@ui.route("/chats")
|
||||
def chats():
|
||||
return "<h1>Страница чатов</h1>"
|
||||
#история чата
|
||||
@ui.route("/init", methods=["GET"])
|
||||
def init():
|
||||
return jsonify({
|
||||
"messages": agent.chat_history,
|
||||
"user_name": agent.user_name,
|
||||
"character": {
|
||||
"name": agent.character.name,
|
||||
"avatar": agent.character.avatar_path
|
||||
}
|
||||
})
|
||||
|
||||
#запрос на генерацию
|
||||
@ui.route("/chat", methods=["POST"])
|
||||
def chat():
|
||||
|
||||
data = request.json
|
||||
|
||||
user_message = data["message"]
|
||||
|
||||
response = agent.respond(user_message)
|
||||
|
||||
agent.save_memory()
|
||||
|
||||
return jsonify({
|
||||
"response": response
|
||||
})
|
||||
|
||||
|
||||
"""#список персонажей
|
||||
@ui.route("/characters", methods=["GET"])
|
||||
def get_characters():
|
||||
return Agent.get_all_char_info()
|
||||
|
||||
#выбор персонажа (не робит)
|
||||
@ui.route("/select_character", methods=["POST"])
|
||||
def select_character():
|
||||
pass
|
||||
'''data = request.json
|
||||
char_id = data["id"]
|
||||
|
||||
global agent
|
||||
agent = Agent(characters[char_id], llm)
|
||||
|
||||
return jsonify({"status": "ok"})'''"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user