Skip to content

Commit efb060d

Browse files
techpro-aimlapigitbook-bot
authored andcommitted
GITBOOK-777: docs: add 3 manual examples for the rest of embedding models
1 parent 08f324b commit efb060d

5 files changed

Lines changed: 348 additions & 14 deletions

File tree

docs/api-references/embedding-models/Anthropic/voyage-2.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ If you don’t have an API key for the AI/ML API yet, feel free to use our [Quic
3232

3333
{% tabs %}
3434
{% tab title="Python" %}
35-
```python
36-
import openai
37-
38-
# Initialize the API client
35+
<pre class="language-python"><code class="lang-python">import openai
36+
<strong>
37+
</strong># Initialize the API client
3938
client = openai.OpenAI(
39+
# Insert your AIML API Key instead of &#x3C;YOUR_AIMLAPI_KEY>
40+
api_key="&#x3C;YOUR_AIMLAPI_KEY>",
4041
base_url="https://api.aimlapi.com/v1",
41-
api_key="<YOUR_AIMLAPI_KEY>",
4242
)
4343

4444
# Define the text for which to generate an embedding
@@ -52,6 +52,46 @@ response = client.embeddings.create(
5252

5353
# Print the embedding
5454
print(response)
55+
</code></pre>
56+
{% endtab %}
57+
58+
{% tab title="JS" %}
59+
```javascript
60+
import OpenAI from "openai";
61+
import util from "util";
62+
63+
// Initialize the API client
64+
const client = new OpenAI({
65+
// Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>
66+
apiKey: "<YOUR_AIMLAPI_KEY>",
67+
baseURL: "https://api.aimlapi.com/v1",
68+
});
69+
70+
// Define the text for which to generate an embedding
71+
const text = "Laura is a DJ.";
72+
73+
const response = await client.embeddings.create({
74+
input: text,
75+
model: "voyage-2",
76+
});
77+
78+
// Convert embedding to a regular array (not TypedArray)
79+
const pythonLikeResponse = {
80+
...response,
81+
data: response.data.map(item => ({
82+
...item,
83+
embedding: Array.from(item.embedding),
84+
})),
85+
};
86+
87+
// Python-like print
88+
console.log(
89+
util.inspect(pythonLikeResponse, {
90+
depth: null,
91+
maxArrayLength: null,
92+
compact: true,
93+
})
94+
);
5595
```
5696
{% endtab %}
5797
{% endtabs %}

docs/api-references/embedding-models/Anthropic/voyage-code-2.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ If you don’t have an API key for the AI/ML API yet, feel free to use our [Quic
2828
[voyage-code-2.json](../../../.gitbook/assets/voyage-code-2.json)
2929
{% endopenapi %}
3030

31-
## Example in Python
31+
## Code Example
3232

33-
```python
34-
import openai
35-
36-
# Initialize the API client
33+
{% tabs %}
34+
{% tab title="Python" %}
35+
<pre class="language-python"><code class="lang-python">import openai
36+
<strong>
37+
</strong># Initialize the API client
3738
client = openai.OpenAI(
39+
# Insert your AIML API Key instead of &#x3C;YOUR_AIMLAPI_KEY>
40+
api_key="&#x3C;YOUR_AIMLAPI_KEY>",
3841
base_url="https://api.aimlapi.com/v1",
39-
api_key="<YOUR_AIMLAPI_KEY>",
4042
)
4143

4244
# Define the text for which to generate an embedding
@@ -50,7 +52,49 @@ response = client.embeddings.create(
5052

5153
# Print the embedding
5254
print(response)
55+
</code></pre>
56+
{% endtab %}
57+
58+
{% tab title="JS" %}
59+
```javascript
60+
import OpenAI from "openai";
61+
import util from "util";
62+
63+
// Initialize the API client
64+
const client = new OpenAI({
65+
// Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>
66+
apiKey: "<YOUR_AIMLAPI_KEY>",
67+
baseURL: "https://api.aimlapi.com/v1",
68+
});
69+
70+
// Define the text for which to generate an embedding
71+
const text = "Laura is a DJ.";
72+
73+
const response = await client.embeddings.create({
74+
input: text,
75+
model: "voyage-code-2",
76+
});
77+
78+
// Convert embedding to a regular array (not TypedArray)
79+
const pythonLikeResponse = {
80+
...response,
81+
data: response.data.map(item => ({
82+
...item,
83+
embedding: Array.from(item.embedding),
84+
})),
85+
};
86+
87+
// Python-like print
88+
console.log(
89+
util.inspect(pythonLikeResponse, {
90+
depth: null,
91+
maxArrayLength: null,
92+
compact: true,
93+
})
94+
);
5395
```
96+
{% endtab %}
97+
{% endtabs %}
5498

5599
This Python example shows how to set up an API client, send text to the embedding API, and print the response with the embedding vector. See how large a vector response the model generates from just a single short input phrase.
56100

0 commit comments

Comments
 (0)