@@ -19,7 +19,7 @@ class OpenAIMonitor:
1919
2020 Parameters
2121 ----------
22- client : openai.api_client.Client, optional
22+ client : openai.api_client.Client
2323 The OpenAI client. It is required if you are using openai>=1.0.0.
2424
2525 Examples
@@ -43,7 +43,7 @@ class OpenAIMonitor:
4343 >>> from openai import OpenAI
4444 >>>
4545 >>> openai_client = OpenAI()
46- >>> monitor = llm_monitors.OpenAIMonitor(publish=True, client=openai_client)
46+ >>> monitor = llm_monitors.OpenAIMonitor(client=openai_client)
4747
4848 3. Use the OpenAI model as you normally would:
4949
@@ -76,7 +76,7 @@ def __init__(
7676 )
7777
7878 def start_monitoring (self ) -> None :
79- """Start monitoring the OpenAI assistant."""
79+ """(Deprecated) Start monitoring the OpenAI assistant."""
8080 warnings .warn (
8181 "The `start_monitoring` method is deprecated and will be removed in a future"
8282 " version. Monitoring is now automatically enabled once the OpenAIMonitor"
@@ -86,7 +86,7 @@ def start_monitoring(self) -> None:
8686 )
8787
8888 def stop_monitoring (self ) -> None :
89- """Stop monitoring the OpenAI assistant."""
89+ """(Deprecated) Stop monitoring the OpenAI assistant."""
9090 warnings .warn (
9191 "The `stop_monitoring` method is deprecated and will be removed in a future"
9292 " version. Monitoring is now automatically enabled once the OpenAIMonitor"
@@ -417,7 +417,7 @@ def monitor_thread_run(self, run: "openai.types.beta.threads.run.Run") -> None:
417417 messages = self .openai_client .beta .threads .messages .list (
418418 thread_id = run .thread_id , order = "asc"
419419 )
420- prompt = self .thread_messages_to_prompt (messages )
420+ prompt = self ._thread_messages_to_prompt (messages )
421421
422422 # Add step to the trace
423423 tracer .add_openai_chat_completion_step_to_trace (
@@ -466,7 +466,7 @@ def _extract_run_metadata(
466466 }
467467
468468 @staticmethod
469- def thread_messages_to_prompt (
469+ def _thread_messages_to_prompt (
470470 messages : List ["openai.types.beta.threads.thread_message.ThreadMessage" ],
471471 ) -> List [Dict [str , str ]]:
472472 """Given list of ThreadMessage, return its contents in the `prompt` format,
@@ -493,7 +493,57 @@ def thread_messages_to_prompt(
493493
494494
495495class AzureOpenAIMonitor (OpenAIMonitor ):
496- """Monitor inferences from Azure OpenAI LLMs and upload traces to Openlayer."""
496+ """Monitor inferences from Azure OpenAI LLMs and upload traces to Openlayer.
497+
498+ Parameters
499+ ----------
500+ client : openai.AzureOpenAI
501+ The AzureOpenAI client.
502+
503+ Examples
504+ --------
505+
506+ Let's say that you have a GPT model you want to monitor. You can turn on monitoring
507+ with Openlayer by simply doing:
508+
509+ 1. Set the environment variables:
510+
511+ .. code-block:: bash
512+
513+ export AZURE_OPENAI_ENDPOINT=<your-azure-openai-endpoint>
514+ export AZURE_OPENAI_API_KEY=<your-azure-openai-api-key>
515+ export AZURE_OPENAI_DEPLOYMENT_NAME=<your-azure-openai-deployment-name>
516+
517+ export OPENLAYER_API_KEY=<your-openlayer-api-key>
518+ export OPENLAYER_PROJECT_NAME=<your-project-name>
519+
520+ 2. Instantiate the monitor:
521+
522+ >>> from opemlayer import llm_monitors
523+ >>> from openai import AzureOpenAI
524+ >>>
525+ >>> azure_client = AzureOpenAI(
526+ >>> api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
527+ >>> api_version="2024-02-01",
528+ >>> azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
529+ >>> )
530+ >>> monitor = llm_monitors.OpenAIMonitor(client=azure_client)
531+
532+ 3. Use the Azure OpenAI model as you normally would:
533+
534+ From this point onwards, you can continue making requests to your model normally:
535+
536+ >>> completion = azure_client.chat.completions.create(
537+ >>> model=os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME"),
538+ >>> messages=[
539+ >>> {"role": "system", "content": "You are a helpful assistant."},
540+ >>> {"role": "user", "content": "How are you doing today?"},
541+ >>> ]
542+ >>> )
543+
544+ The trace of this inference request is automatically uploaded to your Openlayer
545+ project.
546+ """
497547
498548 def __init__ (
499549 self ,
0 commit comments