-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
265 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters