kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/643/head^2
rodzic
0f296becb4
commit
bc12a880a2
|
@ -128,6 +128,7 @@ The SDK-specific imports are all isolated to keep the main `@agentic/stdlib` as
|
||||||
- diffbot
|
- diffbot
|
||||||
- exa
|
- exa
|
||||||
- firecrawl (WIP)
|
- firecrawl (WIP)
|
||||||
|
- midjourney
|
||||||
- people data labs (WIP)
|
- people data labs (WIP)
|
||||||
- perigon
|
- perigon
|
||||||
- predict leads
|
- predict leads
|
||||||
|
@ -169,7 +170,6 @@ The SDK-specific imports are all isolated to keep the main `@agentic/stdlib` as
|
||||||
- replicate
|
- replicate
|
||||||
- huggingface
|
- huggingface
|
||||||
- [skyvern](https://github.com/Skyvern-AI/skyvern)
|
- [skyvern](https://github.com/Skyvern-AI/skyvern)
|
||||||
- midjourney
|
|
||||||
- unstructured
|
- unstructured
|
||||||
- pull from [langchain](https://github.com/langchain-ai/langchainjs/tree/main/langchain)
|
- pull from [langchain](https://github.com/langchain-ai/langchainjs/tree/main/langchain)
|
||||||
- provide a converter for langchain `DynamicStructuredTool`
|
- provide a converter for langchain `DynamicStructuredTool`
|
||||||
|
|
|
@ -5,6 +5,8 @@ import { TimeoutError } from '../errors.js'
|
||||||
import { aiFunction, AIFunctionsProvider } from '../fns.js'
|
import { aiFunction, AIFunctionsProvider } from '../fns.js'
|
||||||
import { assert, delay, getEnv, pruneNullOrUndefined } from '../utils.js'
|
import { assert, delay, getEnv, pruneNullOrUndefined } from '../utils.js'
|
||||||
|
|
||||||
|
// TODO: add additional methods for upscaling, variations, etc.
|
||||||
|
|
||||||
export namespace midjourney {
|
export namespace midjourney {
|
||||||
export const API_BASE_URL = 'https://cl.imagineapi.dev'
|
export const API_BASE_URL = 'https://cl.imagineapi.dev'
|
||||||
|
|
||||||
|
@ -28,6 +30,12 @@ export namespace midjourney {
|
||||||
ref?: string
|
ref?: string
|
||||||
upscaled?: string[]
|
upscaled?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface JobOptions {
|
||||||
|
wait?: boolean
|
||||||
|
timeoutMs?: number
|
||||||
|
intervalMs?: number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,12 +87,22 @@ export class MidjourneyClient extends AIFunctionsProvider {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
async imagine(
|
async imagine(
|
||||||
promptOrOptions: string | { prompt: string }
|
promptOrOptions:
|
||||||
|
| string
|
||||||
|
| ({
|
||||||
|
prompt: string
|
||||||
|
} & midjourney.JobOptions)
|
||||||
): Promise<midjourney.Job> {
|
): Promise<midjourney.Job> {
|
||||||
const options =
|
const {
|
||||||
typeof promptOrOptions === 'string'
|
wait = true,
|
||||||
? { prompt: promptOrOptions }
|
timeoutMs,
|
||||||
: promptOrOptions
|
intervalMs,
|
||||||
|
...options
|
||||||
|
} = typeof promptOrOptions === 'string'
|
||||||
|
? ({ prompt: promptOrOptions } as {
|
||||||
|
prompt: string
|
||||||
|
} & midjourney.JobOptions)
|
||||||
|
: promptOrOptions
|
||||||
|
|
||||||
const res = await this.ky
|
const res = await this.ky
|
||||||
.post('items/images', {
|
.post('items/images', {
|
||||||
|
@ -92,15 +110,56 @@ export class MidjourneyClient extends AIFunctionsProvider {
|
||||||
})
|
})
|
||||||
.json<midjourney.ImagineResponse>()
|
.json<midjourney.ImagineResponse>()
|
||||||
|
|
||||||
return pruneNullOrUndefined(res.data)
|
const job = pruneNullOrUndefined(res.data)
|
||||||
|
if (!wait) {
|
||||||
|
return job
|
||||||
|
}
|
||||||
|
|
||||||
|
if (job.status === 'completed' || job.status === 'failed') {
|
||||||
|
return job
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.waitForJobById(job.id, {
|
||||||
|
timeoutMs,
|
||||||
|
intervalMs
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getJobById(jobId: string): Promise<midjourney.Job> {
|
async getJobById(
|
||||||
|
jobIdOrOptions:
|
||||||
|
| string
|
||||||
|
| ({
|
||||||
|
jobId: string
|
||||||
|
} & midjourney.JobOptions)
|
||||||
|
): Promise<midjourney.Job> {
|
||||||
|
const {
|
||||||
|
jobId,
|
||||||
|
wait = true,
|
||||||
|
timeoutMs,
|
||||||
|
intervalMs
|
||||||
|
} = typeof jobIdOrOptions === 'string'
|
||||||
|
? ({ jobId: jobIdOrOptions } as {
|
||||||
|
jobId: string
|
||||||
|
} & midjourney.JobOptions)
|
||||||
|
: jobIdOrOptions
|
||||||
|
|
||||||
const res = await this.ky
|
const res = await this.ky
|
||||||
.get(`items/images/${jobId}`)
|
.get(`items/images/${jobId}`)
|
||||||
.json<midjourney.ImagineResponse>()
|
.json<midjourney.ImagineResponse>()
|
||||||
|
|
||||||
return pruneNullOrUndefined(res.data)
|
const job = pruneNullOrUndefined(res.data)
|
||||||
|
if (!wait) {
|
||||||
|
return job
|
||||||
|
}
|
||||||
|
|
||||||
|
if (job.status === 'completed' || job.status === 'failed') {
|
||||||
|
return job
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.waitForJobById(job.id, {
|
||||||
|
timeoutMs,
|
||||||
|
intervalMs
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForJobById(
|
async waitForJobById(
|
||||||
|
@ -108,11 +167,8 @@ export class MidjourneyClient extends AIFunctionsProvider {
|
||||||
{
|
{
|
||||||
timeoutMs = 5 * 60 * 1000, // 5 minutes
|
timeoutMs = 5 * 60 * 1000, // 5 minutes
|
||||||
intervalMs = 1000
|
intervalMs = 1000
|
||||||
}: {
|
}: Omit<midjourney.JobOptions, 'wait'> = {}
|
||||||
timeoutMs?: number
|
): Promise<midjourney.Job> {
|
||||||
intervalMs?: number
|
|
||||||
} = {}
|
|
||||||
) {
|
|
||||||
const startTimeMs = Date.now()
|
const startTimeMs = Date.now()
|
||||||
|
|
||||||
function checkForTimeout() {
|
function checkForTimeout() {
|
||||||
|
|
Ładowanie…
Reference in New Issue