mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: SAP AI Core Vercel AI SDK v2 support (#5180)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com> Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
This commit is contained in:
parent
e020f5355e
commit
52bb43eebd
3 changed files with 20 additions and 12 deletions
2
packages/opencode/src/env/index.ts
vendored
2
packages/opencode/src/env/index.ts
vendored
|
|
@ -2,7 +2,7 @@ import { Instance } from "../project/instance"
|
|||
|
||||
export namespace Env {
|
||||
const state = Instance.state(() => {
|
||||
return { ...process.env } as Record<string, string | undefined>
|
||||
return process.env as Record<string, string | undefined>
|
||||
})
|
||||
|
||||
export function get(key: string) {
|
||||
|
|
|
|||
|
|
@ -287,13 +287,21 @@ export namespace Provider {
|
|||
},
|
||||
"sap-ai-core": async () => {
|
||||
const auth = await Auth.get("sap-ai-core")
|
||||
const serviceKey = Env.get("SAP_AI_SERVICE_KEY") || (auth?.type === "api" ? auth.key : undefined)
|
||||
const deploymentId = Env.get("SAP_AI_DEPLOYMENT_ID") || "d65d81e7c077e583"
|
||||
const resourceGroup = Env.get("SAP_AI_RESOURCE_GROUP") || "default"
|
||||
const envServiceKey = iife(() => {
|
||||
const envAICoreServiceKey = Env.get("AICORE_SERVICE_KEY")
|
||||
if (envAICoreServiceKey) return envAICoreServiceKey
|
||||
if (auth?.type === "api") {
|
||||
Env.set("AICORE_SERVICE_KEY", auth.key)
|
||||
return auth.key
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
const deploymentId = Env.get("AICORE_DEPLOYMENT_ID")
|
||||
const resourceGroup = Env.get("AICORE_RESOURCE_GROUP")
|
||||
|
||||
return {
|
||||
autoload: !!serviceKey,
|
||||
options: serviceKey ? { serviceKey, deploymentId, resourceGroup } : {},
|
||||
autoload: !!envServiceKey,
|
||||
options: envServiceKey ? { deploymentId, resourceGroup } : {},
|
||||
async getModel(sdk: any, modelID: string) {
|
||||
return sdk(modelID)
|
||||
},
|
||||
|
|
@ -795,7 +803,7 @@ export namespace Provider {
|
|||
const mod = await import(installedPath)
|
||||
|
||||
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
|
||||
const loaded = await fn({
|
||||
const loaded = fn({
|
||||
name: model.providerID,
|
||||
...options,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -947,26 +947,26 @@ SAP AI Core provides access to 40+ models from OpenAI, Anthropic, Google, Amazon
|
|||
└ enter
|
||||
```
|
||||
|
||||
Or set the `SAP_AI_SERVICE_KEY` environment variable:
|
||||
Or set the `AICORE_SERVICE_KEY` environment variable:
|
||||
|
||||
```bash
|
||||
SAP_AI_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}' opencode
|
||||
AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}' opencode
|
||||
```
|
||||
|
||||
Or add it to your bash profile:
|
||||
|
||||
```bash title="~/.bash_profile"
|
||||
export SAP_AI_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'
|
||||
export AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'
|
||||
```
|
||||
|
||||
4. Optionally set deployment ID and resource group:
|
||||
|
||||
```bash
|
||||
SAP_AI_DEPLOYMENT_ID=your-deployment-id SAP_AI_RESOURCE_GROUP=your-resource-group opencode
|
||||
AICORE_DEPLOYMENT_ID=your-deployment-id AICORE_RESOURCE_GROUP=your-resource-group opencode
|
||||
```
|
||||
|
||||
:::note
|
||||
If not set, uses deployment ID `d65d81e7c077e583` (general-purpose) and resource group `default`. Configure these for your specific setup.
|
||||
These settings are optional and should be configured according to your SAP AI Core setup.
|
||||
:::
|
||||
|
||||
5. Run the `/models` command to select from 40+ available models.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue