Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ LINEAR_CLIENT_SECRET=""

AI_GATEWAY_URL=""
AI_GATEWAY_TOKEN=""
AI_REFERER=""
AI_TITLE=""

COMPOSIO_API_KEY=""
COMPOSIO_WEBHOOK_SECRET="" # Must be Base64 encoded, can optionally start with whsec_
Expand Down
12 changes: 9 additions & 3 deletions tasks/ai/generateObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ type GenerateObjectInput = {
args: any
schema?: Record<string, any>
zodSchema?: any
settings?: any
settings?: {
referer?: string
title?: string
[key: string]: any
}
}

type GenerateObjectOutput = {
Expand Down Expand Up @@ -59,13 +63,15 @@ export const generateObject = async ({ input, req }: { input: GenerateObjectInpu
}

const url = process.env.AI_GATEWAY_URL ? process.env.AI_GATEWAY_URL + '/v1/chat/completions' : 'https://openrouter.ai/api/v1/chat/completions'
const referer = settings?.referer || process.env.AI_REFERER
const title = settings?.title || process.env.AI_TITLE
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.AI_GATEWAY_TOKEN || process.env.OPEN_ROUTER_API_KEY}`,
'HTTP-Referer': 'https://functions.do', // TODO: Figure out the proper logic to set/override the app
'X-Title': 'Functions.do - Reliable Structured Outputs Without Complexity', // TODO: Figure out a dynamic place for the app title
...(referer ? { 'HTTP-Referer': referer } : {}),
...(title ? { 'X-Title': title } : {}),
},
body: JSON.stringify(request),
})
Expand Down
12 changes: 9 additions & 3 deletions tasks/ai/generateObjectArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ type GenerateObjectArrayInput = {
args: any
schema?: Record<string, any>
zodSchema?: any
settings?: any
settings?: {
referer?: string
title?: string
[key: string]: any
}
}

type GenerateObjectArrayOutput = {
Expand Down Expand Up @@ -54,13 +58,15 @@ export const generateObjectArray = async ({ input, req }: { input: GenerateObjec
}

const url = process.env.AI_GATEWAY_URL ? process.env.AI_GATEWAY_URL + '/v1/chat/completions' : 'https://openrouter.ai/api/v1/chat/completions'
const referer = settings?.referer || process.env.AI_REFERER
const title = settings?.title || process.env.AI_TITLE
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.AI_GATEWAY_TOKEN || process.env.OPEN_ROUTER_API_KEY}`,
'HTTP-Referer': 'https://functions.do', // TODO: Figure out the proper logic to set/override the app
'X-Title': 'Functions.do - Reliable Structured Outputs Without Complexity', // TODO: Figure out a dynamic place for the app title
...(referer ? { 'HTTP-Referer': referer } : {}),
...(title ? { 'X-Title': title } : {}),
},
body: JSON.stringify(request),
})
Expand Down
12 changes: 9 additions & 3 deletions tasks/ai/generateText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
type GenerateTextInput = {
functionName: string
args: any
settings?: any
settings?: {
referer?: string
title?: string
[key: string]: any
}
}

type GenerateTextOutput = {
Expand Down Expand Up @@ -33,13 +37,15 @@ export const generateText = async ({ input, req }: { input: GenerateTextInput; r
}

const url = process.env.AI_GATEWAY_URL ? process.env.AI_GATEWAY_URL + '/v1/chat/completions' : 'https://openrouter.ai/api/v1/chat/completions'
const referer = settings?.referer || process.env.AI_REFERER
const title = settings?.title || process.env.AI_TITLE
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.AI_GATEWAY_TOKEN || process.env.OPEN_ROUTER_API_KEY}`,
'HTTP-Referer': 'https://functions.do', // TODO: Figure out the proper logic to set/override the app
'X-Title': 'Functions.do - Reliable Structured Outputs Without Complexity', // TODO: Figure out a dynamic place for the app title
...(referer ? { 'HTTP-Referer': referer } : {}),
...(title ? { 'X-Title': title } : {}),
},
body: JSON.stringify(request),
})
Expand Down
Loading