From b9fab4bd4d7e4769c2b33e1ee423d8f7ac9ecfa0 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 20 Jul 2024 13:02:10 -0700 Subject: [PATCH 1/2] docs - using tags OpenAI JS --- docs/my-website/docs/proxy/enterprise.md | 41 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/my-website/docs/proxy/enterprise.md b/docs/my-website/docs/proxy/enterprise.md index 449c2ea17ed..f92688ee37d 100644 --- a/docs/my-website/docs/proxy/enterprise.md +++ b/docs/my-website/docs/proxy/enterprise.md @@ -115,7 +115,7 @@ client = openai.OpenAI( base_url="http://0.0.0.0:4000" ) -# request sent to model set on litellm proxy, `litellm --model` + response = client.chat.completions.create( model="gpt-3.5-turbo", messages = [ @@ -126,7 +126,7 @@ response = client.chat.completions.create( ], extra_body={ "metadata": { - "tags": ["model-anthropic-claude-v2.1", "app-ishaan-prod"] + "tags": ["model-anthropic-claude-v2.1", "app-ishaan-prod"] # 👈 Key Change } } ) @@ -135,6 +135,43 @@ print(response) ``` + + + +Set `extra_body={"metadata": { }}` to `metadata` you want to pass + +```js +const openai = require('openai'); + +async function runOpenAI() { + const client = new openai.OpenAI({ + apiKey: 'sk-1234', + baseURL: 'http://0.0.0.0:4000' + }); + + try { + const response = await client.chat.completions.create({ + model: 'gpt-3.5-turbo', + messages: [ + { + role: 'user', + content: "this is a test request, write a short poem" + }, + ], + tags: ["model-anthropic-claude-v2.1", "app-ishaan-prod"] // 👈 Key Change + }); + console.log(response); + } catch (error) { + console.log("got this exception from server"); + console.error(error); + } +} + +// Call the asynchronous function +runOpenAI(); +``` + + Pass `metadata` as part of the request body From 89922ab71f53423e35022b837c8fa1bea2550412 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 20 Jul 2024 13:15:20 -0700 Subject: [PATCH 2/2] docs js spend tracking with tags --- docs/my-website/docs/proxy/enterprise.md | 45 ++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/docs/my-website/docs/proxy/enterprise.md b/docs/my-website/docs/proxy/enterprise.md index f92688ee37d..5b97dc14e76 100644 --- a/docs/my-website/docs/proxy/enterprise.md +++ b/docs/my-website/docs/proxy/enterprise.md @@ -138,8 +138,6 @@ print(response) -Set `extra_body={"metadata": { }}` to `metadata` you want to pass - ```js const openai = require('openai'); @@ -158,7 +156,9 @@ async function runOpenAI() { content: "this is a test request, write a short poem" }, ], - tags: ["model-anthropic-claude-v2.1", "app-ishaan-prod"] // 👈 Key Change + metadata: { + tags: ["model-anthropic-claude-v2.1", "app-ishaan-prod"] // 👈 Key Change + } }); console.log(response); } catch (error) { @@ -306,6 +306,45 @@ print(response) ``` + + + +```js +const openai = require('openai'); + +async function runOpenAI() { + const client = new openai.OpenAI({ + apiKey: 'sk-1234', + baseURL: 'http://0.0.0.0:4000' + }); + + try { + const response = await client.chat.completions.create({ + model: 'gpt-3.5-turbo', + messages: [ + { + role: 'user', + content: "this is a test request, write a short poem" + }, + ], + metadata: { + spend_logs_metadata: { // 👈 Key Change + hello: "world" + } + } + }); + console.log(response); + } catch (error) { + console.log("got this exception from server"); + console.error(error); + } +} + +// Call the asynchronous function +runOpenAI(); +``` + + Pass `metadata` as part of the request body