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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! A crate for generating [Clex](https://github.com/rootCircle/cpast_mono/tree/main/clex_gen) language expressions from input formats and constraints using Google's Generative AI.
//!
//! # Overview
//! This crate provides functionality to convert human-readable input formats and constraints into formal Clex grammar
//! representations using Google's Generative AI model. It helps automate the process of creating test case generators
//! for competitive programming problems.
//!
//! # Examples
//! ```rust
//! use clex_llm::{create_clex_generator, generate_clex_expression};
//!
//! #[tokio::main]
//! async fn main() {
//! let api_key = "your_google_api_key";
//! let generator = create_clex_generator(api_key).unwrap();
//!
//! let input_format = "The first line contains an integer K, followed by K lines each containing a floating-point number P.";
//! let constraints = "1 ≤ K ≤ 50\n0.0 ≤ P ≤ 1000.0";
//!
//! match generate_clex_expression(&generator, input_format, constraints).await {
//! Ok(expression) => println!("Generated Clex Expression: {}", expression),
//! Err(e) => eprintln!("Error generating Clex expression: {}", e),
//! }
//! }
//! ```
//!
//! # Features
//! - Generate Clex expressions from natural language descriptions
//! - Integrate with Google's Generative AI
//! - Support for various input formats and constraints
//!
//! # Prerequisites
//! - A valid Google Generative AI API key (get the API key from <https://makersuite.google.com/app/apikey>)
use LanguageName;
use ClexPromptGenerator;
use CodeSolutionGenerator;
use PromptError;
/// Creates a new instance of the Clex prompt generator.
///
/// # Arguments
/// * `api_key` - A valid Google Generative AI API key
///
/// # Returns
/// * `Result<ClexPromptGenerator, Box<dyn std::error::Error>>` - A Result containing either the generator instance or an error
///
/// Generates a Clex expression from the given input format and constraints.
///
/// # Arguments
/// * `generator` - A reference to the ClexPromptGenerator instance
/// * `input_format` - A string describing the input format in natural language
/// * `constraints` - A string specifying the constraints on input values
///
/// # Returns
/// * `Result<String, PromptError>` - A Result containing either the generated Clex expression or a Google API error
///
pub async
/// Creates a new instance of the Code solution generator.
///
/// # Arguments
/// * `api_key` - A valid Google Generative AI API key
///
/// # Returns
/// * `Result<CodeSolutionGenerator, Box<dyn std::error::Error>>` - A Result containing either the generator instance or an error
///
/// Generates a code solution from the given statement, input format, and constraints.
///
/// # Arguments
/// * `generator` - A reference to the CodeSolutionGenerator instance
/// * `statement` - A string describing the problem statement in natural language
/// * `input_format` - A string describing the input format in natural language
/// * `constraints` - A string specifying the constraints on input values
///
/// # Returns
/// * `Result<String, PromptError>` - A Result containing either the generated code solution or a Google API error
///
pub async