Skip to content

Commit

Permalink
Merge pull request #106 from harishkotra/main
Browse files Browse the repository at this point in the history
404 Fixes and API key updates
  • Loading branch information
alabulei1 authored Jan 20, 2025
2 parents d1dfa16 + 3e4a7af commit 2892c18
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
27 changes: 20 additions & 7 deletions docs/agent-integrations/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Since each Gaia node provides an OpenAI-compatible API service, it can be a drop

## The OpenAI Python library

:::note

Make sure to replace `YOUR_API_KEY_GOES_HERE` with your **own API key**. To get your own API key, follow [this](../getting-started/authentication) tutorial.

:::

You can install the [official OpenAI Python library](https://pypi.org/project/openai/) as follows.

```
Expand All @@ -20,19 +26,20 @@ Remember to append the `/v1` after the host name. You can find a list of public
```
import openai
client = openai.OpenAI(base_url="https://YOUR-NODE-ID.us.gaianet.network/v1", api_key="")
client = openai.OpenAI(base_url="https://YOUR-NODE-ID.us.gaianet.network/v1", api_key="YOUR_API_KEY_GOES_HERE")
```

Alternatively, you could set an environment variable at the OS level.
Alternatively, you could set an environment variables at the OS level.

```
export OPENAI_API_BASE=https://YOUR-NODE-ID.us.gaianet.network/v1
export OPENAI_API_KEY=YOUR_API_KEY_GOES_HERE
```

Then, when you make API calls from the `client`, make sure that the `model` is set to the model name
available on your node.

```
```py
response = client.chat.completions.create(
model="Meta-Llama-3-8B-Instruct-Q5_K_M",
messages=[
Expand All @@ -50,24 +57,30 @@ as its backend!

## The OpenAI Node API library

:::note

Make sure to replace `YOUR_API_KEY_GOES_HERE` with your **own API key**. To get your own API key, follow [this](../getting-started/authentication) tutorial.

:::

You can install the [OpenAI Node library](https://www.npmjs.com/package/openai) which provides convenient access to the OpenAI REST API from TypeScript or JavaScript as follows:

```
npm install openai
```

Import it into your project as:
```
```js
// Example usage in Node.js
const OpenAI = require('openai');
```

Create an OpenAI client with a custom base URL. Remember to append the `/v1` after the host name.

```
```js
const client = new OpenAI({
baseURL: 'https://YOUR-NODE-ID.us.gaianet.network/v1',
apiKey: '' // Leave this empty when using Gaia
apiKey: 'YOUR_API_KEY_GOES_HERE'
});
```

Expand All @@ -79,7 +92,7 @@ process.env.OPENAI_API_BASE = 'https://YOUR-NODE-ID.us.gaianet.network/v1';
Then, when you make API calls from the `client`, make sure that the `model` is set to the model name
available on your node.

```
```js
async function callOpenAI() {
try {
const response = await client.chat.completions.create({
Expand Down
10 changes: 10 additions & 0 deletions docs/getting-started/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ can also replace OpenAI API configuration with the Gaia node API in other AI age

The base URL to send all API requests is `https://node_id.gaianet.network/v1`.

:::note

Make sure to replace `YOUR_API_KEY_GOES_HERE` with your **own API key**. To get your own API key, follow [this](./authentication) tutorial.

:::

## Endpoints

### Chat
Expand All @@ -27,6 +33,7 @@ By default, the API responds with a full answer in the HTTP response.
curl -X POST https://node_id.gaianet.network/v1/chat/completions \
-H 'accept:application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY_GOES_HERE' \
-d '{"messages":[{"role":"system", "content": "You are a helpful assistant."}, {"role":"user", "content": "What is the capital of France?"}], "model": "model_name"}'
```

Expand All @@ -46,6 +53,7 @@ Add `"stream":true` in your request to make the API send back partial responses
curl -X POST https://node_id.gaianet.network/v1/chat/completions \
-H 'accept:application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY_GOES_HERE' \
-d '{"messages":[{"role":"system", "content": "You are a helpful assistant."}, {"role":"user", "content": "What is the capital of France?"}], "model": "model_name", "stream":true}'
```

Expand Down Expand Up @@ -102,6 +110,7 @@ The `embeddings` endpoint computes embeddings for user queries or file chunks.
curl -X POST https://node_id.gaianet.network/v1/embeddings \
-H 'accept:application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY_GOES_HERE' \
-d '{"model": "nomic-embed-text-v1.5.f16", "input":["Paris, city and capital of France, ..., for Paris has retained its importance as a centre for education and intellectual pursuits.", "Paris’s site at a crossroads ..., drawing to itself much of the talent and vitality of the provinces."]}'
```

Expand Down Expand Up @@ -161,6 +170,7 @@ The `retrieve` endpoint can retrieve text from the node's vector collection base
curl -X POST https://node_id.gaianet.network/v1/retrieve \
-H 'accept:application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY_GOES_HERE' \
-d '{"messages":[{"role":"system", "content": "You are a helpful assistant."}, {"role":"user", "content": "What is the location of Paris?"}], "model":"nomic-embed-text-v1.5.f16"}'
```

Expand Down
2 changes: 2 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const config = {
{ from: '/node-guide/quick-start', to: '/getting-started/quick-start' },
{ from: '/node-guide/install_uninstall', to: '/getting-started/install' },
{ from: '/node-guide/system-requirements', to: '/getting-started/system-requirements' },
{ from: '/getting-started/quick-start/system-requirements', to: '/getting-started/system-requirements' },
{ from: '/getting-started/system-requirements/advanced-deployment-options/cuda', to: '/getting-started/advanced-deployment-options/cuda' },
{ from: '/node-guide/customize', to: '/getting-started/customize' },
{ from: '/node-guide/register', to: '/getting-started/register' },
{ from: '/node-guide/cli-options', to: '/getting-started/cli-options' },
Expand Down

0 comments on commit 2892c18

Please sign in to comment.