File size: 1,952 Bytes
e775944
e12f434
e775944
 
 
 
e12f434
 
e775944
d1cc2d3
e775944
e12f434
5269d9a
 
e775944
 
d1cc2d3
 
e775944
 
d1cc2d3
d9da53f
e9fb71e
 
d1cc2d3
55db170
 
 
 
 
e9fb71e
55db170
e9fb71e
 
d1cc2d3
 
e775944
dd1a1a6
6bbd5b0
dd1a1a6
 
ce75057
 
 
 
 
 
af708df
e775944
 
af708df
e775944
 
 
e12f434
 
e775944
 
 
 
e12f434
d1cc2d3
e775944
d1cc2d3
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
import os
import yaml
from smolagents import GradioUI, CodeAgent, OpenAIServerModel
from tools.web_search import DuckDuckGoSearchTool as WebSearch
from tools.final_answer import FinalAnswerTool as FinalAnswer

# Get current directory path
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))

# Initialize the model
model = OpenAIServerModel(
    model_id='qwen/qwen2.5-coder-32b-instruct',
    api_key=os.getenv("OPENAI_API_KEY", "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"),
    api_base=os.getenv("OPENAI_API_BASE", "https://integrate.api.nvidia.com/v1"),
)

# Initialize tools
web_search = WebSearch()
final_answer = FinalAnswer()

# Load YAML prompt templates
with open(os.path.join(CURRENT_DIR, "prompts.yaml"), "r") as f:
    raw_templates = yaml.safe_load(f)

# ✅ FIXED: Function name corrected from unwrap_text_object to unwrap_text_objects
def unwrap_text_objects(obj):
    if isinstance(obj, dict):
        if obj.get("type") == "text" and "text" in obj:
            return obj["text"]
        return {k: unwrap_text_objects(v) for k, v in obj.items()}
    elif isinstance(obj, list):
        return "\n".join(unwrap_text_objects(i) for i in obj)
    return obj

# Apply the unwrapping to raw templates
prompt_templates = unwrap_text_objects(raw_templates)

print("✅ Loaded YAML keys:", list(raw_templates.keys()))
print("🧾 System prompt preview:\n", raw_templates["system_prompt"][:200])


# ✅ Debug print to verify structure
print("🟢 System Prompt:", prompt_templates.get("system_prompt"))




# Create the agent
agent = CodeAgent(
    model=model,
    tools=[web_search, final_answer],
    managed_agents=[],
    max_steps=20,
    verbosity_level=1,
    name="CodeAgent",
    description="An autonomous coding assistant",
    executor_type='local',
    executor_kwargs={},
    prompt_templates=prompt_templates
)

# Launch the Gradio UI
if __name__ == "__main__":
    GradioUI(agent).launch()