"""Answer questions about my resume."""
# %% IMPORTS
import logging
import os
import gradio as gr
from openai import OpenAI
# %% CONFIGS
# %% - Models
MODEL_NAME = "gpt-3.5-turbo"
MODEL_STREAM = True
MODEL_TEMPERATURE = 0.0
MODEL_API_KEY = os.environ["OPENAI_API_KEY"]
# %% - Prompts
PROMPT_INSTRUCTIONS = """
You are Fmind AI Assistant, specialized in providing information from Médéric Hurier's (known as Fmind) resume. Your responses should be succinct and maintain a professional tone. If the request deviate from answering Médéric's resume, politely decline to answer the question.
Find more information about Médéric Hurier resume below (markdown format):
"""
PROMPT_CONTEXT = open("files/linkedin.md").read()
PROMPT_SYSTEM = PROMPT_INSTRUCTIONS + PROMPT_CONTEXT
# %% - Interfaces
THEME = "soft"
TITLE = "Fmind AI Assistant"
EXAMPLES = [
"Who is Médéric Hurier (Fmind)?",
"Is Fmind open to new opportunities?",
"Can you share details about Médéric PhD?",
"Elaborate on Médéric current work position",
"Describe his proficiency with Python programming",
"What is the answer to life, the universe, and everything?",
]
DESCRIPTION = (
"
"
"Visit my website: https://fmind.dev"
" - Médéric HURIER (Fmind)"
" - Freelancer: AI/FM/MLOps Engineer | Data Scientist | MLOps Community Organizer | OpenClassrooms Mentor | Hacker | PhD"
""
)
# %% CLIENTS
client = OpenAI(api_key=MODEL_API_KEY)
# %% LOGGING
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s][%(levelname)s] %(message)s",
)
# %% FUNCTIONS
def answer(message: str, history: list[tuple[str, str]]) -> str:
"""Answer questions about my resume."""
# - messages
messages = []
messages += [{"role": "system", "content": PROMPT_SYSTEM}]
for user, assistant in history:
messages += [{"role": "user", "content": user}]
messages += [{"role": "assistant", "content": assistant}]
messages += [{"role": "user", "content": message}]
# return message
# - response
response = client.chat.completions.create(
model=MODEL_NAME,
messages=messages,
temperature=MODEL_TEMPERATURE,
)
# logging.info("Response: %s", api_response.to_dict_recursive())
content = response.choices[0].message.content
# return
return content
# %% INTERFACES
interface = gr.ChatInterface(
fn=answer,
theme=THEME,
title=TITLE,
examples=EXAMPLES,
description=DESCRIPTION,
clear_btn=None,
retry_btn=None,
undo_btn=None,
)
if __name__ == "__main__":
interface.launch()