Skip to content

Commit d173b3b

Browse files
committed
docs: openai copmatiblity guide
1 parent 0cf6ce6 commit d173b3b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

vector-inference/openai.mdx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
---
2-
title: "OpenAI compatible interface"
2+
title: "Using OpenAI SDK"
33
---
4+
5+
Trieve Vector Inference is compatible with the OpenAI api. This means you're able to just replace the endpoint, without changing any pre-existing code.
6+
Here's an example with the `openai` python sdk
7+
8+
First install the dependencies
9+
10+
```sh
11+
pip install openai
12+
pip install requests
13+
pip install python-dotenv
14+
```
15+
16+
```python openai_compatibility.py
17+
import openai
18+
import time
19+
import requests
20+
import os
21+
from dotenv import load_dotenv
22+
23+
load_dotenv()
24+
25+
endpoint = "http://<your-ingress-endpoint-here>"
26+
27+
openai.base_url = endpoint
28+
29+
client = openai.OpenAI(
30+
# This is the default and can be omitted
31+
api_key=os.environ.get("OPENAI_API_KEY"),
32+
base_url=endpoint
33+
)
34+
35+
embedding = client.embeddings.create(
36+
input="This is some example input",
37+
model="BAAI/bge-m3"
38+
)
39+
```

0 commit comments

Comments
 (0)