-
Notifications
You must be signed in to change notification settings - Fork 25
WIP - API iteration #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,323 @@ | ||||||
| """ | ||||||
| This file is part of the Graphite project. | ||||||
|
|
||||||
| Copyright (c) 2023-2025 Binome Dev and contributors | ||||||
|
|
||||||
| This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||||||
| If a copy of the MPL was not distributed with this file, You can obtain one at | ||||||
| https://mozilla.org/MPL/2.0/. | ||||||
| """ | ||||||
|
|
||||||
| import asyncio | ||||||
| from collections.abc import AsyncGenerator | ||||||
| import inspect | ||||||
| from typing import Callable, Concatenate, List, ParamSpec, TypeVar | ||||||
| from uuid import uuid4 | ||||||
|
|
||||||
| from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFromTopicEvent | ||||||
| from grafi.common.models.command import Command | ||||||
| from grafi.common.models.invoke_context import InvokeContext | ||||||
| from grafi.common.models.message import Message, Messages, MsgsAGen | ||||||
| from grafi.common.topics.input_topic import InputTopic | ||||||
| from grafi.common.topics.output_topic import OutputTopic | ||||||
| from grafi.common.topics.subscription_builder import SubscriptionBuilder | ||||||
| from grafi.common.topics.topic import Topic | ||||||
| from grafi.nodes.node import Node | ||||||
| from grafi.nodes.node_base import NodeBaseBuilder | ||||||
| from grafi.tools.llms.llm import LLM | ||||||
| from grafi.tools.tool import Tool | ||||||
| from grafi.workflows.impl.event_driven_workflow import EventDrivenWorkflow | ||||||
| from grafi.workflows.workflow import Workflow | ||||||
| from openinference.semconv.trace import OpenInferenceSpanKindValues | ||||||
|
|
||||||
|
|
||||||
| class CallableTool(Tool): | ||||||
| _a_invoke_impl: Callable[[InvokeContext, List[Message]], MsgsAGen] = None | ||||||
|
|
||||||
| def __init__(self, tool_invoke: Callable[[InvokeContext, Messages], MsgsAGen], **kwargs): | ||||||
| super().__init__(name = "CallableTool", oi_span_type=OpenInferenceSpanKindValues.TOOL, type="CallableTool", **kwargs) | ||||||
| self._a_invoke_impl = tool_invoke | ||||||
|
|
||||||
| async def a_invoke( | ||||||
| self, | ||||||
| invoke_context: InvokeContext, | ||||||
| input_data: Messages, | ||||||
| ) -> MsgsAGen: | ||||||
| if self._a_invoke_impl is None: | ||||||
| raise NotImplementedError("Must provide `_a__invoke_impl` Callable.") | ||||||
| yield self._a_invoke_impl(self, invoke_context, input_data) | ||||||
|
||||||
| yield self._a_invoke_impl(self, invoke_context, input_data) | |
| yield self._a_invoke_impl(invoke_context, input_data) |
Copilot
AI
Aug 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the variable name _node_condiiton - it should be _node_condition to match the attribute defined in the constructor.
| return eval(self._node_condiiton, __builtins__ ={}, globals=None, locals=available_topics) | |
| return eval(self._node_condition, __builtins__ ={}, globals=None, locals=available_topics) |
Copilot
AI
Aug 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using eval() with user-provided input is a security risk. Consider using a safer expression evaluation library like ast.literal_eval() or a dedicated expression parser to prevent code injection attacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Inconsistent spacing around the
=operator. Should be consistent with Python PEP 8 style guide (no spaces around=in keyword arguments).