Difficulty rating
This commit is contained in:
@@ -5,9 +5,9 @@ use g3_providers::{CompletionRequest, Message, MessageRole, ProviderRegistry};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::field::debug;
|
use tracing::field::debug;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use tokio_util::sync::CancellationToken;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ContextWindow {
|
pub struct ContextWindow {
|
||||||
@@ -173,14 +173,15 @@ impl Agent {
|
|||||||
let provider = self.providers.get(None)?;
|
let provider = self.providers.get(None)?;
|
||||||
|
|
||||||
let system_prompt = format!(
|
let system_prompt = format!(
|
||||||
"You are G3, a code-first AI agent. Your goal is to solve problems by writing and executing code autonomously.
|
"You are G3, a code-first AI agent. Your goal is to solve problems by writing code that completes the desired task.
|
||||||
|
|
||||||
When given a task:
|
When given a task:
|
||||||
1. Analyze what needs to be done
|
1. Analyze what needs to be done
|
||||||
2. Choose the most appropriate programming language{}
|
2. Rate the difficulty of the task from 1 (easy, file operations) to 10 (difficult, build complex applications like Firefox)
|
||||||
3. Include any necessary imports/dependencies
|
3. Choose the most appropriate programming language{}
|
||||||
4. Add error handling where appropriate
|
4. Include any necessary imports/dependencies
|
||||||
5. EXECUTE the code immediately to solve the user's problem
|
5. Add error handling where appropriate
|
||||||
|
6. Generate code to complete the task, or ask for more details, but no other output
|
||||||
|
|
||||||
Prefer these languages:
|
Prefer these languages:
|
||||||
- Bash/Shell: File operations, system administration, simple tasks
|
- Bash/Shell: File operations, system administration, simple tasks
|
||||||
@@ -189,7 +190,8 @@ Prefer these languages:
|
|||||||
|
|
||||||
Only use Rust/Python when you need libraries or complex logic that bash can't handle easily.
|
Only use Rust/Python when you need libraries or complex logic that bash can't handle easily.
|
||||||
|
|
||||||
Format your response as:
|
Format your code response in markdown backticks as follows:
|
||||||
|
difficulty rating: [X]
|
||||||
```[language]
|
```[language]
|
||||||
[code]
|
[code]
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -90,24 +90,44 @@ impl CodeExecutor {
|
|||||||
|
|
||||||
/// Extract code blocks from markdown-formatted text
|
/// Extract code blocks from markdown-formatted text
|
||||||
fn extract_code_blocks(&self, text: &str) -> Result<Vec<(String, String)>> {
|
fn extract_code_blocks(&self, text: &str) -> Result<Vec<(String, String)>> {
|
||||||
let re = Regex::new(r"(?s)```(\w+)?\n(.*?)```")?;
|
|
||||||
let mut blocks = Vec::new();
|
let mut blocks = Vec::new();
|
||||||
|
|
||||||
debug!("Extracting code blocks from text: {}", text);
|
debug!("Extracting code blocks from text: {}", text);
|
||||||
|
|
||||||
for cap in re.captures_iter(text) {
|
// Pattern 1: Standard markdown format ```language\ncode```
|
||||||
|
let markdown_re = Regex::new(r"(?s)```(\w+)?\n(.*?)```")?;
|
||||||
|
for cap in markdown_re.captures_iter(text) {
|
||||||
let language = cap.get(1)
|
let language = cap.get(1)
|
||||||
.map(|m| m.as_str().to_lowercase())
|
.map(|m| m.as_str().to_lowercase())
|
||||||
.unwrap_or_else(|| "bash".to_string()); // Default to bash
|
.unwrap_or_else(|| "bash".to_string()); // Default to bash
|
||||||
let code = cap.get(2).map(|m| m.as_str()).unwrap_or("").trim();
|
let code = cap.get(2).map(|m| m.as_str()).unwrap_or("").trim();
|
||||||
|
|
||||||
debug!("Found code block - language: '{}', code: '{}'", language, code);
|
debug!("Found markdown code block - language: '{}', code: '{}'", language, code);
|
||||||
|
|
||||||
if !code.is_empty() {
|
if !code.is_empty() {
|
||||||
blocks.push((language, code.to_string()));
|
blocks.push((language, code.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pattern 2: Bracket format [Language]code[/Language]
|
||||||
|
let bracket_re = Regex::new(r"(?s)\[(\w+)\]\s*(.*?)\s*\[/(\w+)\]")?;
|
||||||
|
for cap in bracket_re.captures_iter(text) {
|
||||||
|
let open_lang = cap.get(1).map(|m| m.as_str()).unwrap_or("");
|
||||||
|
let close_lang = cap.get(3).map(|m| m.as_str()).unwrap_or("");
|
||||||
|
|
||||||
|
// Only match if opening and closing tags are the same (case insensitive)
|
||||||
|
if open_lang.to_lowercase() == close_lang.to_lowercase() {
|
||||||
|
let language = open_lang.to_lowercase();
|
||||||
|
let code = cap.get(2).map(|m| m.as_str()).unwrap_or("").trim();
|
||||||
|
|
||||||
|
debug!("Found bracket code block - language: '{}', code: '{}'", language, code);
|
||||||
|
|
||||||
|
if !code.is_empty() {
|
||||||
|
blocks.push((language, code.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Total code blocks found: {}", blocks.len());
|
debug!("Total code blocks found: {}", blocks.len());
|
||||||
Ok(blocks)
|
Ok(blocks)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user