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

Support Context Propagation #599

Merged
merged 14 commits into from
Apr 13, 2024
Merged

Support Context Propagation #599

merged 14 commits into from
Apr 13, 2024

Conversation

hinthornw
Copy link
Collaborator

@hinthornw hinthornw commented Apr 12, 2024

Client Side:

async def the_parent_function():
    async with AsyncClient(app=fake_app, base_url="http://localhost:8000") as client:
        headers = {}
        if span := get_current_span():
            headers.update(span.to_headers())
        return await client.post("/fake-route", headers=headers)

Server Side:

@fake_app.post("/fake-route")
async def fake_route(request: Request):
    with tracing_context(headers=request.headers):
        fake_function()
    return {"message": "Fake route response"}

If people like, we could add some fun middleware, but probably not necessary

- [x] change default dataset creation (should be unique per file)
- [x] change env vars to use `LANGSMITH_` prefix
Want feedback on:

- [x] ergonomics: is this a general UX we want to support
- [x] imports: should i re-implement string, embedding distance, etc.?
- [x] Do we want default implementations?
- [x] Any other we ought to include at the outset?
- [x] I could also do a general `expect(value).is(...)` or something:
want anything super generic like that?

Example:

```python
@Unit(inputs=x, outputs=y)
def test_output_semantically_close():
    response = oai_client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Say hello!"},
        ],
    )
    # The embedding_distance call logs the embedding distance to LangSmith
    expect.embedding_distance(
        prediction=response.choices[0].message.content,
        reference="Hello!",
        # The following optional assertion logs a
        # pass/fail score to LangSmith
        # and raises an AssertionError if the assertion fails.
    ).to_be_less_than(0.5)
    # Compute damerau_levenshtein distance
    expect.string_distance(
        prediction=response.choices[0].message.content,
        reference="Hello!",
        # And then log a pass/fail score to LangSmith
    ).to_be_less_than(0.5)
```

The idea is it's still an easy onramp for developers to quickly write
some scoring functions and get it running regularly in CI
@hinthornw hinthornw force-pushed the wfh/dt branch 2 times, most recently from 4ec1507 to a6719e9 Compare April 12, 2024 20:04
@hinthornw hinthornw changed the title Baggage Support Context Propagation Apr 12, 2024
@hinthornw hinthornw marked this pull request as ready for review April 12, 2024 22:37
Copy link
Contributor

@agola11 agola11 left a comment

Choose a reason for hiding this comment

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

Looks good but would remove all of the code that switches from Run to Span, that's a bigger change that we're going to need to coordinate with the UI and docs

@hinthornw hinthornw merged commit 2066011 into main Apr 13, 2024
7 checks passed
@hinthornw hinthornw deleted the wfh/dt branch April 13, 2024 07:17
hinthornw added a commit that referenced this pull request Apr 15, 2024
Client Side:

```
async def the_parent_function():
    async with AsyncClient(app=fake_app, base_url="http://localhost:8000") as client:
        headers = {}
        if span := get_current_span():
            headers.update(span.to_headers())
        return await client.post("/fake-route", headers=headers)

```

Server Side:

```
@fake_app.post("/fake-route")
async def fake_route(request: Request):
    with tracing_context(headers=request.headers):
        fake_function()
    return {"message": "Fake route response"}

```

If people like, we could add some fun middleware, but probably not
necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants