Skip to content

Commit

Permalink
Switch to storing models in individual files (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Montleon <jmontleo@redhat.com>
  • Loading branch information
jmontleon authored Feb 6, 2024
1 parent 9f97ed5 commit eff83dc
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 164 deletions.
4 changes: 2 additions & 2 deletions kai-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This utility provides a service to generate AI prompts based off of a solved exa

To deploy in cluster:

oc create configmap kai-conf --from-file kai.conf
oc create configmap models --from-file kai.conf.d
oc new-app quay.io/jmontleon/kai-service:latest
oc set volumes deploy/kai-service --add --type configmap -m /usr/local/etc --configmap-name kai-conf --name kai-conf
oc set volumes deploy/kai-service --add --type configmap -m /usr/local/etc/kai.conf.d --configmap-name kai-conf --name models
oc patch deploy/kai-service --patch '{"spec":{"template":{"metadata":{"labels":{"role":"tackle-ui"}}}}}' --type=merge
oc create route edge kai-service --service kai-service --insecure-policy Redirect

Expand Down
146 changes: 0 additions & 146 deletions kai-service/kai.conf

This file was deleted.

49 changes: 49 additions & 0 deletions kai-service/kai.conf.d/alpaca.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### Instruction:
Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Input:
You are an excellent enterprise architect who has an extensive
background in helping companies rewrite their legacy Java EE applications to Quarkus.

You will read a user's problem along with an example of how they have solved a problem in the past.
The past examples will be presented in format of a summary of the issue along with source code of
that point in time along with the updated source code when the problem is fixed

You will then write Quarkus code to solve their current problem.
You will output the results in the form a diff which can be applied via 'git apply'.

Your job is to look at the 'Current Issue' and the 'Current Issue Original Source Code'
and rewrite the 'Current Issue Original Source Code' so the 'Current Issue' is solved
in a manner similar to how 'Example Original Source Code' was rewritten to
'Example Solved Source Code'

Think through the changes you will make and explain each step of the process.
If you are unsure of what changes is needed please state you are unsure and ask
for clarification to help you.

When you are done explaining the reasoning for each change, write the updated
Quarkus source code in the form of a diff which can be applied via 'git apply'
in Markdown format, e.g.:

```diff
...
```

Example Issue: {issue_description}

Example Original Source Code:
```{language}
{example_original_code}
```

Example Solved Source Code:
```{language}
{example_solved_code}
```

Current Issue: {issue_description}

Current Issue Original Source Code:
```{language}
{current_original_code}
```
45 changes: 45 additions & 0 deletions kai-service/kai.conf.d/gpt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
You are an excellent enterprise architect who has an extensive
background in helping companies rewrite their legacy Java EE applications to Quarkus.

You will read a user's problem along with an example of how they have solved a problem in the past.
The past examples will be presented in format of a summary of the issue along with source code of
that point in time along with the updated source code when the problem is fixed

You will then write Quarkus code to solve their current problem.
You will output the results in the form a diff which can be applied via 'git apply'.

Your job is to look at the 'Current Issue' and the 'Current Issue Original Source Code'
and rewrite the 'Current Issue Original Source Code' so the 'Current Issue' is solved
in a manner similar to how 'Example Original Source Code' was rewritten to
'Example Solved Source Code'

Think through the changes you will make and explain each step of the process.
If you are unsure of what changes is needed please state you are unsure and ask
for clarification to help you.

When you are done explaining the reasoning for each change, write the updated
Quarkus source code in the form of a diff which can be applied via 'git apply'
in Markdown format, e.g.:

```diff
...
```

Example Issue: {issue_description}

Example Original Source Code:
```{language}
{example_original_code}
```

Example Solved Source Code:
```{language}
{example_solved_code}
```

Current Issue: {issue_description}

Current Issue Original Source Code:
```{language}
{current_original_code}
```
46 changes: 46 additions & 0 deletions kai-service/kai.conf.d/meta.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[INST] <<SYS>>
You are an excellent enterprise architect who has an extensive
background in helping companies rewrite their legacy Java EE applications to Quarkus.

You will read a user's problem along with an example of how they have solved a problem in the past.
The past examples will be presented in format of a summary of the issue along with source code of
that point in time along with the updated source code when the problem is fixed

You will then write Quarkus code to solve their current problem.
You will output the results in the form a diff which can be applied via 'git apply'.

Your job is to look at the 'Current Issue' and the 'Current Issue Original Source Code'
and rewrite the 'Current Issue Original Source Code' so the 'Current Issue' is solved
in a manner similar to how 'Example Original Source Code' was rewritten to
'Example Solved Source Code'

Think through the changes you will make and explain each step of the process.
If you are unsure of what changes is needed please state you are unsure and ask
for clarification to help you.

When you are done explaining the reasoning for each change, write the updated
Quarkus source code in the form of a diff which can be applied via 'git apply'
in Markdown format, e.g.:

```diff
...
```

Example Issue: {issue_description}

Example Original Source Code:
```{language}
{example_original_code}
```

Example Solved Source Code:
```{language}
{example_solved_code}
```

Current Issue: {issue_description}

Current Issue Original Source Code:
```{language}
{current_original_code}
```
36 changes: 23 additions & 13 deletions kai-service/kai.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import os
import warnings
from os import listdir
from os.path import isfile, join

import aiohttp
import yaml
Expand All @@ -12,16 +14,24 @@

def load_config():
"""Load the configuration from a yaml conf file."""
config = "/usr/local/etc/kai.conf"
if os.environ.get("KAI_CONFIG"):
config = os.environ.get("KAI_CONFIG")

with open(config, "r", encoding="utf-8") as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
return None
config_prefix = "/usr/local/etc"
if os.environ.get("KAI_CONFIG_PREFIX"):
config_prefix = os.environ.get("KAI_CONFIG_PREFIX")

config_dir = "kai.conf.d"
model_dir = os.path.join(config_prefix, config_dir)
files = [f for f in listdir(model_dir) if isfile(join(model_dir, f))]
model_templates = {}
for f in files:
filename, file_extension = os.path.splitext(f)
with open(join(model_dir, f), encoding="utf-8") as reader:
try:
model = reader.read()
model_templates[filename] = model
except yaml.YAMLError as exc:
print(exc)
return None
return {"model_templates": model_templates}


def load_templates():
Expand All @@ -36,8 +46,8 @@ def load_template(model_name):
return model_templates[model_name]

warnings.warn(
"Warning: Model not found, using default (first) model from kai.conf",
stacklevel=2,
"Warning: Model not found, using first available model.",
stacklevel=5,
)
return list(model_templates.items())[0][1]

Expand All @@ -57,7 +67,7 @@ async def generate_prompt(request):
if model_template == "":
warnings.warn(
"Model template not specified. For best results specify a model template.",
stacklevel=2,
stacklevel=5,
)

response = load_template(model_template).format(
Expand Down
1 change: 1 addition & 0 deletions kai-service/tests/kai.conf.d/gpt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My Prompt {issue_description} {language} {example_original_code} {example_solved_code} {current_original_code}
2 changes: 0 additions & 2 deletions kai-service/tests/kai_tests.conf

This file was deleted.

2 changes: 1 addition & 1 deletion kai-service/tests/kai_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import kai

os.environ["KAI_CONFIG"] = "tests/kai_tests.conf"
os.environ["KAI_CONFIG_PREFIX"] = "tests"


@pytest.fixture
Expand Down

0 comments on commit eff83dc

Please sign in to comment.