Skip to content

Commit f3d0d98

Browse files
committed
ai-server docs WIP, adding usage example code includes to match ai-server-examples repository.
1 parent 3378f98 commit f3d0d98

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```csharp
2+
// Using AI Server DTOs with OpenAI API
3+
var request = new OpenAiChat {
4+
Model = "gpt-4-turbo",
5+
Messages = new List<OpenAiMessage> {
6+
new OpenAiMessage { Role = "system", Content = "You are a helpful AI assistant." },
7+
new OpenAiMessage { Role = "user", Content = "How do LLMs work?" }
8+
},
9+
MaxTokens = 50
10+
};
11+
12+
var json = JsonSerializer.SerializeToString(request);
13+
var response = await client.PostAsync("https://api.openai.com/v1/chat/completions",
14+
new StringContent(json, Encoding.UTF8, "application/json"));
15+
```

MyApp/_pages/ai-server/install/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ docker compose up
5959
Once the AI Server is running, you can access the Admin Portal at [http://localhost:5005/admin](http://localhost:5005/admin) to configure your AI providers and generate API keys.
6060
If you first ran the AI Server with configured API Keys in your `.env` file, you providers will be automatically configured for the related services.
6161

62-
> You can reset the process by deleting your local `App_Data` directory and rerunning `docker compose up`.
62+
> You can reset the process by deleting your local `App_Data` directory and rerunning `docker compose up`.
63+
64+
You will then be able to make requests to the AI Server API endpoints, and access the Admin Portal user interface like the [Chat interface](http://localhost:5005/admin/Chat) to use your AI Provider models.

MyApp/_pages/ai-server/usage/index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: AI Server API Usage
3+
---
4+
5+
# AI Server API Usage
6+
7+
AI Server provides a unified API to process requests for AI services to access LLMs, Image Generation, Transcription, and more. The API is designed to be simple to use and easy to integrate into your applications providing many supported languages and frameworks.
8+
9+
## Making a Chat Request
10+
11+
To make a chat request to AI Server, you can use the `/api/CreateOpenAiChat` endpoint. This endpoint requires a `CreateOpenAiChat` request DTO that contains a property matching the `OpenAI` API.
12+
13+
```csharp
14+
var response = client.Post(new CreateOpenAiChat {
15+
Request = new OpenAiChat {
16+
Model = "gpt-3.5-turbo",
17+
Messages = new List<OpenAiMessage> {
18+
new OpenAiMessage { Role = "system", Content = "You are a helpful AI assistant." },
19+
new OpenAiMessage { Role = "user", Content = "How do I ..." }
20+
}
21+
}
22+
});
23+
```
24+
25+
Additional optional features on the request to enhance the usage of AI Server include:
26+
27+
- **RefId**: A unique identifier for the request specified by the client to more easily track the progress of the request.
28+
- **Provider**: Force the request to use a specific provider, overriding the selection logic.
29+
- **ReplyTo**: A HTTP URL to send the response to on completion of the request.
30+
- **Tag**: A tag to help categorize the request for easier tracking.
31+
32+
## Using the AI Server Request DTOs with other OpenAI compatible APIs
33+
34+
One advantage of using AI Server is that it provides a common set of request DTOs in 11 different languages that are compatible with OpenAI's API. This allows you to switch between OpenAI and AI Server without changing your client code.
35+
This means you can switch to using typed APIs in your preferred language with your existing service providers OpenAI compatible APIs, and optionally switch to AI Server when you're ready to self-host your AI services for better value.
36+
37+
```csharp
38+
// Using OpenAI API
39+
var request = new OpenAiChat {
40+
Model = "gpt-3.5-turbo",
41+
Messages = new List<OpenAiMessage> {
42+
new OpenAiMessage { Role = "system", Content = "You are a helpful AI assistant." },
43+
new OpenAiMessage { Role = "user", Content = "How do I ..." }
44+
}
45+
};
46+
47+
var response = await client.PostAsync("https://api.openai.com/v1/", request);
48+
```

0 commit comments

Comments
 (0)