Skip to content
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

feat(instrumentation): new spans for llms #13565

Merged
merged 3 commits into from
May 21, 2024

Conversation

RogerHYang
Copy link
Contributor

Before

Screenshot 2024-05-17 at 7 17 43 AM

After

Screenshot 2024-05-17 at 7 39 40 AM

Code

def multiply(a: int, b: int) -> int:
    """Multiple two integers and returns the result integer"""
    return a * b


def add(a: int, b: int) -> int:
    """Add two integers and returns the result integer"""
    return a + b


multiply_tool = FunctionTool.from_defaults(fn=multiply)
add_tool = FunctionTool.from_defaults(fn=add)
agent = OpenAIAgent.from_tools([multiply_tool, add_tool])
Settings.llm = OpenAI(model="gpt-3.5-turbo")

if __name__ == "__main__":
    response = agent.query("What is (121 * 3) + 42?")
    print(response)

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 17, 2024
@@ -253,3 +254,19 @@ async def astream_complete(
print(response.text, end="", flush=True)
```
"""

def __init_subclass__(cls, **kwargs) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh this is nice!

Up to now, I've been resorting to decorating the subclasses individually. If I'm reading this correctly, then this new hook allows for "decorating" these methods with span automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all subclasses will have these methods decorated automatically.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a docstring to this method to explain what's happening in here for future devs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -209,6 +209,19 @@ def dummy_wrapper(_self: Any, *args: Any, **kwargs: Any) -> Any:
if not is_wrapped:
f.__wrapped__ = True # type: ignore

for attr in (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment for what this is doing? I actually don't quite get what is happening here haha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Screenshots below show the difference before/after the pass-through.

before

Screenshot 2024-05-19 at 11 17 50 PM

after

Screenshot 2024-05-19 at 11 16 04 PM

Copy link
Contributor

@nerdai nerdai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, @RogerHYang -- thanks!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 20, 2024
@nerdai nerdai merged commit e6c34b9 into run-llama:main May 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants