-
Notifications
You must be signed in to change notification settings - Fork 51
fix: implement OpenAI-compatible generation for 5 AI stubs (#450) #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,51 @@ interface Config { | |
| baseUrl?: string; | ||
| } | ||
|
|
||
| const DEFAULT_BASE = 'https://api.venice.ai'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Venice API base URL is |
||
|
|
||
| export default defineAi<Config>({ | ||
| id: 'ai-venice', | ||
| label: 'Venice AI', | ||
| defaultModel: 'llama-3.3-70b', | ||
| models: ['llama-3.3-70b'], | ||
|
|
||
| async generate(ctx, prompt, _opts, _config) { | ||
| async generate(ctx, prompt, opts, config) { | ||
| const apiKey = ctx.secret('VENICE_API_KEY'); | ||
| if (!apiKey) throw new Error('VENICE_API_KEY not in vault — run `sh1pt promote ai setup`'); | ||
| ctx.log(`[stub] ai-venice · ${prompt.length} chars in — integration pending`); | ||
| return { text: '[stub — ai-venice integration not yet implemented]', model: 'llama-3.3-70b' }; | ||
| const model = opts.model ?? 'llama-3.3-70b'; | ||
| ctx.log(`venice · model=${model} · ${prompt.length} chars in`); | ||
| if (ctx.dryRun) return { text: '[dry-run]', model }; | ||
|
|
||
| const messages: Array<{ role: string; content: string }> = []; | ||
| if (opts.system) messages.push({ role: 'system', content: opts.system }); | ||
| messages.push({ role: 'user', content: prompt }); | ||
|
|
||
| const res = await fetch(`${config.baseUrl ?? DEFAULT_BASE}/v1/chat/completions`, { | ||
| method: 'POST', | ||
| headers: { | ||
| authorization: `Bearer ${apiKey}`, | ||
| 'content-type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ | ||
| model, | ||
| messages, | ||
| ...(opts.maxTokens !== undefined ? { max_tokens: opts.maxTokens } : {}), | ||
| ...(opts.temperature !== undefined ? { temperature: opts.temperature } : {}), | ||
| ...opts.extra, | ||
| }), | ||
| }); | ||
| if (!res.ok) throw new Error(`Venice ${res.status}: ${(await res.text()).slice(0, 200)}`); | ||
| const data = (await res.json()) as { | ||
| choices: Array<{ message?: { content?: string } }>; | ||
| model: string; | ||
| usage?: { prompt_tokens?: number; completion_tokens?: number }; | ||
| }; | ||
| return { | ||
| text: data.choices[0]?.message?.content ?? '', | ||
| model: data.model, | ||
| inputTokens: data.usage?.prompt_tokens, | ||
| outputTokens: data.usage?.completion_tokens, | ||
| }; | ||
| }, | ||
|
|
||
| setup: tokenSetup<Config>({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cohere's OpenAI-compatible chat completions endpoint is at
https://api.cohere.ai/compatibility/v1/chat/completions, nothttps://api.cohere.ai/v1/chat/completions. The currentDEFAULT_BASEwill produce requests to the wrong path, which will fail at runtime. The official Cohere compatibility docs confirm this path.