Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions examples/basic.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
import lunary

from openai import OpenAI
import os
from dotenv import load_dotenv

client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
)

lunary.monitor(client)


with lunary.users.identify("user1", user_props={"email": "[email protected]"}):
completion = client.chat.completions.create(
model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}]
)
print(completion.choices[0].message.content)
def test_monitor():
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
lunary.monitor(client)
# Add assertions to verify the expected behavior of the monitor function

def test_identify_user():
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
with lunary.users.identify("user1", user_props={"email": "[email protected]"}):
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello world"}]
)
assert completion.choices[0].message.content is not None

@lunary.agent("My great agent", user_id="123", tags=["test", "test2"])
def my_agent(a, b, c, test, test2):
tool1("hello")
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
tool1_output = tool1("hello")
output = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello world"}],
)
print(output)
tool2()
return "Agent output"

tool2_output = tool2()
return f"Agent output: {tool1_output}, {tool2_output}"

@lunary.tool(name="tool 1", user_id="123")
def tool1(a):
return "Output 1"


@lunary.tool()
def tool2():
return "Output 2"

def test_my_agent():
result = my_agent(1, 2, 3, test="sdkj", test2="sdkj")
assert "Agent output: Output 1, Output 2" in result

def test_tool1():
result = tool1("hello")
assert result == "Output 1"

my_agent(1, 2, 3, test="sdkj", test2="sdkj")
def test_tool2():
result = tool2()
assert result == "Output 2"
Loading