Skip to content

Commit 1e104dd

Browse files
committed
Merge branch 'main' into function-debug
merging from main
2 parents 2e096a7 + 5540971 commit 1e104dd

31 files changed

+951
-26
lines changed

.github/workflows/ci.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: docs-ci
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- add-docs-portal
7+
permissions:
8+
contents: write
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Configure Git Credentials
15+
run: |
16+
git config user.name github-actions[bot]
17+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.x
21+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
22+
- uses: actions/cache@v4
23+
with:
24+
key: mkdocs-material-${{ env.cache_id }}
25+
path: .cache
26+
restore-keys: |
27+
mkdocs-material-
28+
- run: pip install mkdocs-material
29+
- run: pip install "mkdocs-material[imaging]"
30+
- run: mkdocs gh-deploy -f docs/mkdocs.yml --force

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ valid_and_test_processed/
99

1010
# Python cache files
1111
**/__pycache__/
12+
docs/.cache/

README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ key = "..."
5757
The file: `alpha_codium/settings/configuration.toml` contains the configuration for the project.
5858
In the `config` section you can choose the model you want to use ("gpt-4", "gpt-3.5-turbo-16k", or others).
5959

60-
### Solving a specific problem
60+
### Solving a specific problem from CodeContest
6161
To solve a specific problem with AlphaCodium, from the root folder run:
6262
```
6363
python -m alpha_codium.solve_problem \
@@ -82,7 +82,7 @@ Example problem (test set, problem number 12):
8282
</table>
8383
</p>
8484

85-
### Solving the entire dataset
85+
### Solving an entire CodeContest dataset split
8686
to solve the entire dataset with AlphaCodium, from the root folder run:
8787
```
8888
python -m alpha_codium.solve_dataset \
@@ -107,6 +107,24 @@ python -m alpha_codium.evaluate_dataset\
107107
--database_solution_path /path/to/output/dir/dataset_output.json
108108
```
109109

110+
### Solving a new problem (CodeContest format)
111+
To solve a custom problem with AlphaCodium, first create a json file that includes the CodeContest problem fields, and then from the root folder run:
112+
```
113+
python -m alpha_codium.solve_my_problem \
114+
--my_problem_json_file /path/to/my_problem.json
115+
```
116+
- The `my_problem_json_file` is the path to to the custom problem json file.
117+
118+
See the `my_problem_example.json` to see an example of a custom problem. The json file should include the following fields:
119+
- `name` is the name of the problem.
120+
- `description` is a description of the problem.
121+
- (optional) `public_tests` with the following fields:
122+
- `input` is a list of strings that represent the input.
123+
- `output` is a list of strings that represent the output.
124+
- (optional) `private_tests`, that follows the same structure as `public_tests`
125+
- (optional) `generated_tests`, that follows the same structure as `public_tests`
126+
127+
110128
## Technical Q&A
111129
Aggregating some technical questions we received about this project:
112130
___

alpha_codium/code_contests/eval/pass_at_k_evaluator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from evaluate import load as load_metric
44

55
from alpha_codium.code_contests.data.provider import CodeContestDataProvider
6-
from alpha_codium.config_loader import get_settings
6+
from alpha_codium.settings.config_loader import get_settings
77

88

99
def calculate_metrics(ds, k_values=[1, 10, 100]): # noqa: B006

alpha_codium/gen/coding_competitor.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ def render(self, problem_json, prompt: str):
4343
if hasattr(self.prompt[prompt], 'frequency_penalty'):
4444
frequency_penalty = self.prompt[prompt].frequency_penalty
4545
else:
46-
frequency_penalty = 0
46+
frequency_penalty = None
4747
return sys_prompt, usr_prompt, temperature, frequency_penalty
4848

4949
async def _run(self, model, problem, prompt:str = "code_contests_prompt_reflect"):
5050
system_prompt, user_prompt, temperature, frequency_penalty = self.render(problem, prompt)
5151

52+
if frequency_penalty == None:
53+
frequency_penalty = get_settings().get("config.frequency_penalty")
54+
5255
response, finish_reason = await self.ai_handler.chat_completion(
5356
model=model, system=system_prompt, user=user_prompt,
5457
temperature=temperature, frequency_penalty=frequency_penalty,
@@ -107,7 +110,6 @@ def solve_problem(dataset_name,
107110
problem_number=0):
108111

109112
# load dataset
110-
base_path = os.getcwd()
111113
logger = get_logger(__name__)
112114
data_provider = CodeContestDataProvider(dataset_location=dataset_name)
113115
if problem_number and problem_name:
@@ -156,6 +158,14 @@ def solve_problem(dataset_name,
156158
pass
157159

158160

161+
return solve_my_problem(problem)
162+
163+
164+
def solve_my_problem(problem):
165+
166+
base_path = os.getcwd()
167+
logger = get_logger(__name__)
168+
159169
solver = CodeContestsCompetitor()
160170
os.chdir(base_path)
161171
solution = solver.solve_problem_in_dataset(problem)

alpha_codium/llm/token_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from jinja2 import Environment, StrictUndefined
22
from tiktoken import encoding_for_model, get_encoding
33

4-
from alpha_codium.config_loader import get_settings
4+
from alpha_codium.settings.config_loader import get_settings
55

66

77
def get_token_encoder():

alpha_codium/settings/choose_best_solution_direct.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_choose_best_solution_direct]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system = """\
54
To solve the problem, utilize an exhaustive high-computational approach like simulation, recursion, brute-force or other direct approach. Ignore the problem constraints regarding large input size.
65
"""

alpha_codium/settings/code_contests_prompt_analyze_and_fix.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_analyze_and_fix]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
- You must divide the fixed code into small sub-functions, with meaningful names and functionality. Each function should be no longer than 10 lines of code.
65
- The fixed code should be robust and general, and work for other input examples as well.

alpha_codium/settings/code_contests_prompt_analyze_and_fix_direct.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_analyze_and_fix_direct]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
- You must divide the new code into small sub-functions, with meaningful names and functionality. Variable names should also be meaningful.
65
- The new code still needs to utilize an exhaustive approach like simulation, recursion, brute-force or direct solution. Ignore the problem constraints regarding large input size.

alpha_codium/settings/code_contests_prompt_analyze_failure.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_analyze_failure]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system = """\
54
"""
65
user="""\

alpha_codium/settings/code_contests_prompts_baseline.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_baseline]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system= """\
54
"""
65
user="""

alpha_codium/settings/code_contests_prompts_choose_best_solution.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_choose_best_solution]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
- As a seasoned programmer, choose the best solution.
65
- Output nothing other that the YAML.

alpha_codium/settings/code_contests_prompts_fix_solution.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_fix_solution]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system="""\
54
- You must divide the fixed code into small sub-functions, with meaningful names and functionality. Each function should be no longer than 10 lines of code.
65
- The fixed code should be robust and general, and work for other input examples as well.

alpha_codium/settings/code_contests_prompts_generate_ai_tests.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_generate_ai_tests]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
"""
65

alpha_codium/settings/code_contests_prompts_generate_possible_solutions.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_generate_possible_solutions]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system= """\
54
Pay attention to small details and nuances in the problem description.
65
"""

alpha_codium/settings/code_contests_prompts_reflect.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompt_reflect]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system= """\
54
The self-reflection must cover every aspect of the problem. Pay attention to small details and nuances in the problem description.
65
"""

alpha_codium/settings/code_contests_prompts_solve.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_solve]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system= """\
54
- You must divide the generated code into small sub-functions, with meaningful names and functionality. Each function should be no longer than 10 lines of code.
65
- Double-check the solution code. The generated solution must generalize to any valid input, and not just the provided examples.

alpha_codium/settings/code_contests_prompts_solve_direct.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_solve_direct]
22
temperature = 0.3
3-
frequency_penalty = 0.1
43
system= """\
54
- You must divide the generated code into small sub-functions, with meaningful names and functionality. Each function should be no longer than 10 lines of code.
65
- The code should ignore the problem constraints for large inputs.

alpha_codium/settings/code_contests_prompts_validate_ai_tests.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_validate_ai_tests]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
Your goal is to consider each AI-generated test, and make sure its output and its explanation are correct. Be critical - they could be wrong.
65
guidelines:

alpha_codium/settings/code_contests_prompts_validate_reflection.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[code_contests_prompts_validate_reflection]
22
temperature = 0.2
3-
frequency_penalty = 0.1
43
system = """\
54
"""
65

alpha_codium/settings/configuration.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
model="gpt-4-0125-preview"
33
#model="gpt-4-0613"
44
#model = "gpt-3.5-turbo-16k"
5+
frequency_penalty=0.1
56
ai_timeout=90 # seconds
67
fallback_models =[]
78
verbosity_level=2 # 0,1,2
89
private_dataset_cache_dir="~/ai/alphacodium"
910
max_requests_per_minute=60
1011

11-
1212
[dataset]
1313
evaluate_prev_solutions=false
1414
num_iterations=1 # X iterations to try to solve the problem

alpha_codium/solve_my_problem.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import argparse
2+
import json
3+
4+
from alpha_codium.gen.coding_competitor import solve_problem, solve_my_problem
5+
from alpha_codium.log import setup_logger
6+
from alpha_codium.settings.config_loader import get_settings
7+
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("--my_problem_json_file", type=str, default="my_problem_example.json")
10+
11+
if __name__ == "__main__":
12+
args = parser.parse_args()
13+
setup_logger()
14+
15+
with open(args.my_problem_json_file, "r") as my_problem:
16+
solve_my_problem(json.load(my_problem))

docs/docs/CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alpha-codium-docs.codium.ai

docs/docs/assets/favicon.ico

15 KB
Binary file not shown.

docs/docs/assets/logo.png

263 KB
Loading

docs/docs/css/custom.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
:root {
2+
--md-primary-fg-color: #765bfa;
3+
--md-accent-fg-color: #AEA1F1;
4+
}
5+
.md-nav__title, .md-nav__link {
6+
font-size: 16px; /* Adjust the font size as needed */
7+
}
8+
9+
.md-tabs__link {
10+
font-size: 16px; /* Adjust the font size as needed */
11+
}
12+
13+
.md-header__title {
14+
font-size: 20px; /* Adjust the font size as needed */
15+
}

0 commit comments

Comments
 (0)