Skip to content

Commit

Permalink
[Docs] OpenAI Integration docs for the website (#549)
Browse files Browse the repository at this point in the history
* minor fix in anthropic doc

* add openai docs in integrations section

* divert step for installation with tooltip

* additional step for installing cohere sdk

* change `params` to `logs` in `ActionEvent`

* fix incorrect version mention

* add section for `ollama` installation`

* arrange integrations alphabetically and add `openai.mdx`

* remove Python

* modify link to openai.com

* cleaner sections

* add openai branding images

* add sync example notebook

* minor fix

* minor correction in description

* add async example notebook

* something

* updated examples `README.md`

* add a `README.md` (kinda) to the `openai_examples` directory

* minor correction

* replace link

---------

Co-authored-by: reibs <[email protected]>
  • Loading branch information
the-praxs and areibman authored Dec 6, 2024
1 parent 7c9b746 commit 7072e20
Show file tree
Hide file tree
Showing 14 changed files with 714 additions and 12 deletions.
Binary file added docs/images/external/openai/openai-lockup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/external/openai/openai-logomark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@
{
"group": "Integrations",
"pages": [
"v1/integrations/crewai",
"v1/integrations/anthropic",
"v1/integrations/autogen",
"v1/integrations/langchain",
"v1/integrations/cohere",
"v1/integrations/anthropic",
"v1/integrations/ollama",
"v1/integrations/crewai",
"v1/integrations/langchain",
"v1/integrations/litellm",
"v1/integrations/multion",
"v1/integrations/ollama",
"v1/integrations/openai",
"v1/integrations/rest"
]
},
Expand Down
17 changes: 15 additions & 2 deletions docs/v1/integrations/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ This is a living integration. Should you need any added functionality, message u
<Step title="Install the AgentOps SDK">
<CodeGroup>
```bash pip
pip install agentops anthropic
pip install agentops
```
```bash poetry
poetry add agentops anthropic
poetry add agentops
```
</CodeGroup>
</Step>
<Step title="Install the Anthropic SDK">
<Note>
`anthropic>=0.32.0` is currently supported with additional support for the Computer Use tool.
</Note>
<CodeGroup>
```bash pip
pip install anthropic
```
```bash poetry
poetry add anthropic
```
</CodeGroup>
</Step>
Expand Down
13 changes: 13 additions & 0 deletions docs/v1/integrations/cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ This is a living integration. Should you need any added functionality, message u
poetry add agentops
```
</CodeGroup>
</Step>
<Step title="Install the Cohere SDK">
<Note>
`cohere>=5.4.0` is currently supported.
</Note>
<CodeGroup>
```bash pip
pip install cohere
```
```bash poetry
poetry add cohere
```
</CodeGroup>
</Step>
<Step title="Add 3 lines of code">
<CodeTooltip/>
Expand Down
10 changes: 10 additions & 0 deletions docs/v1/integrations/ollama.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ This is a living integration. Should you need any added functionality, message u
```
</CodeGroup>
</Step>
<Step title="Install the Ollama SDK">
<CodeGroup>
```bash pip
pip install ollama
```
```bash poetry
poetry add ollama
```
</CodeGroup>
</Step>
<Step title="Add 3 lines of code">
<CodeTooltip/>
<CodeGroup>
Expand Down
195 changes: 195 additions & 0 deletions docs/v1/integrations/openai.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
title: OpenAI
description: "AgentOps provides first class support for OpenAI's GPT family of models"
---

import CodeTooltip from '/snippets/add-code-tooltip.mdx'
import EnvTooltip from '/snippets/add-env-tooltip.mdx'

<Note>
This is a living integration. Should you need any added functionality, message us on [Discord](https://discord.gg/UgJyyxx7uc)!
</Note>

<Card title="OpenAI" icon="robot" href="https://www.openai.com">
First class support for GPT family of models
</Card>

<Steps>
<Step title="Install the AgentOps SDK">
<CodeGroup>
```bash pip
pip install agentops
```
```bash poetry
poetry add agentops
```
</CodeGroup>
</Step>
<Step title="Install the OpenAI SDK">
<Note>
`openai<1.0.0` has limited support while `openai>=1.0.0` is continuously supported.
</Note>
<CodeGroup>
```bash pip
pip install openai
```
```bash poetry
poetry add openai
```
</CodeGroup>

To install `openai<1.0.0`, use the following:
<CodeGroup>
```bash pip
pip install "openai<1.0.0"
```
```bash poetry
poetry add "openai<1.0.0"
```
</CodeGroup>
</Step>
<Step title="Add 3 lines of code">
<CodeTooltip/>
<span className="api-key-container">
<CodeGroup>
```python python
import agentops
from openai import OpenAI

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()
...
# End of program (e.g. main.py)
agentops.end_session("Success") # Success|Fail|Indeterminate
```
</CodeGroup>
</span>
<EnvTooltip />
<span className="api-key-container">
<CodeGroup>
```python .env
AGENTOPS_API_KEY=<YOUR API KEY>
OPENAI_API_KEY=<YOUR OPENAI API KEY>
```
</CodeGroup>
Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration)
</span>
</Step>
<Step title="Run your Agent">
Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Agent! 🕵️
<Tip>
After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard
</Tip>
<div/>
<Frame type="glass" caption="Clickable link to session">
<img height="200" src="https://raw.githubusercontent.com/AgentOps-AI/agentops/refs/heads/main/docs/images/external/app_screenshots/session-replay.png?raw=true" />
</Frame>
</Step>
</Steps>

## Full Examples

<CodeGroup>
```python sync
from openai import OpenAI
import agentops

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()

response = client.chat.completions.create((
model="gpt-4o-mini",
messages=[{
"role": "user",
"content": "Write a haiku about AI and humans working together"
}]
)

print(response.choices[0].message.content)
agentops.end_session('Success')
```

```python async
from openai import AsyncOpenAI
import agentops
import asyncio

async def main():
agentops.init(<INSERT YOUR API KEY HERE>)
client = AsyncOpenAI()

response = await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{
"role": "user",
"content": "Write a haiku about AI and humans working together"
}]
)

