Added some docs about using the OpenAI integration as a universal client
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 385 KiB |
@@ -56,3 +56,60 @@ Once you have set up a OpenAI client, you can use it to create tasks.
|
||||
Perform different AI-powered tasks using OpenAI.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Usage as Universal Client
|
||||
|
||||
You can use our OpenAI integration as a universal client to interact with other OpenAI-compatible APIs, such as [Perplexity.ai](https://docs.perplexity.ai/)
|
||||
|
||||
```ts
|
||||
import { OpenAI } from "@trigger.dev/openai";
|
||||
|
||||
const perplexity = new OpenAI({
|
||||
id: "perplexity",
|
||||
apiKey: process.env["PERPLEXITY_API_KEY"]!,
|
||||
baseURL: "https://api.perplexity.ai",
|
||||
icon: "brand-open-source",
|
||||
});
|
||||
```
|
||||
|
||||
Since [Perplexity.ai](https://docs.perplexity.ai/) is compatible with OpenAI, you can use the same tasks as with OpenAI.
|
||||
|
||||
```ts
|
||||
client.defineJob({
|
||||
id: "perplexity-tasks",
|
||||
name: "Perplexity Tasks",
|
||||
version: "0.0.1",
|
||||
trigger: eventTrigger({
|
||||
name: "perplexity.tasks",
|
||||
}),
|
||||
integrations: {
|
||||
perplexity,
|
||||
},
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.perplexity.chat.completions.create("chat-completion", {
|
||||
model: "mistral-7b-instruct",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "Create a good programming joke about background jobs",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Run this in the background
|
||||
await io.perplexity.chat.completions.backgroundCreate("background-chat-completion", {
|
||||
model: "mistral-7b-instruct",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "If you were a programming language, what would you be and why?",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
And you'll get the same experience in the Run Dashboard when viewing the logs:
|
||||
|
||||

|
||||
|
||||
@@ -90,7 +90,7 @@ client.defineJob({
|
||||
perplexity,
|
||||
},
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.perplexity.createChatCompletion("chat-completion", {
|
||||
await io.perplexity.chat.completions.create("chat-completion", {
|
||||
model: "mistral-7b-instruct",
|
||||
messages: [
|
||||
{
|
||||
@@ -100,7 +100,7 @@ client.defineJob({
|
||||
],
|
||||
});
|
||||
|
||||
await io.perplexity.backgroundCreateChatCompletion("background-chat-completion", {
|
||||
await io.perplexity.chat.completions.backgroundCreate("background-chat-completion", {
|
||||
model: "mistral-7b-instruct",
|
||||
messages: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user