File size: 2,971 Bytes
0dd81f9 579b38c 68114ba 6091941 0dd81f9 68114ba 0dd81f9 68114ba 6091941 68114ba 0dd81f9 68114ba 0dd81f9 68114ba 0dd81f9 68114ba 0dd81f9 68114ba 6091941 0dd81f9 68114ba |
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 |
from smolagents.tools import Tool
import requests
from typing import List, Dict
from bs4 import BeautifulSoup
import tempfile
from tools.odoo_documentation_search import OdooDocumentationSearchTool
import yaml
from tools.final_answer import FinalAnswerTool
from tools.summarizer_service import SummarizerService
class OdooCodeAgent18(Tool):
name = "odoo_code_agent_18"
description = "Generates Odoo code for version 18 based on the user's query and Odoo documentation, using prompt templates."
def __init__(self, system_prompt: str):
self.summarizer_service = SummarizerService()
self.is_initialized = True
self.system_prompt = system_prompt
inputs = {
"query": {"type": "string", "description": "The search query (e.g., 'create a new module')"}
}
output_type = "array"
def forward(self, query: str) -> List[Dict]:
"""
Generates Odoo code for version 18 based on the user's query and Odoo documentation.
"""
base_url = "https://www.odoo.com/documentation/18.0/" # Specific to Odoo 18
try:
# Use the odoo_documentation_search tool to get relevant documentation snippets
odoo_docs = OdooDocumentationSearchTool().forward(query=query, version="18.0")
# Generate Odoo code based on the search results (Placeholder - Replace with actual implementation)
generated_code = self.generate_code(query, odoo_docs)
return [{"Code": generated_code}]
except requests.exceptions.RequestException as e:
return [{"Error": f"Error fetching Odoo documentation: {str(e)}"}]
def perform_search(self, query: str, documentation: str) -> str:
"""
Performs semantic, keyword, and reranking search on the documentation.
(Placeholder - Replace with actual implementation)
"""
# Placeholder implementation - Replace with actual search logic
# This could involve using libraries like Sentence Transformers for semantic search,
# keyword extraction techniques, and a reranking algorithm to prioritize relevant results.
# For now, just return the first 500 characters of the documentation
return documentation[:500]
def generate_code(self, query: str, odoo_docs: List[Dict]) -> str:
"""
Generates Odoo code based on the search results and the user's query.
"""
# Use the summarization pipeline to generate code based on the prompt, query, and documentation
prompt = f"{self.system_prompt}\n\nUser query: {query}\n\nOdoo documentation:\n"
for doc in odoo_docs:
prompt += f"# {doc['Result']}\n"
if not odoo_docs:
prompt += "# No documentation found.\n"
truncated_prompt = prompt[:500]
code = self.summarizer_service.summarize(truncated_prompt)
return FinalAnswerTool(answer=f"```py\n{code}\n```", include_download=True)
|