Skip to content

Commit

Permalink
Call Azure OpenAI for optimizing the experiences (#2)
Browse files Browse the repository at this point in the history
Directly call the Azure Chat service to get the 3 best experiences.

* Update the documentation
* Add Dependabot configuration file
  • Loading branch information
vbossica authored Dec 23, 2024
1 parent 7342d55 commit 44cc4fc
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore =
# line break after binary operator
W504
per-file-ignores =
sample_cli/src/sample_cli/sample_cli_help.py:W605
cyrano/cyrano_help.py:W605
exclude =
env
doc
Expand Down
11 changes: 0 additions & 11 deletions cyrano/cyrano.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from __future__ import print_function
from typing import Literal

from knack import CLI
from cyrano.common.config import CLI_ENV_VARIABLE_PREFIX, GLOBAL_CONFIG_DIR
from cyrano.common.logmodule import init_logging
from cyrano.groups.group1.greeting_exception import GreetingException
from .cyrano_commands import CyranoCommandsLoader
from .cyrano_help import CyranoHelp

Expand All @@ -25,10 +21,3 @@ def __init__(self) -> None:
help_cls=CyranoHelp)
init_logging('cyrano.log')
self.args = None

def exception_handler(self, ex) -> Literal[1]:
if isinstance(ex, GreetingException):
print(f'Greetings caught: {ex}')
return 1

return super(Cyrano, self).exception_handler(ex)
10 changes: 5 additions & 5 deletions cyrano/cyrano_commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import OrderedDict
from knack.commands import CLICommandsLoader
from cyrano.groups.group1._module import (
load_commands as load_group1_commands,
load_arguments as load_group1_arguments
from cyrano.groups.optimize._module import (
load_commands as load_optimize_commands,
load_arguments as load_optimize_arguments
)


Expand All @@ -12,9 +12,9 @@ class CyranoCommandsLoader(CLICommandsLoader):
"""

def load_command_table(self, args) -> OrderedDict:
load_group1_commands(self)
load_optimize_commands(self)
return super(CyranoCommandsLoader, self).load_command_table(args)

def load_arguments(self, command) -> None:
load_group1_arguments(self)
load_optimize_arguments(self)
super(CyranoCommandsLoader, self).load_arguments(command)
2 changes: 1 addition & 1 deletion cyrano/cyrano_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CyranoHelp(CLIHelp):

def __init__(self, cli_ctx=None) -> None:
# import command group help
import cyrano.groups.group1._help # noqa: F401
import cyrano.groups.optimize._help # noqa: F401
super(CyranoHelp, self).__init__(
cli_ctx=cli_ctx,
welcome_message=WELCOME_MESSAGE)
Expand Down
8 changes: 0 additions & 8 deletions cyrano/groups/group1/_help.py

This file was deleted.

16 changes: 0 additions & 16 deletions cyrano/groups/group1/commands.py

This file was deleted.

3 changes: 0 additions & 3 deletions cyrano/groups/group1/greeting_exception.py

This file was deleted.

File renamed without changes.
8 changes: 8 additions & 0 deletions cyrano/groups/optimize/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from knack.help_files import helps


helps['optimize'] = """
type: group
short-summary: Commands for optimizing resumes.
long-summary:
"""
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def load_commands(cli_command_loader) -> None:
"""

with CommandGroup(cli_command_loader,
'group1', 'cyrano.groups.group1.{}') as group:
group.command('greetings', 'commands#greetings')
'optimize', 'cyrano.groups.optimize.{}') as group:
group.command('experiences', 'commands#optimize_experiences')


def load_arguments(cli_command_loader) -> None:
Expand All @@ -22,5 +22,6 @@ def load_arguments(cli_command_loader) -> None:
"""

with ArgumentsContext(cli_command_loader, 'group1') as arguments:
arguments.argument('name', options_list='--name')
arguments.argument('throw_exception', options_list='--throw-exception')
arguments.argument('experiences_file', options_list='--experiences-file')
arguments.argument('requirements_file', options_list='--requirements-file')
arguments.argument('output_file', options_list='--output-file')
62 changes: 62 additions & 0 deletions cyrano/groups/optimize/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import asyncio
import logging
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, AzureChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
from ...common.config import GLOBAL_CONFIG


def optimize_experiences(experiences_file: str,
requirements_file: str,
output_file: str) -> None:
"""
Optimize the experiences based on the job requirements and
save the results in the output file.
:param experiences_file: the file containing the experiences
:param requirements_file: the file containing the job requirements
:param output_file: the output file
"""

asyncio.run(_optimize_experiences(experiences_file, requirements_file, output_file))


async def _optimize_experiences(experiences_file: str,
requirements_file: str,
output_file: str) -> None:
logging.info('Optimize experiences')

# read experiences and job requirements
with open(experiences_file, 'r', encoding='utf-8') as file:
experiences = file.read()
with open(requirements_file, 'r', encoding='utf-8') as file:
requirements = file.read()

chat_completion_service = AzureChatCompletion(
deployment_name=GLOBAL_CONFIG.get('azure_openai', 'deployment'),
endpoint=GLOBAL_CONFIG.get('azure_openai', 'endpoint'),
api_key=GLOBAL_CONFIG.get('azure_openai', 'api_key'))

request_settings = AzureChatPromptExecutionSettings(
max_tokens=1000,
)

system_message = """
You are an assistant that helps people find the best
3 experiences based on the job requirements. The user
will provide you with a list of experiences and a list
of requirements.
"""

user_input = f"Requirements: {requirements}\n\n" \
f"Experiences: {experiences}"

chat_history = ChatHistory(system_message=system_message)
chat_history.add_user_message(user_input)

response = await chat_completion_service.get_chat_message_content(
chat_history=chat_history,
settings=request_settings,
)
if response:
with open(output_file, 'w', encoding='utf-8') as file:
file.write(response)
11 changes: 10 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@
cyrano
Subgroups:
group1 : Commands for group1.
optimize : Commands for optimizing resumes.
```
1. Update the `~/.cyrano/config` file with the Azure OpenAI values:
```text
[azure_openai]
deployment =
endpoint =
api_key =
```
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors = [
]
dependencies = [
"knack >= 0.12.0",
"semantic-kernel >= 1.17.1",
]
dynamic = ["version"]

Expand Down
7 changes: 7 additions & 0 deletions tests/foo_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import unittest


class FooTests(unittest.TestCase):

def test_foo(self) -> None:
self.assertEqual('bar', 'bar')
22 changes: 0 additions & 22 deletions tests/group1_tests.py

This file was deleted.

0 comments on commit 44cc4fc

Please sign in to comment.