MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / PydanticAIBackend

Class PydanticAIBackend

codewiki/src/be/pydantic_ai_backend.py:39–127  ·  view source on GitHub ↗

API-key based backend using pydantic-ai + openai/litellm clients.

Source from the content-addressed store, hash-verified

37
38
39class PydanticAIBackend(LLMBackend):
40 """API-key based backend using pydantic-ai + openai/litellm clients."""
41
42 def __init__(self, config: Config) -> None:
43 self._config = config
44 self._fallback_models = create_fallback_models(config)
45 self._custom_instructions = config.get_prompt_addition()
46
47 def complete(
48 self,
49 prompt: str,
50 *,
51 model: str | None = None,
52 temperature: float = 0.0,
53 ) -> str:
54 return call_llm(prompt, self._config, model=model, temperature=temperature)
55
56 async def run_module_agent(
57 self,
58 module_name: str,
59 components: Dict[str, Node],
60 core_component_ids: List[str],
61 module_path: List[str],
62 working_dir: str,
63 ) -> Dict[str, Any]:
64 config = self._config
65 module_tree_path = os.path.join(working_dir, MODULE_TREE_FILENAME)
66 module_tree = file_manager.load_json(module_tree_path)
67
68 overview_docs_path = os.path.join(working_dir, OVERVIEW_FILENAME)
69 if os.path.exists(overview_docs_path):
70 logger.info("✓ Overview docs already exists at %s", overview_docs_path)
71 return module_tree
72 docs_path = os.path.join(working_dir, f"{module_name}.md")
73 if os.path.exists(docs_path):
74 logger.info("✓ Module docs already exists at %s", docs_path)
75 return module_tree
76
77 if is_complex_module(components, core_component_ids):
78 agent = Agent(
79 self._fallback_models,
80 name=module_name,
81 deps_type=CodeWikiDeps,
82 tools=[
83 read_code_components_tool,
84 str_replace_editor_tool,
85 generate_sub_module_documentation_tool,
86 ],
87 system_prompt=format_system_prompt(module_name, self._custom_instructions),
88 )
89 else:
90 agent = Agent(
91 self._fallback_models,
92 name=module_name,
93 deps_type=CodeWikiDeps,
94 tools=[read_code_components_tool, str_replace_editor_tool],
95 system_prompt=format_leaf_system_prompt(module_name, self._custom_instructions),
96 )

Callers 1

get_backendFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected