Set up GraphBit with minimal overhead configuration - DIRECT API ONLY.
(self)
| 49 | return llm_config["max_tokens"], llm_config["temperature"] |
| 50 | |
| 51 | async def setup(self) -> None: |
| 52 | """Set up GraphBit with minimal overhead configuration - DIRECT API ONLY.""" |
| 53 | # Align runtime worker threads with the current CPU affinity so the runtime |
| 54 | # uses only the pinned CPU cores |
| 55 | configure_runtime(worker_threads=get_cpu_affinity_or_count_fallback()) |
| 56 | |
| 57 | # Initialize GraphBit core only (skip workflow system) |
| 58 | # Use debug=False for benchmarks to minimize overhead |
| 59 | init(debug=False) |
| 60 | |
| 61 | # Get LLM configuration from config |
| 62 | llm_config_obj: LLMConfig | None = self.config.get("llm_config") |
| 63 | if not llm_config_obj: |
| 64 | # Fallback to old format for backward compatibility |
| 65 | llm_config_dict = get_standard_llm_config(self.config) |
| 66 | api_key = os.getenv("OPENAI_API_KEY") or llm_config_dict["api_key"] |
| 67 | if not api_key: |
| 68 | raise ValueError("API key not found in environment or config") |
| 69 | |
| 70 | # Default to OpenAI for backward compatibility |
| 71 | self.llm_config = LlmConfig.openai(api_key, llm_config_dict["model"]) |
| 72 | else: |
| 73 | # Use new LLMConfig structure |
| 74 | api_key = llm_config_obj.api_key or os.getenv("OPENAI_API_KEY") |
| 75 | |
| 76 | if llm_config_obj.provider == LLMProvider.OPENAI: |
| 77 | if not api_key: |
| 78 | raise ValueError("OpenAI API key not found in environment or config") |
| 79 | self.llm_config = LlmConfig.openai(api_key, llm_config_obj.model) |
| 80 | |
| 81 | elif llm_config_obj.provider == LLMProvider.ANTHROPIC: |
| 82 | anthropic_key = llm_config_obj.api_key or os.getenv("ANTHROPIC_API_KEY") |
| 83 | if not anthropic_key: |
| 84 | raise ValueError("Anthropic API key not found in environment or config") |
| 85 | self.llm_config = LlmConfig.anthropic(anthropic_key, llm_config_obj.model) |
| 86 | |
| 87 | elif llm_config_obj.provider == LLMProvider.OLLAMA: |
| 88 | # GraphBit LlmConfig.ollama() only takes model parameter |
| 89 | self.llm_config = LlmConfig.ollama(llm_config_obj.model) |
| 90 | |
| 91 | else: |
| 92 | raise ValueError(f"Unsupported provider for GraphBit: {llm_config_obj.provider}") |
| 93 | |
| 94 | # Create LLM client using the direct API (bypass workflow system entirely) |
| 95 | # Use debug=False for benchmarks to avoid debug output overhead |
| 96 | self.llm_client = LlmClient(self.llm_config, debug=False) |
| 97 | |
| 98 | # Pre-warm the client to avoid initialization overhead in benchmarks |
| 99 | with contextlib.suppress(Exception): |
| 100 | # Warmup is optional |
| 101 | if self.llm_client is not None: |
| 102 | await self.llm_client.warmup() |
| 103 | |
| 104 | async def teardown(self) -> None: |
| 105 | """Cleanup GraphBit resources.""" |
nothing calls this directly
no test coverage detected