Skip to content

Commit

Permalink
azure-docs (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottMktn authored May 14, 2024
1 parent ddc07fc commit c27fb3d
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 3 deletions.
61 changes: 61 additions & 0 deletions docs/integrations/azure/langchain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "Langchain"
description: "Learn how to integrate Azure-OpenAI with Helicone using Langchain."
---

<Steps>
<Step title="Create an account + Generate an API Key">
Log into www.helicone.ai or create an account. Once you have an account, you
can generate an [API key](https://helicone.ai/developer).
</Step>
<Step title="Set HELICONE_API_KEY as an environment variable">
```typescript
HELICONE_API_KEY=<your API key>
```
</Step>
<Step title="Modify the API base and add the `Helicone-Auth` header">
<CodeGroup>

```typescript example.ts
const model = new ChatOpenAI({
azureOpenAIApiKey: "[AZURE_OPENAI_API_KEY]",
azureOpenAIApiDeploymentName: "openai/deployments/gpt-35-turbo",
azureOpenAIApiVersion: "2023-03-15-preview",
azureOpenAIBasePath: "https://oai.hconeai.com",
configuration: {
organization: "[organization]",
baseOptions: {
headers: {
"Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
"Helicone-OpenAI-Api-Base":
"https://[YOUR_AZURE_DOMAIN].openai.azure.com",
},
},
},
});
```

```python example.py
from langchain.chat_models import AzureChatOpenAI

helicone_headers = {
"Helicone-Auth": f"Bearer {helicone_api_key}",
"Helicone-OpenAI-Api-Base": "https://<model_name>.openai.azure.com/"
}

self.model = AzureChatOpenAI(
openai_api_base="https://oai.hconeai.com",
deployment_name="gpt-35-turbo",
openai_api_key=<AZURE_OPENAI_API_KEY>,
openai_api_version="2023-05-15",
openai_api_type="azure",
max_retries=max_retries,
headers=helicone_headers,
**kwargs,
)
```

</CodeGroup>

</Step>
</Steps>
71 changes: 71 additions & 0 deletions docs/integrations/azure/node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: "Node.js"
description: "Learn how to integrate Azure-OpenAI with Helicone using Node.js."
---

## Proxy Integration

<Info>
<b>Recomendation: Model Override</b>

When using Azure, the model displays differently than expected at times. We have implemented logic to parse out the model, but to guarantee your model is consistent, we highly recommend using model override:

<code>Helicone-Model-Override: [MODEL_NAME]</code>
<br />
<br />
<a href="/helicone-headers/header-directory"> Click here to learn more about model override</a>
</Info>

<Steps>
<Step title="Create an account + Generate an API Key">
Log into www.helicone.ai or create an account. Once you have an account, you
can generate an [API key](https://helicone.ai/developer).
</Step>
<Step title="Set HELICONE_API_KEY as an environment variable">
```javascript
HELICONE_API_KEY=<your API key>
```
</Step>
<Step title="Modify the base path and add a Helicone-Auth header">
<Note>Please ensure to include the ‘api-version’ in all of your requests.</Note>
<CodeGroup>

```javascript OpenAI V4+
import OpenAI from "openai";

const openai = new OpenAI({
baseURL: "https://oai.hconeai.com/openai/deployments/[DEPLOYMENT_NAME]",
defaultHeaders: {
"Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
"Helicone-OpenAI-API-Base": "https://[AZURE_DOMAIN].openai.azure.com",
"api-key": "[AZURE_API_KEY]",
},
defaultQuery: { "api-version": "[API_VERSION]" },
});
```

```javascript OpenAI
import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
apiKey: "[AZURE_OPENAI_API_KEY]",
basePath: "https://oai.hconeai.com/openai/deployments/[DEPLOYMENT]",
baseOptions: {
headers: {
"Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
"api-key": "[AZURE_OPENAI_API_KEY]",
"Helicone-OpenAI-Api-Base": "https://[AZURE_DOMAIN].openai.azure.com",
},
params: {
"api-version": "[API_VERSION]",
},
},
});

const openai = new OpenAIApi(configuration);
```

</CodeGroup>

</Step>
</Steps>
123 changes: 123 additions & 0 deletions docs/integrations/azure/python.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: "Python"
description: "Learn how to integrate Azure-OpenAI with Helicone using Python"
---

<Info>
<b>Recomendation: Model Override</b>

When using Azure, the model displays differently than expected at times. We have implemented logic to parse out the model, but to guarantee your model is consistent, we highly recommend using model override:

<code>Helicone-Model-Override: [MODEL_NAME]</code>
<br />
<br />
<a href="/helicone-headers/header-directory"> Click here to learn more about model override</a>
</Info>

## Proxy Integration (recommended)

<Steps>
<Step title="Create an account + Generate an API Key">
Log into www.helicone.ai or create an account. Once you have an account, you
can generate an [API key](https://helicone.ai/developer).
</Step>
<Step title="Set HELICONE_API_KEY as an environment variable">
```Python
export HELICONE_API_KEY=<your API key>
```

</Step>
<Step title="Modify the base path and add a Helicone-Auth header">
<Note>It is mandatory to include the `apik-key` in both locations.</Note>
<CodeGroup>

```Python OpenAI v1+
client = OpenAI(
api_key="[AZURE_OPENAI_API_KEY]",
base_url="https://oai.hconeai.com/openai/deployments/[DEPLOYMENT]",
default_headers={
"Helicone-OpenAI-Api-Base": "https://[AZURE_DOMAIN].openai.azure.com",
"Helicone-Auth": "Bearer [HELICONE_API_KEY]",
"api-key": "[AZURE_OPENAI_API_KEY]",
},
default_query={
"api-version": "[API_VERSION]"
}
)
```

```Python OpenAI v1
import openai

openai.api_base = "https://oai.hconeai.com"
openai.api_key = "[AZURE_OPENAI_API_KEY]"
openai.api_version = "[API_VERSION]"
openai.api_type = "azure"

# Create the completion request
openai.ChatCompletion.create(
model="[DEPLOYMENT]",
messages=[{"role": "User", "content": "Say hi!"}],
headers={
"Helicone-Auth": "Bearer [HELICONE_API_KEY]",
"Helicone-OpenAI-Api-Base": "https://[AZURE_DOMAIN].openai.azure.com",
}
)
```

</CodeGroup>
</Step>
</Steps>

## Package Integration

<Steps>
<Step title="Create an account + Generate an API Key">
Log into www.helicone.ai or create an account. Once you have an account, you
can generate an [API key](https://helicone.ai/developer).
</Step>
<Step title="Set HELICONE_API_KEY as an environment variable">

```Python
export HELICONE_API_KEY=<your API key>
```

</Step>
<Step title="Install the Helicone package">

```Python
pip install helicone
```

</Step>
<Step title="Modify OpenAI import to use Helicone">

```Python
from helicone.openai_proxy import openai # replace `import openai` with this line
```

</Step>
<Step title="Configure your azure domain and you are ready to send your azure requests to Helicone.">

```Python
from helicone.openai_proxy import openai

openai.api_type = "azure"
openai.api_base = "https://[YOUR_AZURE_DOMAIN].openai.azure.com"
openai.api_version = "2023-03-15-preview"
openai.api_key = YOUR_AZURE_API_KEY

response = openai.ChatCompletion.create(
engine = 'gpt-35-turbo',
messages = [{
'role': 'user',
'content': "Hello World!"
}],
max_tokens=15,
)


```

</Step>
</Steps>
2 changes: 1 addition & 1 deletion docs/integrations/openai/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: "Learn how to integrate OpenAI with Helicone using Node.js."
</Step>
<Step title="Set HELICONE_API_KEY as an environment variable">
```javascript
export HELICONE_API_KEY=<your API key>
HELICONE_API_KEY=<your API key>
```
</Step>
<Step title="Modify the base path and add a Helicone-Auth header">
Expand Down
11 changes: 9 additions & 2 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@
"integrations/openai/async"
]
},
"getting-started/integration-method/azure",
{
"group": "Azure OpenAI",
"pages": [
"integrations/azure/node",
"integrations/azure/python",
"integrations/azure/langchain"
]
},
"getting-started/integration-method/anthropic",
"getting-started/integration-method/anyscale",
"getting-started/integration-method/together",
Expand Down Expand Up @@ -82,7 +89,7 @@
"features/advanced-usage/retries",
"features/advanced-usage/custom-rate-limits",
"features/advanced-usage/vault",
"features/advanced-usage/moderations",
"features/advanced-usage/moderations",
"features/advanced-usage/llm-security",
"features/webhooks",
{
Expand Down

0 comments on commit c27fb3d

Please sign in to comment.