File size: 2,808 Bytes
3c7fd6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf2aa3f
a717c8f
 
cf2aa3f
 
 
3c7fd6a
cf2aa3f
3c7fd6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: "CodeDebugCollab_Flow"
description: |2-
  Given a problem description, alternate between a step in which code is generated, and a step in which the produced code is evaluated and useful feedback is provided. 

# ~~~ Input interface specification ~~~
input_interface:
  - "problem_description"
  - "input_description"
  - "output_description"
  - "io_examples_and_explanation"
  - "public_tests_individual_io"

# ~~~ Output interface specification ~~~
output_interface:
  - "code"

# ~~~ Flow specification ~~~
max_rounds: 4

subflows_config:
  CodeGenerator:
    _target_: .CF_Code.instantiate_from_default_config
    name: "CodeGenerator"
    backend:
      _target_: flows.backends.llm_lite.LiteLLMBackend
      api_infos: ???
      model_name:
        openai: "gpt-4"
        azure: "azure/gpt-4"
    human_message_prompt_template:
      _target_: flows.prompt_template.JinjaPrompt
      template: |2-
        {{testing_results_summary}}
      
        {{code_feedback}}


        Consider the problem statement, the last proposed solution, its issue and the provided feedback. Return a corrected version of the code that solves the original problem and resolves the issue, without any explanation, in the following format:
        ```python
        {{code_placeholder}}
        ```
      input_variables:
        - code_feedback
        - testing_results_summary
      partial_variables:
        code_placeholder: "{{python_code}}"
    input_interface_initialized:
      - "code_feedback"
      - "testing_results_summary"
  CodeDebugCritic:
    _target_: .CF_CodeDebugCritic.instantiate_from_default_config

topology:
  # ~~~ Code Generator ~~~
  - goal: "Generate/refine a solution."

    ### Input Interface
    input_interface:
      _target_: flows.interfaces.KeyInterface
      additional_transformations:
        - _target_: flows.data_transformations.KeyMatchInput

    ### Flow Specification
    flow: CodeGenerator

    ### Output Interface
    output_interface:
      _target_: flows.interfaces.KeyInterface
      additional_transformations:
        - _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
          regex: '(?<=```python)([\s\S]*?)(?=```)'
          regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
          input_key: "api_output"
          output_key: "code"
          strip: True
          assert_unique: True
      keys_to_select:
        - "code"

    reset: false

  # ~~~ Code Critic Grounded in Tests ~~~
  - goal: "Provide feedback for the candidate solution that is grounded in test results."

    ### Input Interface
    input_interface:
      _target_: flows.interfaces.KeyInterface
      additional_transformations:
        - _target_: flows.data_transformations.KeyMatchInput

    ### Flow Specification
    flow: CodeDebugCritic

    reset: true