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

Add OpenAI client support to logger.py #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

steventkrawczyk
Copy link
Contributor

@steventkrawczyk steventkrawczyk commented Dec 29, 2023

Overview of Change

OpenAI has a new API format that uses a client object, so we need to change the way we monkey patch logging

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)

The intention is for our code to support the following

from openai import OpenAI
import prompttools.logger
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)

Why is this the best approach?

This is the most flexible way to patching things in, rather than having users import a wrapped object from our library or wrapping clients themselves. Ideally, users are building more complex apps with some kind of dependency injection to manage the OpenAI client and they only need to patch in one place.

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

1 participant