print(response.choices[0].message.content)
agentops.end_session('Success')

asyncio.run(main())
```

</CodeGroup>

### Streaming examples

<CodeGroup>
```python sync
from openai import OpenAI
import agentops

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()

stream = client.chat.completions.create(
model="gpt-4o-mini",
stream=True,
messages=[{
"role": "user",
"content": "Write a haiku about AI and humans working together"
}],
)

for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")

agentops.end_session('Success')
```

```python async
from openai import AsyncOpenAI
import agentops
import asyncio

async def main():
agentops.init(<INSERT YOUR API KEY HERE>)
client = AsyncOpenAI()

stream = await client.chat.completions.create(
model="gpt-4o-mini",
stream=True,
messages=[{
"role": "user",
"content": "Write a haiku about AI and humans working together"
}],
)

async for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")

agentops.end_session('Success')

asyncio.run(main())
```

</CodeGroup>

<script type="module" src="/scripts/github_stars.js"></script>
<script type="module" src="/scripts/link_to_api_button.js"></script>
<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>
<script type="module" src="/scripts/button_heartbeat_animation.js"></script>
<script type="css" src="/styles/styles.css"></script>
<script type="module" src="/scripts/adjust_api_dynamically.js"></script>
17 changes: 12 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ At a high level, AgentOps gives you the ability to monitor LLM calls, costs, lat
- [Multi-Agent](./multi_agent_example.ipynb)

## Integrations
- [Using Langchain](./langchain_examples.ipynb)
- [Crew.ai](https://github.com/joaomdmoura/crewAI-examples/tree/main/markdown_validator)
- Crew is a framework for developing agents, a number of their example projects use AgentOps
- [Cohere](./cohere_example.ipynb)
- [Anthropic](./anthropic_example.ipynb)
- [AI21](./ai21_examples/ai21_examples.ipynb)
- [Anthropic](./anthropic_examples/)-
- [Autogen](./autogen_examples/)
- [Cohere](./cohere_examples/cohere_example.ipynb)
- [Crew.ai](./crew_examples/)
- [Groq](./multi_agent_groq_example.ipynb)
- [Langchain](./langchain_examples/langchain_examples.ipynb)
- [LiteLLM](./litlelm_examples/litlelm_example.ipynb)
- [Mistral](./mistral_examples/mistral_example.ipynb)
- [MultiOn](./multion_examples/)
- [Ollama](./ollama_examples/ollama_examples.ipynb)
- [OpenAI](./openai_examples/)
2 changes: 1 addition & 1 deletion examples/openai-gpt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
" agentops.record(\n",
" ActionEvent(\n",
" action_type=\"Agent says hello\",\n",
" params=str(message),\n",
" logs=str(message),\n",
" returns=str(response.choices[0].message.content),\n",
" )\n",
" )"
Expand Down
21 changes: 21 additions & 0 deletions examples/openai_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# OpenAI integration with AgentOps

AgentOps supports observability for OpenAI's API for both version 0.0.x and version 1.x.

To learn more about OpenAI visit [here!](https://www.openai.com) and their documentation [here](https://platform.openai.com/docs/introduction).

## Getting Started

### Prerequisites
* An AgentOps account with an API key
* An OpenAI API key

Refer to the [AgentOps documentation](https://docs.agentops.ai/getting-started/api-key) for more information on how to get an API key.

### Documentation
The documentation for the OpenAI integration can be found [here](https://docs.agentops.ai/integrations/openai).

The example notebooks are present in the [openai_examples](./openai_examples/) directory.

### License
This project is released under the MIT License.
Loading

0 comments on commit 7072e20

Please sign in to comment.