import json
import os

import pandas as pd
import requests
from dotenv import load_dotenv
# from IPython.display import clear_output

load_dotenv()

API_HOST = os.getenv("API_HOST")
API_PORT = os.getenv("API_PORT")
REDIS_HOST = os.getenv("REDIS_HOST")
REDIS_PORT = os.getenv("REDIS_PORT")

prompt = """
### Human: I want you to act as a human resource expert and summarize the top five skills required by following user profile:
----
Working Experience
1. Front End Developer, ABC Tech Solutions (May 2020 - July 2022)
    * Developed and maintained user-friendly, responsive web applications using HTML, CSS, and JavaScript for a diverse clientele, resulting in a 30% increase in customer satisfaction.
    * Collaborated closely with UX/UI designers and back-end developers to implement seamless integration of design and functionality, optimizing load times by 20%.
2. Junior Front End Developer, XYZ Web Agency (January 2018 - April 2020)
    * Assisted in the creation of mobile-first web designs, adhering to accessibility standards and ensuring cross-browser compatibility, which led to a 25% increase in mobile traffic.
    * Actively participated in agile development sprints, contributing to efficient project management and improving the overall quality of deliverables.
3. Intern, Front End Development, LMN Digital (June 2017 - December 2017)
    * Gained hands-on experience in modern web development frameworks, including React and Angular, through the creation of interactive web components.
    * Assisted in troubleshooting and resolving front-end issues, refining code quality, and optimizing website performance.
----
### Assistant:
"""

sep = "###"
# worker_addr = f"http://{API_HOST}:{API_PORT}"
worker_addr = "http://cn50.it.auth.gr:21002"
headers = {"User-Agent": "SkillGPT Client"}
pload = {
    "model": "vicuna-13b",
    "prompt": prompt,
    "max_new_tokens": 500,
    "temperature": 0.7,
    "stop": sep,
}
response = requests.post(worker_addr + "/generate_stream", headers=headers,
        json=pload, stream=True)

for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b"\0"):
    if chunk:
        data = json.loads(chunk.decode("utf-8"))
        output = data["text"].split(sep)[-1]
        # clear_output(wait=True)
        print(f"\r{output}", end="")

