wandb / weave

Weave is a toolkit for developing AI-powered applications, built by Weights & Biases.
https://wandb.me/weave
Apache License 2.0
604 stars 43 forks source link

feat: Cohere chat models integration #1846

Closed tcapelle closed 4 days ago

tcapelle commented 3 weeks ago

Cohere API integration with Weave

circle-job-mirror[bot] commented 3 weeks ago

Preview this PR with FeatureBee: https://beta.wandb.ai/?betaVersion=f1a7d7bc2d4f8f59423385562763157622dd9059

tcapelle commented 2 weeks ago

@tssweeney I need help with 2 things:

tcapelle commented 1 week ago

The only thing that may need changing is how the patching is applied.

As you know @tssweeney the cohere Client modifies the chat function on the init, so we need to patch before creating a client. Two options for this:

import cohere
import os
import weave
from weave.integrations.cohere import cohere_patcher

# we need to patch before we create the client
cohere_patcher.attempt_patch()

co = cohere.Client(api_key=os.environ["COHERE_API_KEY"])

weave.init("cohere_project")

one option could be:

# cohere.__init__.py
from weave.integrations.cohere.cohere_sdk import cohere_patcher as _cohere_patcher

def cohere_patcher():
    _cohere_patcher.attempt_patch()

but feel free to change this import logic...