Skip to content

Commit

Permalink
Merge branch 'master' into griffin/objects-db-refactor
Browse files Browse the repository at this point in the history
:wq
  • Loading branch information
gtarpenning committed Dec 13, 2024
2 parents 66e7436 + c964e3f commit 017a687
Show file tree
Hide file tree
Showing 127 changed files with 4,466 additions and 1,847 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
hooks:
- id: mypy
additional_dependencies:
[types-pkg-resources==0.1.3, types-all, wandb>=0.15.5]
[types-pkg-resources==0.1.3, types-all, wandb>=0.15.5, wandb<0.19.0]
# Note: You have to update pyproject.toml[tool.mypy] too!
args: ["--config-file=pyproject.toml"]
exclude: (.*pyi$)|(weave_query)|(tests)|(examples)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/evaluation/scorers.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ In Weave, Scorers are used to evaluate AI outputs and return evaluation metrics.
from weave.scorers import OpenAIModerationScorer
from openai import OpenAI

oai_client = OpenAI(api_key=...) # initialize your LLM client here
oai_client = OpenAI() # initialize your LLM client here

scorer = OpenAIModerationScorer(
client=oai_client,
Expand Down
1 change: 0 additions & 1 deletion docs/docs/guides/integrations/local_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ First and most important, is the `base_url` change during the `openai.OpenAI()`

```python
client = openai.OpenAI(
api_key='fake',
base_url="http://localhost:1234",
)
```
Expand Down
1 change: 0 additions & 1 deletion docs/docs/guides/integrations/notdiamond.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ preference_id = train_router(
response_column="actual",
language="en",
maximize=True,
api_key=api_key,
)
```

Expand Down
33 changes: 33 additions & 0 deletions docs/docs/guides/tracking/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,39 @@ A Weave op is a versioned function that automatically logs all calls.
</TabItem>
</Tabs>

## Control sampling rate

<Tabs groupId="programming-language">
<TabItem value="python" label="Python" default>
You can control how frequently an op's calls are traced by setting the `tracing_sample_rate` parameter in the `@weave.op` decorator. This is useful for high-frequency ops where you only need to trace a subset of calls.

Note that sampling rates are only applied to root calls. If an op has a sample rate, but is called by another op first, then that sampling rate will be ignored.

```python
@weave.op(tracing_sample_rate=0.1) # Only trace ~10% of calls
def high_frequency_op(x: int) -> int:
return x + 1

@weave.op(tracing_sample_rate=1.0) # Always trace (default)
def always_traced_op(x: int) -> int:
return x + 1
```

When an op's call is not sampled:
- The function executes normally
- No trace data is sent to Weave
- Child ops are also not traced for that call

The sampling rate must be between 0.0 and 1.0 inclusive.

</TabItem>
<TabItem value="typescript" label="TypeScript">
```plaintext
This feature is not available in TypeScript yet. Stay tuned!
```
</TabItem>
</Tabs>

### Control call link output

If you want to suppress the printing of call links during logging, you can use the `WEAVE_PRINT_CALL_LINK` environment variable to `false`. This can be useful if you want to reduce output verbosity and reduce clutter in your logs.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _In this example, we're using openai so you will need to add an OpenAI [API key]
import weave
from openai import OpenAI

client = OpenAI(api_key="...")
client = OpenAI()

# Weave will track the inputs, outputs and code of this function
# highlight-next-line
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorial-tracing_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Building on our [basic tracing example](/quickstart), we will now add additional
import json
from openai import OpenAI

client = OpenAI(api_key="...")
client = OpenAI()

# highlight-next-line
@weave.op()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ module = "weave_query.*"
ignore_errors = true

[tool.bumpversion]
current_version = "0.51.24-dev0"
current_version = "0.51.25-dev0"
parse = """(?x)
(?P<major>0|[1-9]\\d*)\\.
(?P<minor>0|[1-9]\\d*)\\.
Expand Down
12 changes: 8 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@ def __getattribute__(self, name):
return ServerRecorder(server)


def create_client(request) -> weave_init.InitializedClient:
def create_client(
request, autopatch_settings: typing.Optional[autopatch.AutopatchSettings] = None
) -> weave_init.InitializedClient:
inited_client = None
weave_server_flag = request.config.getoption("--weave-server")
server: tsi.TraceServerInterface
Expand Down Expand Up @@ -513,7 +515,7 @@ def create_client(request) -> weave_init.InitializedClient:
entity, project, make_server_recorder(server)
)
inited_client = weave_init.InitializedClient(client)
autopatch.autopatch()
autopatch.autopatch(autopatch_settings)

return inited_client

Expand All @@ -527,19 +529,21 @@ def client(request):
yield inited_client.client
finally:
inited_client.reset()
autopatch.reset_autopatch()


@pytest.fixture()
def client_creator(request):
"""This fixture is useful for delaying the creation of the client (ex. when you want to set settings first)"""

@contextlib.contextmanager
def client():
inited_client = create_client(request)
def client(autopatch_settings: typing.Optional[autopatch.AutopatchSettings] = None):
inited_client = create_client(request, autopatch_settings)
try:
yield inited_client.client
finally:
inited_client.reset()
autopatch.reset_autopatch()

yield client

Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/instructor/instructor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_instructor_openai(
assert op_name_from_ref(call.op_name) == "openai.chat.completions.create"
output = call.output
output_arguments = json.loads(
output.choices[0].message.tool_calls[0].function.arguments
output["choices"][0]["message"]["tool_calls"][0]["function"]["arguments"]
)
assert "person_name" in output_arguments
assert "age" in output_arguments
Expand Down Expand Up @@ -112,7 +112,7 @@ async def extract_person(text: str) -> Person:
assert op_name_from_ref(call.op_name) == "openai.chat.completions.create"
output = call.output
output_arguments = json.loads(
output.choices[0].message.tool_calls[0].function.arguments
output["choices"][0]["message"]["tool_calls"][0]["function"]["arguments"]
)
assert "person_name" in output_arguments
assert "age" in output_arguments
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_instructor_iterable(
assert call.started_at < call.ended_at
assert op_name_from_ref(call.op_name) == "openai.chat.completions.create"
output = call.output
output_arguments = json.loads(output.choices[0].message.content)
output_arguments = json.loads(output["choices"][0]["message"]["content"])
assert "tasks" in output_arguments
assert "person_name" in output_arguments["tasks"][0]
assert "age" in output_arguments["tasks"][0]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
interactions:
- request:
body: '{"messages":[{"role":"user","content":"tell me a joke"}],"model":"gpt-4o"}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate, zstd
connection:
- keep-alive
content-length:
- '74'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.57.2
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.57.2
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.13.0rc2
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//jFJNa9wwEL37V0x1yWVd7P3KspcSSKE5thvooSlGK40tJbJGSOOSNOx/
L/Z+2KEp9KLDe/Me743mNQMQVostCGUkqza4/Eav1f1O/v4aVvvbL/Pdt7tVHUp1s/vsnhsx6xW0
f0TFZ9VHRW1wyJb8kVYRJWPvWl4vFpvNYl2UA9GSRtfLmsD5kvJ5MV/mxSYv1iehIaswiS38yAAA
Xoe3j+g1PostFLMz0mJKskGxvQwBiEiuR4RMySaWnsVsJBV5Rj+k/m5eQJO/YkhP6JDJJ6htYxhQ
KgPEBuOnB//g7w2eJ438hcAGoek4fZgaR6y7JPtevnPuhB8uSR01IdI+nfgLXltvk6kiykS+T5WY
ghjYQwbwc9hI96akCJHawBXTE/resCyPdmL8ggm5PJFMLN2Iz1ezd9wqjSytS5ONCiWVQT0qx/XL
TluaENmk899h3vM+9ra++R/7kVAKA6OuQkRt1dvC41jE/kD/NXbZ8RBYpJfE2Fa19Q3GEO3xRupQ
qWslC9xLJUV2yP4AAAD//wMA4O+DUSwDAAA=
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8f01fe3aabd037cf-YYZ
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Wed, 11 Dec 2024 02:20:01 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=xqe_jHZdTV5LijJQYQ3GMY5MjtVrCyxbFO4glgLvgD0-1733883601-1.0.1.1-p.DDUca_cHppJu2hXzzA0CXU1mtalxHUNfBWVgPIQj.UkU603pbNscCvSIi4_Zjlz9Zuc3.hjlvoyZxcDBJTsw;
path=/; expires=Wed, 11-Dec-24 02:50:01 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=WEjxXqkGswaEDhllTROGX_go9tgaWNJcUJ3cCd50xDI-1733883601764-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
openai-organization:
- wandb
openai-processing-ms:
- '607'
openai-version:
- '2020-10-01'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- '10000'
x-ratelimit-limit-tokens:
- '30000000'
x-ratelimit-remaining-requests:
- '9999'
x-ratelimit-remaining-tokens:
- '29999979'
x-ratelimit-reset-requests:
- 6ms
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_8592a74b531c806f65c63c7471101cb6
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
interactions:
- request:
body: '{"messages":[{"role":"user","content":"tell me a joke"}],"model":"gpt-4o"}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate, zstd
connection:
- keep-alive
content-length:
- '74'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.57.2
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.57.2
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.13.0rc2
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//jFLJbtswEL3rK6a85GIV8lYvl6KX9NQFrYEckkKgyZHImOII5KiJEfjf
C8qLHDQFeuHhbXgzw5cMQFgt1iCUkaya1uWf9Hyuv5H29ebu89Pt80Z9//H0RS2nX/e3LEbJQdtH
VHx2vVfUtA7Zkj/SKqBkTKnjxXS6XCwWk3FPNKTRJVvdcj6jfFJMZnmxzIsPJ6MhqzCKNdxnAAAv
/Zsqeo3PYg3F6Iw0GKOsUawvIgARyCVEyBhtZOmPdU+kIs/o+9Y/u4AjMBjwJoIEZ2vDuUEZGDU8
0g6hogB76tYP/sHfmT1o8jcMcYcOmXyEKlkApTJAbDB8TMKNwbPSyN8IbBDqjuO76xoBqy7KtAXf
OXfCD5e5HNVtoG088Re8st5GUwaUkXyaITK1omcPGcCvfn/dq5WINlDTcsm0Q58Cx+NjnBgONpCT
2YlkYukGfDofvZFWamRpXbzav1BSGdSDcziW7LSlKyK7mvnvMm9lH+e2vv6f+IFQCltGXbYBtVWv
Bx5kAdN3/pfssuO+sIj7yNiUlfU1hjbY44+q2nKl54XSq1WxFdkh+wMAAP//AwAWTTnuWgMAAA==
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8f016eadbff439d2-YYZ
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Wed, 11 Dec 2024 00:42:01 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=8FO1yMjc3pMQWRpWrkIe5mcs39GLeqQPmgHQq0YTT8s-1733877721-1.0.1.1-i4G06DBN08aH1F1H73U_TB9OLK3jLsV1jXydB1cQ4Hqx7I.r8xDn.7hFRZe2hy3D_nABTG1nDcdDoXL_wYiqug;
path=/; expires=Wed, 11-Dec-24 01:12:01 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=jxwySgtriPkUP8L2os1nb_gRq_SSUo3yWFUyJmHPmGY-1733877721989-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
openai-organization:
- wandb
openai-processing-ms:
- '652'
openai-version:
- '2020-10-01'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- '10000'
x-ratelimit-limit-tokens:
- '30000000'
x-ratelimit-remaining-requests:
- '9999'
x-ratelimit-remaining-tokens:
- '29999979'
x-ratelimit-reset-requests:
- 6ms
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_1c86d4fda2ad715edfd41bcd2f4bdd89
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 017a687

Please sign in to comment.